Class PolynomialGF2mSmallM
java.lang.Object
org.bouncycastle.pqc.legacy.math.linearalgebra.PolynomialGF2mSmallM
This class describes operations with polynomials from the ring R =
GF(2^m)[X], where 2 <= m <=31.
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final char
Constant used for polynomial construction (see constructorPolynomialGF2mSmallM(GF2mField, int, char, SecureRandom)
). -
Constructor Summary
ConstructorsConstructorDescriptionPolynomialGF2mSmallM
(GF2mField field) Construct the zero polynomial over the finite field GF(2^m).PolynomialGF2mSmallM
(GF2mField field, byte[] enc) Create a polynomial over the finite field GF(2^m).PolynomialGF2mSmallM
(GF2mField field, int degree) Construct a monomial of the given degree over the finite field GF(2^m).PolynomialGF2mSmallM
(GF2mField field, int[] coeffs) Construct the polynomial over the given finite field GF(2^m) from the given coefficient vector.PolynomialGF2mSmallM
(GF2mField field, int deg, char typeOfPolynomial, SecureRandom sr) Construct a polynomial over the finite field GF(2^m).Create a polynomial over the finite field GF(2^m) out of the given coefficient vector.Copy constructor. -
Method Summary
Modifier and TypeMethodDescriptionadd
(PolynomialGF2mSmallM addend) Compute the sum of this polynomial and the given polynomial.addMonomial
(int degree) Compute the sum of this polynomial and the monomial of the given degree.void
addToThis
(PolynomialGF2mSmallM addend) Add the given polynomial to this polynomial (overwrite this).Divide this polynomial by the given polynomial.boolean
checks if given object is equal to this polynomial.int
evaluateAt
(int e) Evaluate this polynomial p at a value e (in GF(2^m)) with the Horner scheme.Return the greatest common divisor of this and a polynomial fint
getCoefficient
(int index) Return the coefficient with the given index.int
Return the degree of this polynomialbyte[]
Returns encoded polynomial, i.e., this polynomial in byte array formint
int
hashCode()
Reduce this polynomial modulo another polynomial.modDiv
(PolynomialGF2mSmallM divisor, PolynomialGF2mSmallM modulus) Compute the result of the division of this polynomial by another polynomial modulo a third polynomial.Compute the inverse of this polynomial modulo the given polynomial.Compute the product of this polynomial and another polynomial modulo a third polynomial.Compute a polynomial pair (a,b) from this polynomial and the given polynomial g with the property b*this = a mod g and deg(a)<=deg(g)/2.modSquareMatrix
(PolynomialGF2mSmallM[] matrix) Square this polynomial using a squaring matrix.Compute the square root of this polynomial modulo the given polynomial.modSquareRootMatrix
(PolynomialGF2mSmallM[] matrix) Compute the square root of this polynomial using a square root matrix.multiply
(PolynomialGF2mSmallM factor) Compute the product of this polynomial and the given factor using a Karatzuba like scheme.void
multThisWithElement
(int element) Multiply this polynomial with an element from GF(2^m).multWithElement
(int element) Compute the product of this polynomial with an element from GF(2^m).multWithMonomial
(int k) Compute the product of this polynomial with a monomial X^k.toString()
Returns a human readable form of the polynomial.
-
Field Details
-
RANDOM_IRREDUCIBLE_POLYNOMIAL
public static final char RANDOM_IRREDUCIBLE_POLYNOMIALConstant used for polynomial construction (see constructorPolynomialGF2mSmallM(GF2mField, int, char, SecureRandom)
).- See Also:
-
-
Constructor Details
-
PolynomialGF2mSmallM
Construct the zero polynomial over the finite field GF(2^m).- Parameters:
field
- the finite field GF(2^m)
-
PolynomialGF2mSmallM
Construct a polynomial over the finite field GF(2^m).- Parameters:
field
- the finite field GF(2^m)deg
- degree of polynomialtypeOfPolynomial
- type of polynomialsr
- PRNG
-
PolynomialGF2mSmallM
Construct a monomial of the given degree over the finite field GF(2^m).- Parameters:
field
- the finite field GF(2^m)degree
- the degree of the monomial
-
PolynomialGF2mSmallM
Construct the polynomial over the given finite field GF(2^m) from the given coefficient vector.- Parameters:
field
- finite field GF2mcoeffs
- the coefficient vector
-
PolynomialGF2mSmallM
Create a polynomial over the finite field GF(2^m).- Parameters:
field
- the finite field GF(2^m)enc
- byte[] polynomial in byte array form
-
PolynomialGF2mSmallM
Copy constructor.- Parameters:
other
- anotherPolynomialGF2mSmallM
-
PolynomialGF2mSmallM
Create a polynomial over the finite field GF(2^m) out of the given coefficient vector. The finite field is also obtained from theGF2mVector
.- Parameters:
vect
- the coefficient vector
-
-
Method Details
-
getDegree
public int getDegree()Return the degree of this polynomial- Returns:
- int degree of this polynomial if this is zero polynomial return -1
-
getHeadCoefficient
public int getHeadCoefficient()- Returns:
- the head coefficient of this polynomial
-
getCoefficient
public int getCoefficient(int index) Return the coefficient with the given index.- Parameters:
index
- the index- Returns:
- the coefficient with the given index
-
getEncoded
public byte[] getEncoded()Returns encoded polynomial, i.e., this polynomial in byte array form- Returns:
- the encoded polynomial
-
evaluateAt
public int evaluateAt(int e) Evaluate this polynomial p at a value e (in GF(2^m)) with the Horner scheme.- Parameters:
e
- the element of the finite field GF(2^m)- Returns:
- this(e)
-
add
Compute the sum of this polynomial and the given polynomial.- Parameters:
addend
- the addend- Returns:
- this + a (newly created)
-
addToThis
Add the given polynomial to this polynomial (overwrite this).- Parameters:
addend
- the addend
-
addMonomial
Compute the sum of this polynomial and the monomial of the given degree.- Parameters:
degree
- the degree of the monomial- Returns:
- this + X^k
-
multWithElement
Compute the product of this polynomial with an element from GF(2^m).- Parameters:
element
- an element of the finite field GF(2^m)- Returns:
- this * element (newly created)
- Throws:
ArithmeticException
- if element is not an element of the finite field this polynomial is defined over.
-
multThisWithElement
public void multThisWithElement(int element) Multiply this polynomial with an element from GF(2^m).- Parameters:
element
- an element of the finite field GF(2^m)- Throws:
ArithmeticException
- if element is not an element of the finite field this polynomial is defined over.
-
multWithMonomial
Compute the product of this polynomial with a monomial X^k.- Parameters:
k
- the degree of the monomial- Returns:
- this * X^k
-
div
Divide this polynomial by the given polynomial.- Parameters:
f
- a polynomial- Returns:
- polynomial pair = {q,r} where this = q*f+r and deg(r) < deg(f);
-
gcd
Return the greatest common divisor of this and a polynomial f- Parameters:
f
- polynomial- Returns:
- GCD(this, f)
-
multiply
Compute the product of this polynomial and the given factor using a Karatzuba like scheme.- Parameters:
factor
- the polynomial- Returns:
- this * factor
-
mod
Reduce this polynomial modulo another polynomial.- Parameters:
f
- the reduction polynomial- Returns:
- this mod f
-
modMultiply
Compute the product of this polynomial and another polynomial modulo a third polynomial.- Parameters:
a
- another polynomialb
- the reduction polynomial- Returns:
- this * a mod b
-
modSquareMatrix
Square this polynomial using a squaring matrix.- Parameters:
matrix
- the squaring matrix- Returns:
- this^2 modulo the reduction polynomial implicitly given via the squaring matrix
-
modSquareRoot
Compute the square root of this polynomial modulo the given polynomial.- Parameters:
a
- the reduction polynomial- Returns:
- this^(1/2) mod a
-
modSquareRootMatrix
Compute the square root of this polynomial using a square root matrix.- Parameters:
matrix
- the matrix for computing square roots in (GF(2^m))^t the polynomial ring defining the square root matrix- Returns:
- this^(1/2) modulo the reduction polynomial implicitly given via the square root matrix
-
modDiv
Compute the result of the division of this polynomial by another polynomial modulo a third polynomial.- Parameters:
divisor
- the divisormodulus
- the reduction polynomial- Returns:
- this * divisor^(-1) mod modulus
-
modInverse
Compute the inverse of this polynomial modulo the given polynomial.- Parameters:
a
- the reduction polynomial- Returns:
- this^(-1) mod a
-
modPolynomialToFracton
Compute a polynomial pair (a,b) from this polynomial and the given polynomial g with the property b*this = a mod g and deg(a)<=deg(g)/2.- Parameters:
g
- the reduction polynomial- Returns:
- PolynomialGF2mSmallM[] {a,b} with b*this = a mod g and deg(a)<= deg(g)/2
-
equals
checks if given object is equal to this polynomial.The method returns false whenever the given object is not polynomial over GF(2^m).
-
hashCode
public int hashCode() -
toString
Returns a human readable form of the polynomial.
-