Top Description Fields Constructors Methods
org.bouncycastle.pqc.legacy.math.linearalgebra

public Class PolynomialGF2mSmallM

extends Object
Class Inheritance
Imports
java.security.SecureRandom

This class describes operations with polynomials from the ring R = GF(2^m)[X], where 2 <= m <=31.
See Also
GF2mField, PolynomialRingGF2m

Field Summary

Modifier and TypeField and Description
private int[]
coefficients

For the polynomial representation the map f: R->Z*, poly(X) -> [coef_0, coef_1, ...] is used, where coef_i is the ith coefficient of the polynomial represented as int (see GF2mField).

private int
degree

the degree of this polynomial

private GF2mField
field

the finite field GF(2^m)

public static final char
RANDOM_IRREDUCIBLE_POLYNOMIAL

Constant used for polynomial construction (see constructor PolynomialGF2mSmallM(GF2mField, int, char, SecureRandom)).

Constructor Summary

AccessConstructor and Description
public
PolynomialGF2mSmallM(GF2mField
the finite field GF(2^m)
field
)

Construct the zero polynomial over the finite field GF(2^m).

public
PolynomialGF2mSmallM(GF2mField
the finite field GF(2^m)
field
,
int
degree of polynomial
deg
,
char
type of polynomial
typeOfPolynomial
,
SecureRandom
PRNG
sr
)

Construct a polynomial over the finite field GF(2^m).

public
PolynomialGF2mSmallM(GF2mField
the finite field GF(2^m)
field
,
int
the degree of the monomial
degree
)

Construct a monomial of the given degree over the finite field GF(2^m).

public
PolynomialGF2mSmallM(GF2mField
finite field GF2m
field
,
int[]
the coefficient vector
coeffs
)

Construct the polynomial over the given finite field GF(2^m) from the given coefficient vector.

public
PolynomialGF2mSmallM(GF2mField
the finite field GF(2^m)
field
,
byte[]
byte[] polynomial in byte array form
enc
)

Create a polynomial over the finite field GF(2^m).

public
public
PolynomialGF2mSmallM(GF2mVector
the coefficient vector
vect
)

Create a polynomial over the finite field GF(2^m) out of the given coefficient vector.

Method Summary

Modifier and TypeMethod and Description
public PolynomialGF2mSmallM

Returns:

this + a (newly created)
add
(PolynomialGF2mSmallM
the addend
addend
)

Compute the sum of this polynomial and the given polynomial.

private int[]

Returns:

a + b
add
(int[]
the first polynomial
a
,
int[]
the second polynomial
b
)

Compute the sum of two polynomials a and b over the finite field GF(2^m).

public PolynomialGF2mSmallM

Returns:

this + X^k
addMonomial
(int
the degree of the monomial
degree
)

Compute the sum of this polynomial and the monomial of the given degree.

public void
addToThis(PolynomialGF2mSmallM
the addend
addend
)

Add the given polynomial to this polynomial (overwrite this).

private void
computeDegree()

Compute the degree of this polynomial.

private static int

Returns:

the degree of the polynomial a. If a is the zero polynomial, return -1.
computeDegree
(int[]
the polynomial
a
)

Compute the degree of a polynomial.

private int[]

Returns:

the generated irreducible polynomial
createRandomIrreduciblePolynomial
(int
polynomial degree
deg
,
SecureRandom
source of randomness
sr
)

Create an irreducible polynomial with the given degree over the field GF(2^m).

public PolynomialGF2mSmallM[]

Returns:

polynomial pair = {q,r} where this = q*f+r and deg(r) < deg(f);
div
(PolynomialGF2mSmallM
a polynomial
f
)

Divide this polynomial by the given polynomial.

private int[][]

Returns:

int[][] {q,r}, where a = q*f+r and deg(r) < deg(f);
div
(int[]
the first polynomial
a
,
int[]
the second polynomial
f
)

Compute the result of the division of two polynomials over the field GF(2^m).

public boolean

Returns:

true or false
equals
(Object
object
other
)

Overrides java.lang.Object.equals.

checks if given object is equal to this polynomial.

public int

Returns:

this(e)
evaluateAt
(int
the element of the finite field GF(2^m)
e
)

Evaluate this polynomial p at a value e (in GF(2^m)) with the Horner scheme.

public PolynomialGF2mSmallM

Returns:

GCD(this, f)
gcd
(PolynomialGF2mSmallM
polynomial
f
)

Return the greatest common divisor of this and a polynomial f

private int[]

Returns:

gcd(f, g)
gcd
(int[]
the first polynomial
f
,
int[]
the second polynomial
g
)

Return the greatest common divisor of two polynomials over the field GF(2^m).

public int

Returns:

the coefficient with the given index
getCoefficient
(int
the index
index
)

Return the coefficient with the given index.

public int

Returns:

int degree of this polynomial if this is zero polynomial return -1
getDegree
()

Return the degree of this polynomial

public byte[]

Returns:

the encoded polynomial
getEncoded
()

Returns encoded polynomial, i.e., this polynomial in byte array form

public int

Returns:

the head coefficient of this polynomial
getHeadCoefficient
()

public int

Returns:

the hash code of this polynomial
hashCode
()

Overrides java.lang.Object.hashCode.

Returns a hash code value for this object.

private static int

Returns:

the head coefficient of a
headCoefficient
(int[]
the polynomial
a
)

Return the head coefficient of a polynomial.

private static boolean

Returns:

true if a and b represent the same polynomials, false otherwise
isEqual
(int[]
the first polynomial
a
,
int[]
the second polynomial
b
)

Compare two polynomials given as int arrays.

private boolean

Returns:

true if a is irreducible, false otherwise
isIrreducible
(int[]
the polynomial to check
a
)

Check a polynomial for irreducibility over the field GF(2^m).

public PolynomialGF2mSmallM

Returns:

this mod f
mod
(PolynomialGF2mSmallM
the reduction polynomial
f
)

Reduce this polynomial modulo another polynomial.

private int[]

Returns:

a mod f
mod
(int[]
the polynomial
a
,
int[]
the reduction polynomial
f
)

Reduce a polynomial modulo another polynomial.

public PolynomialGF2mSmallM

Returns:

this * divisor^(-1) mod modulus
modDiv
(PolynomialGF2mSmallM
the divisor
divisor
,
PolynomialGF2mSmallM
the reduction polynomial
modulus
)

Compute the result of the division of this polynomial by another polynomial modulo a third polynomial.

private int[]

Returns:

a * b^(-1) mod g
modDiv
(int[]
the first polynomial
a
,
int[]
the second polynomial
b
,
int[]
the reduction polynomial
g
)

Compute the result of the division of two polynomials modulo a third polynomial over the field GF(2^m).

public PolynomialGF2mSmallM

Returns:

this^(-1) mod a
modInverse
(PolynomialGF2mSmallM
the reduction polynomial
a
)

Compute the inverse of this polynomial modulo the given polynomial.

public PolynomialGF2mSmallM

Returns:

this * a mod b
modMultiply
(PolynomialGF2mSmallM
another polynomial
a
,
PolynomialGF2mSmallM
the reduction polynomial
b
)

Compute the product of this polynomial and another polynomial modulo a third polynomial.

private int[]

Returns:

a * b mod g
modMultiply
(int[]
the first polynomial
a
,
int[]
the second polynomial
b
,
int[]
the reduction polynomial
g
)

Compute the product of two polynomials modulo a third polynomial over the finite field GF(2^m).

public PolynomialGF2mSmallM[]

Returns:

PolynomialGF2mSmallM[] {a,b} with b*this = a mod g and deg(a)<= deg(g)/2
modPolynomialToFracton
(PolynomialGF2mSmallM
the reduction polynomial
g
)

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.

public PolynomialGF2mSmallM

Returns:

this^2 modulo the reduction polynomial implicitly given via the squaring matrix
modSquareMatrix
(PolynomialGF2mSmallM[]
the squaring matrix
matrix
)

Square this polynomial using a squaring matrix.

public PolynomialGF2mSmallM

Returns:

this^(1/2) mod a
modSquareRoot
(PolynomialGF2mSmallM
the reduction polynomial
a
)

Compute the square root of this polynomial modulo the given polynomial.

public PolynomialGF2mSmallM

Returns:

this^(1/2) modulo the reduction polynomial implicitly given via the square root matrix
modSquareRootMatrix
(PolynomialGF2mSmallM[]
the matrix for computing square roots in (GF(2^m))^t the polynomial ring defining the square root matrix
matrix
)

Compute the square root of this polynomial using a square root matrix.

public PolynomialGF2mSmallM

Returns:

this * factor
multiply
(PolynomialGF2mSmallM
the polynomial
factor
)

Compute the product of this polynomial and the given factor using a Karatzuba like scheme.

private int[]

Returns:

a * b
multiply
(int[]
the first polynomial
a
,
int[]
the second polynomial
b
)

Compute the product of two polynomials over the field GF(2^m) using a Karatzuba like multiplication.

public void
multThisWithElement(int
an element of the finite field GF(2^m)
element
)

Multiply this polynomial with an element from GF(2^m).

public PolynomialGF2mSmallM

Returns:

this * element (newly created)
multWithElement
(int
an element of the finite field GF(2^m)
element
)

Compute the product of this polynomial with an element from GF(2^m).

private int[]

Returns:

a * element
multWithElement
(int[]
the polynomial
a
,
int
an element of the finite field GF(2^m)
element
)

Compute the product of a polynomial a with an element from the finite field GF(2^m).

public PolynomialGF2mSmallM

Returns:

this * X^k
multWithMonomial
(int
the degree of the monomial
k
)

Compute the product of this polynomial with a monomial X^k.

private static int[]

Returns:

a * X^k
multWithMonomial
(int[]
the polynomial
a
,
int
the degree of the monomial
k
)

Compute the product of a polynomial with a monomial X^k.

private static int[]

Returns:

the reduced polynomial
normalForm
(int[]
the polynomial
a
)

Strip leading zero coefficients from the given polynomial.

public String

Returns:

a human readable form of the polynomial.
toString
()

Overrides java.lang.Object.toString.

Returns a human readable form of the polynomial.

Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAllwaitwaitwait

Field Detail

coefficientsback to summary
private int[] coefficients

For the polynomial representation the map f: R->Z*, poly(X) -> [coef_0, coef_1, ...] is used, where coef_i is the ith coefficient of the polynomial represented as int (see GF2mField). The polynomials are stored as int arrays.

degreeback to summary
private int degree

the degree of this polynomial

fieldback to summary
private GF2mField field

the finite field GF(2^m)

RANDOM_IRREDUCIBLE_POLYNOMIALback to summary
public static final char RANDOM_IRREDUCIBLE_POLYNOMIAL

Constant used for polynomial construction (see constructor PolynomialGF2mSmallM(GF2mField, int, char, SecureRandom)).

Constructor Detail

PolynomialGF2mSmallMback to summary
public PolynomialGF2mSmallM(GF2mField field)

Construct the zero polynomial over the finite field GF(2^m).

Parameters
field:GF2mField

the finite field GF(2^m)

PolynomialGF2mSmallMback to summary
public PolynomialGF2mSmallM(GF2mField field, int deg, char typeOfPolynomial, SecureRandom sr)

Construct a polynomial over the finite field GF(2^m).

Parameters
field:GF2mField

the finite field GF(2^m)

deg:int

degree of polynomial

typeOfPolynomial:char

type of polynomial

sr:SecureRandom

PRNG

PolynomialGF2mSmallMback to summary
public PolynomialGF2mSmallM(GF2mField field, int degree)

Construct a monomial of the given degree over the finite field GF(2^m).

Parameters
field:GF2mField

the finite field GF(2^m)

degree:int

the degree of the monomial

PolynomialGF2mSmallMback to summary
public PolynomialGF2mSmallM(GF2mField field, int[] coeffs)

Construct the polynomial over the given finite field GF(2^m) from the given coefficient vector.

Parameters
field:GF2mField

finite field GF2m

coeffs:int[]

the coefficient vector

PolynomialGF2mSmallMback to summary
public PolynomialGF2mSmallM(GF2mField field, byte[] enc)

Create a polynomial over the finite field GF(2^m).

Parameters
field:GF2mField

the finite field GF(2^m)

enc:byte[]

byte[] polynomial in byte array form

PolynomialGF2mSmallMback to summary
public PolynomialGF2mSmallM(PolynomialGF2mSmallM other)

Copy constructor.

Parameters
other:PolynomialGF2mSmallM

another PolynomialGF2mSmallM

PolynomialGF2mSmallMback to summary
public PolynomialGF2mSmallM(GF2mVector vect)

Create a polynomial over the finite field GF(2^m) out of the given coefficient vector. The finite field is also obtained from the GF2mVector.

Parameters
vect:GF2mVector

the coefficient vector

Method Detail

addback to summary
public PolynomialGF2mSmallM add(PolynomialGF2mSmallM addend)

Compute the sum of this polynomial and the given polynomial.

Parameters
addend:PolynomialGF2mSmallM

the addend

Returns:PolynomialGF2mSmallM

this + a (newly created)

addback to summary
private int[] add(int[] a, int[] b)

Compute the sum of two polynomials a and b over the finite field GF(2^m).

Parameters
a:int[]

the first polynomial

b:int[]

the second polynomial

Returns:int[]

a + b

addMonomialback to summary
public PolynomialGF2mSmallM addMonomial(int degree)

Compute the sum of this polynomial and the monomial of the given degree.

Parameters
degree:int

the degree of the monomial

Returns:PolynomialGF2mSmallM

this + X^k

addToThisback to summary
public void addToThis(PolynomialGF2mSmallM addend)

Add the given polynomial to this polynomial (overwrite this).

Parameters
addend:PolynomialGF2mSmallM

the addend

computeDegreeback to summary
private void computeDegree()

Compute the degree of this polynomial. If this is the zero polynomial, the degree is -1.

computeDegreeback to summary
private static int computeDegree(int[] a)

Compute the degree of a polynomial.

Parameters
a:int[]

the polynomial

Returns:int

the degree of the polynomial a. If a is the zero polynomial, return -1.

createRandomIrreduciblePolynomialback to summary
private int[] createRandomIrreduciblePolynomial(int deg, SecureRandom sr)

Create an irreducible polynomial with the given degree over the field GF(2^m).

Parameters
deg:int

polynomial degree

sr:SecureRandom

source of randomness

Returns:int[]

the generated irreducible polynomial

divback to summary
public PolynomialGF2mSmallM[] div(PolynomialGF2mSmallM f)

Divide this polynomial by the given polynomial.

Parameters
f:PolynomialGF2mSmallM

a polynomial

Returns:PolynomialGF2mSmallM[]

polynomial pair = {q,r} where this = q*f+r and deg(r) < deg(f);

divback to summary
private int[][] div(int[] a, int[] f)

Compute the result of the division of two polynomials over the field GF(2^m).

Parameters
a:int[]

the first polynomial

f:int[]

the second polynomial

Returns:int[][]

int[][] {q,r}, where a = q*f+r and deg(r) < deg(f);

equalsback to summary
public boolean equals(Object other)

Overrides java.lang.Object.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).

Parameters
other:Object

object

Returns:boolean

true or false

evaluateAtback to summary
public int evaluateAt(int e)

Evaluate this polynomial p at a value e (in GF(2^m)) with the Horner scheme.

Parameters
e:int

the element of the finite field GF(2^m)

Returns:int

this(e)

gcdback to summary
public PolynomialGF2mSmallM gcd(PolynomialGF2mSmallM f)

Return the greatest common divisor of this and a polynomial f

Parameters
f:PolynomialGF2mSmallM

polynomial

Returns:PolynomialGF2mSmallM

GCD(this, f)

gcdback to summary
private int[] gcd(int[] f, int[] g)

Return the greatest common divisor of two polynomials over the field GF(2^m).

Parameters
f:int[]

the first polynomial

g:int[]

the second polynomial

Returns:int[]

gcd(f, g)

getCoefficientback to summary
public int getCoefficient(int index)

Return the coefficient with the given index.

Parameters
index:int

the index

Returns:int

the coefficient with the given index

getDegreeback to summary
public int getDegree()

Return the degree of this polynomial

Returns:int

int degree of this polynomial if this is zero polynomial return -1

getEncodedback to summary
public byte[] getEncoded()

Returns encoded polynomial, i.e., this polynomial in byte array form

Returns:byte[]

the encoded polynomial

getHeadCoefficientback to summary
public int getHeadCoefficient()
Returns:int

the head coefficient of this polynomial

hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Doc from java.lang.Object.hashCode.

Returns a hash code value for this object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
Returns:int

the hash code of this polynomial

headCoefficientback to summary
private static int headCoefficient(int[] a)

Return the head coefficient of a polynomial.

Parameters
a:int[]

the polynomial

Returns:int

the head coefficient of a

isEqualback to summary
private static boolean isEqual(int[] a, int[] b)

Compare two polynomials given as int arrays.

Parameters
a:int[]

the first polynomial

b:int[]

the second polynomial

Returns:boolean

true if a and b represent the same polynomials, false otherwise

isIrreducibleback to summary
private boolean isIrreducible(int[] a)

Check a polynomial for irreducibility over the field GF(2^m).

Parameters
a:int[]

the polynomial to check

Returns:boolean

true if a is irreducible, false otherwise

modback to summary
public PolynomialGF2mSmallM mod(PolynomialGF2mSmallM f)

Reduce this polynomial modulo another polynomial.

Parameters
f:PolynomialGF2mSmallM

the reduction polynomial

Returns:PolynomialGF2mSmallM

this mod f

modback to summary
private int[] mod(int[] a, int[] f)

Reduce a polynomial modulo another polynomial.

Parameters
a:int[]

the polynomial

f:int[]

the reduction polynomial

Returns:int[]

a mod f

modDivback to summary
public PolynomialGF2mSmallM modDiv(PolynomialGF2mSmallM divisor, PolynomialGF2mSmallM modulus)

Compute the result of the division of this polynomial by another polynomial modulo a third polynomial.

Parameters
divisor:PolynomialGF2mSmallM

the divisor

modulus:PolynomialGF2mSmallM

the reduction polynomial

Returns:PolynomialGF2mSmallM

this * divisor^(-1) mod modulus

modDivback to summary
private int[] modDiv(int[] a, int[] b, int[] g)

Compute the result of the division of two polynomials modulo a third polynomial over the field GF(2^m).

Parameters
a:int[]

the first polynomial

b:int[]

the second polynomial

g:int[]

the reduction polynomial

Returns:int[]

a * b^(-1) mod g

modInverseback to summary
public PolynomialGF2mSmallM modInverse(PolynomialGF2mSmallM a)

Compute the inverse of this polynomial modulo the given polynomial.

Parameters
a:PolynomialGF2mSmallM

the reduction polynomial

Returns:PolynomialGF2mSmallM

this^(-1) mod a

modMultiplyback to summary
public PolynomialGF2mSmallM modMultiply(PolynomialGF2mSmallM a, PolynomialGF2mSmallM b)

Compute the product of this polynomial and another polynomial modulo a third polynomial.

Parameters
a:PolynomialGF2mSmallM

another polynomial

b:PolynomialGF2mSmallM

the reduction polynomial

Returns:PolynomialGF2mSmallM

this * a mod b

modMultiplyback to summary
private int[] modMultiply(int[] a, int[] b, int[] g)

Compute the product of two polynomials modulo a third polynomial over the finite field GF(2^m).

Parameters
a:int[]

the first polynomial

b:int[]

the second polynomial

g:int[]

the reduction polynomial

Returns:int[]

a * b mod g

modPolynomialToFractonback to summary
public PolynomialGF2mSmallM[] modPolynomialToFracton(PolynomialGF2mSmallM g)

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:PolynomialGF2mSmallM

the reduction polynomial

Returns:PolynomialGF2mSmallM[]

PolynomialGF2mSmallM[] {a,b} with b*this = a mod g and deg(a)<= deg(g)/2

modSquareMatrixback to summary
public PolynomialGF2mSmallM modSquareMatrix(PolynomialGF2mSmallM[] matrix)

Square this polynomial using a squaring matrix.

Parameters
matrix:PolynomialGF2mSmallM[]

the squaring matrix

Returns:PolynomialGF2mSmallM

this^2 modulo the reduction polynomial implicitly given via the squaring matrix

modSquareRootback to summary
public PolynomialGF2mSmallM modSquareRoot(PolynomialGF2mSmallM a)

Compute the square root of this polynomial modulo the given polynomial.

Parameters
a:PolynomialGF2mSmallM

the reduction polynomial

Returns:PolynomialGF2mSmallM

this^(1/2) mod a

modSquareRootMatrixback to summary
public PolynomialGF2mSmallM modSquareRootMatrix(PolynomialGF2mSmallM[] matrix)

Compute the square root of this polynomial using a square root matrix.

Parameters
matrix:PolynomialGF2mSmallM[]

the matrix for computing square roots in (GF(2^m))^t the polynomial ring defining the square root matrix

Returns:PolynomialGF2mSmallM

this^(1/2) modulo the reduction polynomial implicitly given via the square root matrix

multiplyback to summary
public PolynomialGF2mSmallM multiply(PolynomialGF2mSmallM factor)

Compute the product of this polynomial and the given factor using a Karatzuba like scheme.

Parameters
factor:PolynomialGF2mSmallM

the polynomial

Returns:PolynomialGF2mSmallM

this * factor

multiplyback to summary
private int[] multiply(int[] a, int[] b)

Compute the product of two polynomials over the field GF(2^m) using a Karatzuba like multiplication.

Parameters
a:int[]

the first polynomial

b:int[]

the second polynomial

Returns:int[]

a * b

multThisWithElementback to summary
public void multThisWithElement(int element)

Multiply this polynomial with an element from GF(2^m).

Parameters
element:int

an element of the finite field GF(2^m)

Exceptions
ArithmeticException:
if element is not an element of the finite field this polynomial is defined over.
multWithElementback to summary
public PolynomialGF2mSmallM multWithElement(int element)

Compute the product of this polynomial with an element from GF(2^m).

Parameters
element:int

an element of the finite field GF(2^m)

Returns:PolynomialGF2mSmallM

this * element (newly created)

Exceptions
ArithmeticException:
if element is not an element of the finite field this polynomial is defined over.
multWithElementback to summary
private int[] multWithElement(int[] a, int element)

Compute the product of a polynomial a with an element from the finite field GF(2^m).

Parameters
a:int[]

the polynomial

element:int

an element of the finite field GF(2^m)

Returns:int[]

a * element

multWithMonomialback to summary
public PolynomialGF2mSmallM multWithMonomial(int k)

Compute the product of this polynomial with a monomial X^k.

Parameters
k:int

the degree of the monomial

Returns:PolynomialGF2mSmallM

this * X^k

multWithMonomialback to summary
private static int[] multWithMonomial(int[] a, int k)

Compute the product of a polynomial with a monomial X^k.

Parameters
a:int[]

the polynomial

k:int

the degree of the monomial

Returns:int[]

a * X^k

normalFormback to summary
private static int[] normalForm(int[] a)

Strip leading zero coefficients from the given polynomial.

Parameters
a:int[]

the polynomial

Returns:int[]

the reduced polynomial

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Returns a human readable form of the polynomial.

Returns:String

a human readable form of the polynomial.