Class GF2nPolynomialElement
java.lang.Object
org.bouncycastle.pqc.legacy.math.linearalgebra.GF2nElement
org.bouncycastle.pqc.legacy.math.linearalgebra.GF2nPolynomialElement
- All Implemented Interfaces:
GFElement
This class implements elements of finite binary fields GF(2n)
using polynomial representation. For more information on the arithmetic see
for example IEEE Standard 1363 or Certicom online-tutorial.
- See Also:
-
Field Summary
Fields inherited from class org.bouncycastle.pqc.legacy.math.linearalgebra.GF2nElement
mDegree, mField
-
Constructor Summary
ConstructorDescriptionCreates a new GF2nPolynomialElement by cloning the given GF2nPolynomialElement b.GF2nPolynomialElement
(GF2nPolynomialField f, byte[] os) Creates a new GF2nPolynomialElement using the given field f and byte[] os as value.GF2nPolynomialElement
(GF2nPolynomialField f, int[] is) Creates a new GF2nPolynomialElement using the given field f and int[] is as value.Create a new random GF2nPolynomialElement using the given field and source of randomness.Creates a new GF2nPolynomialElement using the given field and Bitstring. -
Method Summary
Modifier and TypeMethodDescriptionCompute the sum of this element and addend.void
Compute this + addend (overwrite this).clone()
Creates a new GF2nPolynomialElement by cloning this GF2nPolynomialElement.boolean
Compare this element with another object.int
hashCode()
increase()
Returns this element + 'one".void
Increases this element by 'one'.invert()
Compute the multiplicative inverse of this element.Calculates the multiplicative inverse of this and returns the result in a new GF2nPolynomialElement.Calculates the multiplicative inverse of this using the modified almost inverse algorithm and returns the result in a new GF2nPolynomialElement.Calculates the multiplicative inverse of this and returns the result in a new GF2nPolynomialElement.boolean
isOne()
Tests if the GF2nPolynomialElement has 'one' as value.boolean
isZero()
Checks whether this element is zero.Compute the product of this element and factor.void
multiplyThisBy
(GFElement factor) Compute this * factor (overwrite this).static GF2nPolynomialElement
Create the one element.power
(int k) Calculates this to the power of k and returns the result in a new GF2nPolynomialElement.Solves the quadratic equation z2 + z = this if such a solution exists.square()
This method is used internally to map the square()-calls within GF2nPolynomialElement to one of the possible squaring methods.Squares this GF2nPolynomialElement by shifting left its Bitstring and reducing.Squares this GF2nPolynomialElement using GF2nField's squaring matrix.Squares this GF2nPolynomialElement by using precalculated values and reducing.Compute the square root of this element and return the result in a newGF2nPolynomialElement
.void
Compute the square root of this element.void
This method is used internally to map the square()-calls within GF2nPolynomialElement to one of the possible squaring methods.void
Squares this GF2nPolynomialElement by shifting left its Bitstring and reducing.void
Squares this GF2nPolynomialElement using GF2nFields squaring matrix.void
Squares this GF2nPolynomialElement by using precalculated values and reducing.boolean
Returns whether the rightmost bit of the bit representation is set.byte[]
Converts this GF2nPolynomialElement to a byte[] according to 1363.Converts this GF2nPolynomialElement to an integer according to 1363.toString()
Returns a string representing this Bitstrings value using hexadecimal radix in MSB-first order.toString
(int radix) Returns a string representing this Bitstrings value using hexadecimal or binary radix in MSB-first order.int
trace()
Returns the trace of this GF2nPolynomialElement.static GF2nPolynomialElement
Create the zero element.Methods inherited from class org.bouncycastle.pqc.legacy.math.linearalgebra.GF2nElement
convert, getField, subtract, subtractFromThis
-
Constructor Details
-
GF2nPolynomialElement
Create a new random GF2nPolynomialElement using the given field and source of randomness.- Parameters:
f
- the GF2nField to userand
- the source of randomness
-
GF2nPolynomialElement
Creates a new GF2nPolynomialElement using the given field and Bitstring.- Parameters:
f
- the GF2nPolynomialField to usebs
- the desired value as Bitstring
-
GF2nPolynomialElement
Creates a new GF2nPolynomialElement using the given field f and byte[] os as value. The conversion is done according to 1363.- Parameters:
f
- the GF2nField to useos
- the octet string to assign to this GF2nPolynomialElement- See Also:
-
GF2nPolynomialElement
Creates a new GF2nPolynomialElement using the given field f and int[] is as value.- Parameters:
f
- the GF2nField to useis
- the integer string to assign to this GF2nPolynomialElement
-
GF2nPolynomialElement
Creates a new GF2nPolynomialElement by cloning the given GF2nPolynomialElement b.- Parameters:
other
- the GF2nPolynomialElement to clone
-
-
Method Details
-
clone
Creates a new GF2nPolynomialElement by cloning this GF2nPolynomialElement.- Specified by:
clone
in interfaceGFElement
- Specified by:
clone
in classGF2nElement
- Returns:
- a copy of this element
-
ZERO
Create the zero element.- Parameters:
f
- the finite field- Returns:
- the zero element in the given finite field
-
ONE
Create the one element.- Parameters:
f
- the finite field- Returns:
- the one element in the given finite field
-
isZero
public boolean isZero()Checks whether this element is zero.- Returns:
- true if this is the zero element
-
isOne
public boolean isOne()Tests if the GF2nPolynomialElement has 'one' as value.- Returns:
- true if this equals one (this == 1)
-
equals
Compare this element with another object. -
hashCode
public int hashCode() -
testRightmostBit
public boolean testRightmostBit()Returns whether the rightmost bit of the bit representation is set. This is needed for data conversion according to 1363.- Specified by:
testRightmostBit
in classGF2nElement
- Returns:
- true if the rightmost bit of this element is set
-
add
Compute the sum of this element and addend.- Parameters:
addend
- the addend- Returns:
- this + other (newly created)
- Throws:
RuntimeException
-
addToThis
Compute this + addend (overwrite this).- Parameters:
addend
- the addend- Throws:
RuntimeException
-
increase
Returns this element + 'one".- Specified by:
increase
in classGF2nElement
- Returns:
- this + 'one'
-
increaseThis
public void increaseThis()Increases this element by 'one'.- Specified by:
increaseThis
in classGF2nElement
-
multiply
Compute the product of this element and factor.- Parameters:
factor
- the factor- Returns:
- this * factor (newly created)
- Throws:
RuntimeException
-
multiplyThisBy
Compute this * factor (overwrite this).- Parameters:
factor
- the factor- Throws:
RuntimeException
-
invert
Compute the multiplicative inverse of this element.- Returns:
- this-1 (newly created)
- Throws:
ArithmeticException
- if this is the zero element.- See Also:
-
invertEEA
Calculates the multiplicative inverse of this and returns the result in a new GF2nPolynomialElement.- Returns:
- this^(-1)
- Throws:
ArithmeticException
- if this equals zero
-
invertSquare
Calculates the multiplicative inverse of this and returns the result in a new GF2nPolynomialElement.- Returns:
- this^(-1)
- Throws:
ArithmeticException
- if this equals zero
-
invertMAIA
Calculates the multiplicative inverse of this using the modified almost inverse algorithm and returns the result in a new GF2nPolynomialElement.- Returns:
- this^(-1)
- Throws:
ArithmeticException
- if this equals zero
-
square
This method is used internally to map the square()-calls within GF2nPolynomialElement to one of the possible squaring methods.- Specified by:
square
in classGF2nElement
- Returns:
- this2 (newly created)
- See Also:
-
squareThis
public void squareThis()This method is used internally to map the square()-calls within GF2nPolynomialElement to one of the possible squaring methods.- Specified by:
squareThis
in classGF2nElement
-
squareMatrix
Squares this GF2nPolynomialElement using GF2nField's squaring matrix. This is supposed to be fast when using a polynomial (no tri- or pentanomial) as fieldpolynomial. Use squarePreCalc when using a tri- or pentanomial as fieldpolynomial instead.- Returns:
- this2 (newly created)
- See Also:
-
squareThisMatrix
public void squareThisMatrix()Squares this GF2nPolynomialElement using GF2nFields squaring matrix. This is supposed to be fast when using a polynomial (no tri- or pentanomial) as fieldpolynomial. Use squarePreCalc when using a tri- or pentanomial as fieldpolynomial instead.- See Also:
-
squareBitwise
Squares this GF2nPolynomialElement by shifting left its Bitstring and reducing. This is supposed to be the slowest method. Use squarePreCalc or squareMatrix instead.- Returns:
- this2 (newly created)
- See Also:
-
squareThisBitwise
public void squareThisBitwise()Squares this GF2nPolynomialElement by shifting left its Bitstring and reducing. This is supposed to be the slowest method. Use squarePreCalc or squareMatrix instead.- See Also:
-
squarePreCalc
Squares this GF2nPolynomialElement by using precalculated values and reducing. This is supposed to de fastest when using a trinomial or pentanomial as field polynomial. Use squareMatrix when using a ordinary polynomial as field polynomial.- Returns:
- this2 (newly created)
- See Also:
-
squareThisPreCalc
public void squareThisPreCalc()Squares this GF2nPolynomialElement by using precalculated values and reducing. This is supposed to de fastest when using a tri- or pentanomial as fieldpolynomial. Use squareMatrix when using a ordinary polynomial as fieldpolynomial.- See Also:
-
power
Calculates this to the power of k and returns the result in a new GF2nPolynomialElement.- Parameters:
k
- the power- Returns:
- this^k in a new GF2nPolynomialElement
-
squareRoot
Compute the square root of this element and return the result in a newGF2nPolynomialElement
.- Specified by:
squareRoot
in classGF2nElement
- Returns:
- this1/2 (newly created)
-
squareRootThis
public void squareRootThis()Compute the square root of this element.- Specified by:
squareRootThis
in classGF2nElement
-
solveQuadraticEquation
Solves the quadratic equation z2 + z = this if such a solution exists. This method returns one of the two possible solutions. The other solution is z + 1. Use z.increase() to compute this solution.- Specified by:
solveQuadraticEquation
in classGF2nElement
- Returns:
- a GF2nPolynomialElement representing one z satisfying the equation z2 + z = this
- Throws:
RuntimeException
- See Also:
-
trace
public int trace()Returns the trace of this GF2nPolynomialElement.- Specified by:
trace
in classGF2nElement
- Returns:
- the trace of this GF2nPolynomialElement
-
toString
Returns a string representing this Bitstrings value using hexadecimal radix in MSB-first order. -
toString
Returns a string representing this Bitstrings value using hexadecimal or binary radix in MSB-first order.- Parameters:
radix
- the radix to use (2 or 16, otherwise 2 is used)- Returns:
- a String representing this Bitstrings value.
-
toByteArray
public byte[] toByteArray()Converts this GF2nPolynomialElement to a byte[] according to 1363.- Returns:
- a byte[] representing the value of this GF2nPolynomialElement
- See Also:
-
toFlexiBigInt
Converts this GF2nPolynomialElement to an integer according to 1363.- Returns:
- a BigInteger representing the value of this GF2nPolynomialElement
- See Also:
-