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

public Class GF2nPolynomial

extends Object
Class Inheritance
Imports
org.bouncycastle.util.Arrays

This class implements polynomials over GF2nElements.
See Also
GF2nElement

Field Summary

Modifier and TypeField and Description
private GF2nElement[]
private int

Constructor Summary

AccessConstructor and Description
public
GF2nPolynomial(int
- the maximum degree + 1
deg
,
GF2nElement
- a GF2nElement
elem
)

Creates a new PolynomialGF2n of size deg and elem as coefficients.

private
GF2nPolynomial(int
the maximum degree + 1
deg
)

Creates a new PolynomialGF2n of size deg.

public
GF2nPolynomial(GF2nPolynomial
the PolynomialGF2n to clone
a
)

Creates a new PolynomialGF2n by cloning the given PolynomialGF2n a.

public
GF2nPolynomial(GF2Polynomial
the Bitstring to use
polynomial
,
GF2nField
the field
B1
)

Creates a new PolynomialGF2n from the given Bitstring polynomial over the GF2nField B1.

Method Summary

Modifier and TypeMethod and Description
public final GF2nPolynomial

Returns:

this + b
add
(GF2nPolynomial
- the PolynomialGF2n to add
b
)

Adds the PolynomialGF2n b to this and returns the result in a new PolynomialGF2n.

public final void
public final GF2nElement

Returns:

the GF2nElement stored as coefficient index
at
(int
the index
index
)

Returns the coefficient at index.

public final GF2nPolynomial[]

Returns:

the quotient and remainder of this / b
divide
(GF2nPolynomial
the divisor
b
)

Divides this by b and stores the result in a new PolynomialGF2n[2], quotient in result[0] and remainder in result[1].

public final void
enlarge(int
the new maximum degree
k
)

Enlarges the size of this PolynomialGF2n to k + 1.

public final boolean
equals(Object
the reference object with which to compare.
other
)

Overrides java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

public final GF2nPolynomial

Returns:

gcd(this, g)
gcd
(GF2nPolynomial
- a GF2nPolynomial
g
)

Computes the greatest common divisor of this and g and returns the result in a new PolynomialGF2n.

public final int

Returns:

the degree of this PolynomialGF2n.
getDegree
()

Returns the degree of this PolynomialGF2n.

public int

Returns:

the hash code of this polynomial
hashCode
()

Overrides java.lang.Object.hashCode.

Returns a hash code value for this object.

public final boolean

Returns:

true if all coefficients equal zero.
isZero
()

Returns true if all coefficients equal zero.

public final GF2nPolynomial

Returns:

this * b
multiply
(GF2nPolynomial
the PolynomialGF2n to multiply
b
)

Multiplies this by b and returns the result in a new PolynomialGF2n.

public final GF2nPolynomial

Returns:

this * b mod g
multiplyAndReduce
(GF2nPolynomial
the PolynomialGF2n to multiply
b
,
GF2nPolynomial
the modul
g
)

Multiplies this by b, reduces the result by g and returns it in a new PolynomialGF2n.

public final GF2nPolynomial

Returns:

the quotient this / b
quotient
(GF2nPolynomial
the divisor
b
)

Divides this by b and stores the quotient in a new PolynomialGF2n.

public final GF2nPolynomial

Returns:

this % g
reduce
(GF2nPolynomial
- the modulus
g
)

Reduces this by g and returns the result in a new PolynomialGF2n.

public final GF2nPolynomial

Returns:

the remainder this % b
remainder
(GF2nPolynomial
the divisor
b
)

Divides this by b and stores the remainder in a new PolynomialGF2n.

public final GF2nPolynomial

Returns:

this x s
scalarMultiply
(GF2nElement
the scalar to multiply
s
)

Multiplies the scalar s to each coefficient of this PolynomialGF2n and returns the result in a new PolynomialGF2n.

public final void
set(int
the index
index
,
GF2nElement
the GF2nElement to store as coefficient index
elem
)

Sets the coefficient at index to elem.

public final GF2nPolynomial
shiftLeft(int amount)

public final void
shiftThisLeft(int
the amount to shift the coefficients
amount
)

Shifts left this by amount and stores the result in this PolynomialGF2n.

public final void
public final int

Returns:

the size (=maximum degree + 1) of this PolynomialGF2n.
size
()

Returns the size (=maximum degree + 1) of this PolynomialGF2n.

Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAlltoStringwaitwaitwait

Field Detail

coeffback to summary
private GF2nElement[] coeff
sizeback to summary
private int size

Constructor Detail

GF2nPolynomialback to summary
public GF2nPolynomial(int deg, GF2nElement elem)

Creates a new PolynomialGF2n of size deg and elem as coefficients.

Parameters
deg:int

- the maximum degree + 1

elem:GF2nElement

- a GF2nElement

GF2nPolynomialback to summary
private GF2nPolynomial(int deg)

Creates a new PolynomialGF2n of size deg.

Parameters
deg:int

the maximum degree + 1

GF2nPolynomialback to summary
public GF2nPolynomial(GF2nPolynomial a)

Creates a new PolynomialGF2n by cloning the given PolynomialGF2n a.

Parameters
a:GF2nPolynomial

the PolynomialGF2n to clone

GF2nPolynomialback to summary
public GF2nPolynomial(GF2Polynomial polynomial, GF2nField B1)

Creates a new PolynomialGF2n from the given Bitstring polynomial over the GF2nField B1.

Parameters
polynomial:GF2Polynomial

the Bitstring to use

B1:GF2nField

the field

Method Detail

addback to summary
public final GF2nPolynomial add(GF2nPolynomial b)

Adds the PolynomialGF2n b to this and returns the result in a new PolynomialGF2n.

Parameters
b:GF2nPolynomial

- the PolynomialGF2n to add

Returns:GF2nPolynomial

this + b

assignZeroToElementsback to summary
public final void assignZeroToElements()
atback to summary
public final GF2nElement at(int index)

Returns the coefficient at index.

Parameters
index:int

the index

Returns:GF2nElement

the GF2nElement stored as coefficient index

divideback to summary
public final GF2nPolynomial[] divide(GF2nPolynomial b)

Divides this by b and stores the result in a new PolynomialGF2n[2], quotient in result[0] and remainder in result[1].

Parameters
b:GF2nPolynomial

the divisor

Returns:GF2nPolynomial[]

the quotient and remainder of this / b

enlargeback to summary
public final void enlarge(int k)

Enlarges the size of this PolynomialGF2n to k + 1.

Parameters
k:int

the new maximum degree

equalsback to summary
public final boolean equals(Object other)

Overrides java.lang.Object.equals.

Doc from java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

The equals method implements an equivalence relation on non-null object references:

  • It is reflexive: for any non-null reference value x, x.equals(x) should return true.
  • It is symmetric: for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any non-null reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.
  • It is consistent: for any non-null reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the objects is modified.
  • For any non-null reference value x, x.equals(null) should return false.

An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.

Parameters
other:Object

the reference object with which to compare.

Returns:boolean

true if this object is the same as the obj argument; false otherwise.

gcdback to summary
public final GF2nPolynomial gcd(GF2nPolynomial g)

Computes the greatest common divisor of this and g and returns the result in a new PolynomialGF2n.

Parameters
g:GF2nPolynomial

- a GF2nPolynomial

Returns:GF2nPolynomial

gcd(this, g)

getDegreeback to summary
public final int getDegree()

Returns the degree of this PolynomialGF2n.

Returns:int

the degree of this PolynomialGF2n.

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

isZeroback to summary
public final boolean isZero()

Returns true if all coefficients equal zero.

Returns:boolean

true if all coefficients equal zero.

multiplyback to summary
public final GF2nPolynomial multiply(GF2nPolynomial b)

Multiplies this by b and returns the result in a new PolynomialGF2n.

Parameters
b:GF2nPolynomial

the PolynomialGF2n to multiply

Returns:GF2nPolynomial

this * b

multiplyAndReduceback to summary
public final GF2nPolynomial multiplyAndReduce(GF2nPolynomial b, GF2nPolynomial g)

Multiplies this by b, reduces the result by g and returns it in a new PolynomialGF2n.

Parameters
b:GF2nPolynomial

the PolynomialGF2n to multiply

g:GF2nPolynomial

the modul

Returns:GF2nPolynomial

this * b mod g

quotientback to summary
public final GF2nPolynomial quotient(GF2nPolynomial b) throws RuntimeException, ArithmeticException

Divides this by b and stores the quotient in a new PolynomialGF2n.

Parameters
b:GF2nPolynomial

the divisor

Returns:GF2nPolynomial

the quotient this / b

reduceback to summary
public final GF2nPolynomial reduce(GF2nPolynomial g) throws RuntimeException, ArithmeticException

Reduces this by g and returns the result in a new PolynomialGF2n.

Parameters
g:GF2nPolynomial

- the modulus

Returns:GF2nPolynomial

this % g

remainderback to summary
public final GF2nPolynomial remainder(GF2nPolynomial b) throws RuntimeException, ArithmeticException

Divides this by b and stores the remainder in a new PolynomialGF2n.

Parameters
b:GF2nPolynomial

the divisor

Returns:GF2nPolynomial

the remainder this % b

scalarMultiplyback to summary
public final GF2nPolynomial scalarMultiply(GF2nElement s)

Multiplies the scalar s to each coefficient of this PolynomialGF2n and returns the result in a new PolynomialGF2n.

Parameters
s:GF2nElement

the scalar to multiply

Returns:GF2nPolynomial

this x s

setback to summary
public final void set(int index, GF2nElement elem)

Sets the coefficient at index to elem.

Parameters
index:int

the index

elem:GF2nElement

the GF2nElement to store as coefficient index

shiftLeftback to summary
public final GF2nPolynomial shiftLeft(int amount)
shiftThisLeftback to summary
public final void shiftThisLeft(int amount)

Shifts left this by amount and stores the result in this PolynomialGF2n.

Parameters
amount:int

the amount to shift the coefficients

shrinkback to summary
public final void shrink()
sizeback to summary
public final int size()

Returns the size (=maximum degree + 1) of this PolynomialGF2n. This is not the degree, use getDegree instead.

Returns:int

the size (=maximum degree + 1) of this PolynomialGF2n.