Top Description Fields Constructors Methods
org.bouncycastle.pqc.legacy.math.ntru.polynomial

public Class BigIntPolynomial

extends Object
Class Inheritance
Imports
java.math.BigDecimal, .BigInteger, java.util.ArrayList, .Collections, .List, org.bouncycastle.crypto.CryptoServicesRegistrar, org.bouncycastle.util.Arrays

A polynomial with BigInteger coefficients.
Some methods (like add) change the polynomial, others (like mult) do not but return the result as a new polynomial.

Field Summary

Modifier and TypeField and Description
pack-priv BigInteger[]
private static final double

Constructor Summary

AccessConstructor and Description
pack-priv
BigIntPolynomial(int
the number of coefficients
N
)

Constructs a new polynomial with N coefficients initialized to 0.

pack-priv
BigIntPolynomial(BigInteger[]
the coefficients
coeffs
)

Constructs a new polynomial with a given set of coefficients.

public
BigIntPolynomial(IntegerPolynomial
the original polynomial
p
)

Constructs a BigIntPolynomial from a IntegerPolynomial.

Method Summary

Modifier and TypeMethod and Description
pack-priv void
add(BigIntPolynomial
another polynomial
b
,
BigInteger modulus)

Adds another polynomial which can have a different number of coefficients, and takes the coefficient values mod modulus.

public void
add(BigIntPolynomial
another polynomial
b
)

Adds another polynomial which can have a different number of coefficients.

public Object
clone()

Overrides java.lang.Object.clone.

Makes a copy of the polynomial that is independent of the original.
public void
div(BigInteger
the number to divide by
divisor
)

Divides each coefficient by a BigInteger and rounds the result to the nearest whole number.

public BigDecimalPolynomial

Returns:

a new BigDecimalPolynomial
div
(BigDecimal
the number to divide by
divisor
,
int
the number of fractional digits to round the result to
decimalPlaces
)

Divides each coefficient by a BigDecimal and rounds the result to decimalPlaces places.

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

Overrides java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.
pack-priv static BigIntPolynomial

Returns:

a random polynomial.
generateRandomSmall
(int
number of coefficients
N
,
int
number of 1's
numOnes
,
int
number of -1's
numNegOnes
)

Generates a random polynomial with numOnes coefficients equal to 1, numNegOnes coefficients equal to -1, and the rest equal to 0.

public BigInteger[]
public int

Returns:

length of the longest coefficient
getMaxCoeffLength
()

Returns the base10 length of the largest coefficient.

public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for the object.
private BigInteger
public void
mod(BigInteger modulus)

Takes each coefficient modulo a number.

public BigIntPolynomial

Returns:

a new polynomial
mult
(BigIntPolynomial
the polynomial to multiply by
poly2
)

Multiplies the polynomial by another, taking the indices mod N.

public void
mult(BigInteger factor)

Multiplies each coefficient by a BigInteger.

pack-priv void
mult(int factor)

Multiplies each coefficient by a int.

private BigIntPolynomial
multRecursive(BigIntPolynomial poly2)

Karazuba multiplication

public void
sub(BigIntPolynomial
another polynomial
b
)

Subtracts another polynomial which can have a different number of coefficients.

pack-priv BigInteger

Returns:

the sum of all coefficients
sumCoeffs
()

Returns the sum of all coefficients, i.e. evaluates the polynomial at 0.

Inherited from java.lang.Object:
finalizegetClassnotifynotifyAlltoStringwaitwaitwait

Field Detail

coeffsback to summary
pack-priv BigInteger[] coeffs
LOG_10_2back to summary
private static final double LOG_10_2

Constructor Detail

BigIntPolynomialback to summary
pack-priv BigIntPolynomial(int N)

Constructs a new polynomial with N coefficients initialized to 0.

Parameters
N:int

the number of coefficients

BigIntPolynomialback to summary
pack-priv BigIntPolynomial(BigInteger[] coeffs)

Constructs a new polynomial with a given set of coefficients.

Parameters
coeffs:BigInteger[]

the coefficients

BigIntPolynomialback to summary
public BigIntPolynomial(IntegerPolynomial p)

Constructs a BigIntPolynomial from a IntegerPolynomial. The two polynomials are independent of each other.

Parameters
p:IntegerPolynomial

the original polynomial

Method Detail

addback to summary
pack-priv void add(BigIntPolynomial b, BigInteger modulus)

Adds another polynomial which can have a different number of coefficients, and takes the coefficient values mod modulus.

Parameters
b:BigIntPolynomial

another polynomial

addback to summary
public void add(BigIntPolynomial b)

Adds another polynomial which can have a different number of coefficients.

Parameters
b:BigIntPolynomial

another polynomial

cloneback to summary
public Object clone()

Overrides java.lang.Object.clone.

Makes a copy of the polynomial that is independent of the original.

Returns:Object

Doc from java.lang.Object.clone.

a clone of this instance.

divback to summary
public void div(BigInteger divisor)

Divides each coefficient by a BigInteger and rounds the result to the nearest whole number.
Does not return a new polynomial but modifies this polynomial.

Parameters
divisor:BigInteger

the number to divide by

divback to summary
public BigDecimalPolynomial div(BigDecimal divisor, int decimalPlaces)

Divides each coefficient by a BigDecimal and rounds the result to decimalPlaces places.

Parameters
divisor:BigDecimal

the number to divide by

decimalPlaces:int

the number of fractional digits to round the result to

Returns:BigDecimalPolynomial

a new BigDecimalPolynomial

equalsback to summary
public boolean equals(Object obj)

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
obj:Object

the reference object with which to compare.

Returns:boolean

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

generateRandomSmallback to summary
pack-priv static BigIntPolynomial generateRandomSmall(int N, int numOnes, int numNegOnes)

Generates a random polynomial with numOnes coefficients equal to 1, numNegOnes coefficients equal to -1, and the rest equal to 0.

Parameters
N:int

number of coefficients

numOnes:int

number of 1's

numNegOnes:int

number of -1's

Returns:BigIntPolynomial

a random polynomial.

getCoeffsback to summary
public BigInteger[] getCoeffs()
getMaxCoeffLengthback to summary
public int getMaxCoeffLength()

Returns the base10 length of the largest coefficient.

Returns:int

length of the longest coefficient

hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Doc from java.lang.Object.hashCode.

Returns a hash code value for the 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

a hash code value for this object.

maxCoeffAbsback to summary
private BigInteger maxCoeffAbs()
modback to summary
public void mod(BigInteger modulus)

Takes each coefficient modulo a number.

multback to summary
public BigIntPolynomial mult(BigIntPolynomial poly2)

Multiplies the polynomial by another, taking the indices mod N. Does not change this polynomial but returns the result as a new polynomial.
Both polynomials must have the same number of coefficients.

Parameters
poly2:BigIntPolynomial

the polynomial to multiply by

Returns:BigIntPolynomial

a new polynomial

multback to summary
public void mult(BigInteger factor)

Multiplies each coefficient by a BigInteger. Does not return a new polynomial but modifies this polynomial.

multback to summary
pack-priv void mult(int factor)

Multiplies each coefficient by a int. Does not return a new polynomial but modifies this polynomial.

multRecursiveback to summary
private BigIntPolynomial multRecursive(BigIntPolynomial poly2)

Karazuba multiplication

subback to summary
public void sub(BigIntPolynomial b)

Subtracts another polynomial which can have a different number of coefficients.

Parameters
b:BigIntPolynomial

another polynomial

sumCoeffsback to summary
pack-priv BigInteger sumCoeffs()

Returns the sum of all coefficients, i.e. evaluates the polynomial at 0.

Returns:BigInteger

the sum of all coefficients