Class GF2nPolynomialElement
- java.lang.Object
-
- org.bouncycastle.pqc.math.linearalgebra.GF2nElement
-
- org.bouncycastle.pqc.math.linearalgebra.GF2nPolynomialElement
-
- All Implemented Interfaces:
GFElement
public class GF2nPolynomialElement extends GF2nElement
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:
- "GF2nField",
GF2nPolynomialField,GF2nONBElement,GF2Polynomial
-
-
Field Summary
-
Fields inherited from class org.bouncycastle.pqc.math.linearalgebra.GF2nElement
mDegree, mField
-
-
Constructor Summary
Constructors Constructor Description GF2nPolynomialElement(GF2nPolynomialElement other)Creates 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.GF2nPolynomialElement(GF2nPolynomialField f, java.util.Random rand)Create a new random GF2nPolynomialElement using the given field and source of randomness.GF2nPolynomialElement(GF2nPolynomialField f, GF2Polynomial bs)Creates a new GF2nPolynomialElement using the given field and Bitstring.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description GFElementadd(GFElement addend)Compute the sum of this element and addend.voidaddToThis(GFElement addend)Compute this + addend (overwrite this).java.lang.Objectclone()Creates a new GF2nPolynomialElement by cloning this GF2nPolynomialElement.booleanequals(java.lang.Object other)Compare this element with another object.inthashCode()GF2nElementincrease()Returns this element + 'one".voidincreaseThis()Increases this element by 'one'.GFElementinvert()Compute the multiplicative inverse of this element.GF2nPolynomialElementinvertEEA()Calculates the multiplicative inverse of this and returns the result in a new GF2nPolynomialElement.GF2nPolynomialElementinvertMAIA()Calculates the multiplicative inverse of this using the modified almost inverse algorithm and returns the result in a new GF2nPolynomialElement.GF2nPolynomialElementinvertSquare()Calculates the multiplicative inverse of this and returns the result in a new GF2nPolynomialElement.booleanisOne()Tests if the GF2nPolynomialElement has 'one' as value.booleanisZero()Checks whether this element is zero.GFElementmultiply(GFElement factor)Compute the product of this element and factor.voidmultiplyThisBy(GFElement factor)Compute this * factor (overwrite this).static GF2nPolynomialElementONE(GF2nPolynomialField f)Create the one element.GF2nPolynomialElementpower(int k)Calculates this to the power of k and returns the result in a new GF2nPolynomialElement.GF2nElementsolveQuadraticEquation()Solves the quadratic equation z2 + z = this if such a solution exists.GF2nElementsquare()This method is used internally to map the square()-calls within GF2nPolynomialElement to one of the possible squaring methods.GF2nPolynomialElementsquareBitwise()Squares this GF2nPolynomialElement by shifting left its Bitstring and reducing.GF2nPolynomialElementsquareMatrix()Squares this GF2nPolynomialElement using GF2nField's squaring matrix.GF2nPolynomialElementsquarePreCalc()Squares this GF2nPolynomialElement by using precalculated values and reducing.GF2nElementsquareRoot()Compute the square root of this element and return the result in a newGF2nPolynomialElement.voidsquareRootThis()Compute the square root of this element.voidsquareThis()This method is used internally to map the square()-calls within GF2nPolynomialElement to one of the possible squaring methods.voidsquareThisBitwise()Squares this GF2nPolynomialElement by shifting left its Bitstring and reducing.voidsquareThisMatrix()Squares this GF2nPolynomialElement using GF2nFields squaring matrix.voidsquareThisPreCalc()Squares this GF2nPolynomialElement by using precalculated values and reducing.booleantestRightmostBit()Returns whether the rightmost bit of the bit representation is set.byte[]toByteArray()Converts this GF2nPolynomialElement to a byte[] according to 1363.java.math.BigIntegertoFlexiBigInt()Converts this GF2nPolynomialElement to an integer according to 1363.java.lang.StringtoString()Returns a string representing this Bitstrings value using hexadecimal radix in MSB-first order.java.lang.StringtoString(int radix)Returns a string representing this Bitstrings value using hexadecimal or binary radix in MSB-first order.inttrace()Returns the trace of this GF2nPolynomialElement.static GF2nPolynomialElementZERO(GF2nPolynomialField f)Create the zero element.-
Methods inherited from class org.bouncycastle.pqc.math.linearalgebra.GF2nElement
convert, getField, subtract, subtractFromThis
-
-
-
-
Constructor Detail
-
GF2nPolynomialElement
public GF2nPolynomialElement(GF2nPolynomialField f, java.util.Random rand)
Create a new random GF2nPolynomialElement using the given field and source of randomness.- Parameters:
f- the GF2nField to userand- the source of randomness
-
GF2nPolynomialElement
public GF2nPolynomialElement(GF2nPolynomialField f, GF2Polynomial bs)
Creates a new GF2nPolynomialElement using the given field and Bitstring.- Parameters:
f- the GF2nPolynomialField to usebs- the desired value as Bitstring
-
GF2nPolynomialElement
public GF2nPolynomialElement(GF2nPolynomialField f, byte[] os)
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:
- "P1363 5.5.5 p23, OS2FEP/OS2BSP"
-
GF2nPolynomialElement
public GF2nPolynomialElement(GF2nPolynomialField f, int[] is)
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
public GF2nPolynomialElement(GF2nPolynomialElement other)
Creates a new GF2nPolynomialElement by cloning the given GF2nPolynomialElement b.- Parameters:
other- the GF2nPolynomialElement to clone
-
-
Method Detail
-
clone
public java.lang.Object clone()
Creates a new GF2nPolynomialElement by cloning this GF2nPolynomialElement.- Specified by:
clonein interfaceGFElement- Specified by:
clonein classGF2nElement- Returns:
- a copy of this element
-
ZERO
public static GF2nPolynomialElement ZERO(GF2nPolynomialField f)
Create the zero element.- Parameters:
f- the finite field- Returns:
- the zero element in the given finite field
-
ONE
public static GF2nPolynomialElement ONE(GF2nPolynomialField f)
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
public boolean equals(java.lang.Object other)
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:
testRightmostBitin classGF2nElement- Returns:
- true if the rightmost bit of this element is set
-
add
public GFElement add(GFElement addend) throws java.lang.RuntimeException
Compute the sum of this element and addend.- Parameters:
addend- the addend- Returns:
- this + other (newly created)
- Throws:
java.lang.RuntimeException
-
addToThis
public void addToThis(GFElement addend) throws java.lang.RuntimeException
Compute this + addend (overwrite this).- Parameters:
addend- the addend- Throws:
java.lang.RuntimeException
-
increase
public GF2nElement increase()
Returns this element + 'one".- Specified by:
increasein classGF2nElement- Returns:
- this + 'one'
-
increaseThis
public void increaseThis()
Increases this element by 'one'.- Specified by:
increaseThisin classGF2nElement
-
multiply
public GFElement multiply(GFElement factor) throws java.lang.RuntimeException
Compute the product of this element and factor.- Parameters:
factor- the factor- Returns:
- this * factor (newly created)
- Throws:
java.lang.RuntimeException
-
multiplyThisBy
public void multiplyThisBy(GFElement factor) throws java.lang.RuntimeException
Compute this * factor (overwrite this).- Parameters:
factor- the factor- Throws:
java.lang.RuntimeException
-
invert
public GFElement invert() throws java.lang.ArithmeticException
Compute the multiplicative inverse of this element.- Returns:
- this-1 (newly created)
- Throws:
java.lang.ArithmeticException- if this is the zero element.- See Also:
invertMAIA(),invertEEA(),invertSquare()
-
invertEEA
public GF2nPolynomialElement invertEEA() throws java.lang.ArithmeticException
Calculates the multiplicative inverse of this and returns the result in a new GF2nPolynomialElement.- Returns:
- this^(-1)
- Throws:
java.lang.ArithmeticException- if this equals zero
-
invertSquare
public GF2nPolynomialElement invertSquare() throws java.lang.ArithmeticException
Calculates the multiplicative inverse of this and returns the result in a new GF2nPolynomialElement.- Returns:
- this^(-1)
- Throws:
java.lang.ArithmeticException- if this equals zero
-
invertMAIA
public GF2nPolynomialElement invertMAIA() throws java.lang.ArithmeticException
Calculates the multiplicative inverse of this using the modified almost inverse algorithm and returns the result in a new GF2nPolynomialElement.- Returns:
- this^(-1)
- Throws:
java.lang.ArithmeticException- if this equals zero
-
square
public GF2nElement square()
This method is used internally to map the square()-calls within GF2nPolynomialElement to one of the possible squaring methods.- Specified by:
squarein classGF2nElement- Returns:
- this2 (newly created)
- See Also:
squarePreCalc()
-
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:
squareThisin classGF2nElement
-
squareMatrix
public GF2nPolynomialElement 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:
GF2Polynomial.vectorMult(org.bouncycastle.pqc.math.linearalgebra.GF2Polynomial),squarePreCalc(),squareBitwise()
-
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.
-
squareBitwise
public GF2nPolynomialElement 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:
squareMatrix(),squarePreCalc(),GF2Polynomial.squareThisBitwise()
-
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.
-
squarePreCalc
public GF2nPolynomialElement 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:
squareMatrix(),GF2Polynomial.squareThisPreCalc()
-
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:
squareMatrix(),GF2Polynomial.squareThisPreCalc()
-
power
public GF2nPolynomialElement power(int k)
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
public GF2nElement squareRoot()
Compute the square root of this element and return the result in a newGF2nPolynomialElement.- Specified by:
squareRootin classGF2nElement- Returns:
- this1/2 (newly created)
-
squareRootThis
public void squareRootThis()
Compute the square root of this element.- Specified by:
squareRootThisin classGF2nElement
-
solveQuadraticEquation
public GF2nElement solveQuadraticEquation() throws java.lang.RuntimeException
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:
solveQuadraticEquationin classGF2nElement- Returns:
- a GF2nPolynomialElement representing one z satisfying the equation z2 + z = this
- Throws:
java.lang.RuntimeException- See Also:
- "IEEE 1363, Annex A.4.7"
-
trace
public int trace()
Returns the trace of this GF2nPolynomialElement.- Specified by:
tracein classGF2nElement- Returns:
- the trace of this GF2nPolynomialElement
-
toString
public java.lang.String toString()
Returns a string representing this Bitstrings value using hexadecimal radix in MSB-first order.
-
toString
public java.lang.String toString(int radix)
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:
- "P1363 5.5.2 p22f BS2OSP, FE2OSP"
-
toFlexiBigInt
public java.math.BigInteger toFlexiBigInt()
Converts this GF2nPolynomialElement to an integer according to 1363.- Returns:
- a BigInteger representing the value of this GF2nPolynomialElement
- See Also:
- "P1363 5.5.1 p22 BS2IP"
-
-