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

public Class SparseTernaryPolynomial

extends Object
implements TernaryPolynomial
Class Inheritance
All Implemented Interfaces
org.bouncycastle.pqc.legacy.math.ntru.polynomial.TernaryPolynomial, org.bouncycastle.pqc.legacy.math.ntru.polynomial.Polynomial
Imports
java.io.IOException, .InputStream, java.math.BigInteger, java.security.SecureRandom, org.bouncycastle.pqc.legacy.math.ntru.util.ArrayEncoder, .Util, org.bouncycastle.util.Arrays

A TernaryPolynomial with a "low" number of nonzero coefficients.

Field Summary

Modifier and TypeField and Description
private static final int
BITS_PER_INDEX

Number of bits to use for each coefficient.

private int
N

private int[]
private int[]

Constructor Summary

AccessConstructor and Description
pack-priv
SparseTernaryPolynomial(int
total number of coefficients including zeros
N
,
int[]
indices of coefficients equal to 1
ones
,
int[]
indices of coefficients equal to -1
negOnes
)

Constructs a new polynomial.

public
SparseTernaryPolynomial(IntegerPolynomial
the original polynomial
intPoly
)

Constructs a DenseTernaryPolynomial from a IntegerPolynomial.

public
SparseTernaryPolynomial(int[]
the coefficients
coeffs
)

Constructs a new SparseTernaryPolynomial with a given set of coefficients.

Method Summary

Modifier and TypeMethod and Description
public void
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.

public static SparseTernaryPolynomial

Returns:

the decoded polynomial
fromBinary
(InputStream
an input stream containing an encoded polynomial
is
,
int
number of coefficients including zeros
N
,
int
number of coefficients equal to 1
numOnes
,
int
number of coefficients equal to -1
numNegOnes
)

Decodes a byte array encoded with toBinary() to a ploynomial.

public static SparseTernaryPolynomial
generateRandom(int
number of coefficients
N
,
int
number of 1's
numOnes
,
int
number of -1's
numNegOnes
,
SecureRandom random)

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

public int[]
public int[]
public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for this object.

public IntegerPolynomial
mult(IntegerPolynomial
a polynomial
poly2
)

Implements org.bouncycastle.pqc.legacy.math.ntru.polynomial.TernaryPolynomial.mult.

Multiplies the polynomial by an IntegerPolynomial, taking the indices mod N

public IntegerPolynomial
mult(IntegerPolynomial
a polynomial
poly2
,
int
a modulus to apply
modulus
)

Implements org.bouncycastle.pqc.legacy.math.ntru.polynomial.Polynomial.mult.

Multiplies the polynomial by an IntegerPolynomial, taking the coefficient values mod modulus and the indices mod N.

public BigIntPolynomial
mult(BigIntPolynomial
the polynomial to multiply by
poly2
)

Implements org.bouncycastle.pqc.legacy.math.ntru.polynomial.Polynomial.mult.

Multiplies the polynomial by a BigIntPolynomial, taking the indices mod N.

public int
size()

Implements org.bouncycastle.pqc.legacy.math.ntru.polynomial.TernaryPolynomial.size.

Returns the maximum number of coefficients the polynomial can have

public byte[]

Returns:

the encoded polynomial
toBinary
()

Encodes the polynomial to a byte array writing BITS_PER_INDEX bits for each coefficient.

public IntegerPolynomial
toIntegerPolynomial()

Implements org.bouncycastle.pqc.legacy.math.ntru.polynomial.Polynomial.toIntegerPolynomial.

Returns a polynomial that is equal to this polynomial (in the sense that mult(IntegerPolynomial, int) returns equal IntegerPolynomials).

Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAlltoStringwaitwaitwait

Field Detail

BITS_PER_INDEXback to summary
private static final int BITS_PER_INDEX

Number of bits to use for each coefficient. Determines the upper bound for N.

Nback to summary
private int N
negOnesback to summary
private int[] negOnes
onesback to summary
private int[] ones

Constructor Detail

SparseTernaryPolynomialback to summary
pack-priv SparseTernaryPolynomial(int N, int[] ones, int[] negOnes)

Constructs a new polynomial.

Parameters
N:int

total number of coefficients including zeros

ones:int[]

indices of coefficients equal to 1

negOnes:int[]

indices of coefficients equal to -1

SparseTernaryPolynomialback to summary
public SparseTernaryPolynomial(IntegerPolynomial intPoly)

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

Parameters
intPoly:IntegerPolynomial

the original polynomial

SparseTernaryPolynomialback to summary
public SparseTernaryPolynomial(int[] coeffs)

Constructs a new SparseTernaryPolynomial with a given set of coefficients.

Parameters
coeffs:int[]

the coefficients

Method Detail

clearback to summary
public void clear()

Implements org.bouncycastle.pqc.legacy.math.ntru.polynomial.TernaryPolynomial.clear.

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.

fromBinaryback to summary
public static SparseTernaryPolynomial fromBinary(InputStream is, int N, int numOnes, int numNegOnes) throws IOException

Decodes a byte array encoded with toBinary() to a ploynomial.

Parameters
is:InputStream

an input stream containing an encoded polynomial

N:int

number of coefficients including zeros

numOnes:int

number of coefficients equal to 1

numNegOnes:int

number of coefficients equal to -1

Returns:SparseTernaryPolynomial

the decoded polynomial

generateRandomback to summary
public static SparseTernaryPolynomial generateRandom(int N, int numOnes, int numNegOnes, SecureRandom random)

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

getNegOnesback to summary
public int[] getNegOnes()

Implements org.bouncycastle.pqc.legacy.math.ntru.polynomial.TernaryPolynomial.getNegOnes.

getOnesback to summary
public int[] getOnes()

Implements org.bouncycastle.pqc.legacy.math.ntru.polynomial.TernaryPolynomial.getOnes.

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

a hash code value for this object

multback to summary
public IntegerPolynomial mult(IntegerPolynomial poly2)

Implements org.bouncycastle.pqc.legacy.math.ntru.polynomial.TernaryPolynomial.mult.

Doc from org.bouncycastle.pqc.legacy.math.ntru.polynomial.TernaryPolynomial.mult.

Multiplies the polynomial by an IntegerPolynomial, taking the indices mod N

Parameters
poly2:IntegerPolynomial

Doc from org.bouncycastle.pqc.legacy.math.ntru.polynomial.Polynomial.mult.

a polynomial

Returns:IntegerPolynomial

Doc from org.bouncycastle.pqc.legacy.math.ntru.polynomial.Polynomial.mult.

the product of the two polynomials

multback to summary
public IntegerPolynomial mult(IntegerPolynomial poly2, int modulus)

Implements org.bouncycastle.pqc.legacy.math.ntru.polynomial.Polynomial.mult.

Doc from org.bouncycastle.pqc.legacy.math.ntru.polynomial.Polynomial.mult.

Multiplies the polynomial by an IntegerPolynomial, taking the coefficient values mod modulus and the indices mod N.

Parameters
poly2:IntegerPolynomial

a polynomial

modulus:int

a modulus to apply

Returns:IntegerPolynomial

the product of the two polynomials

multback to summary
public BigIntPolynomial mult(BigIntPolynomial poly2)

Implements org.bouncycastle.pqc.legacy.math.ntru.polynomial.Polynomial.mult.

Doc from org.bouncycastle.pqc.legacy.math.ntru.polynomial.Polynomial.mult.

Multiplies the polynomial by a BigIntPolynomial, 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

sizeback to summary
public int size()

Implements org.bouncycastle.pqc.legacy.math.ntru.polynomial.TernaryPolynomial.size.

Doc from org.bouncycastle.pqc.legacy.math.ntru.polynomial.TernaryPolynomial.size.

Returns the maximum number of coefficients the polynomial can have

toBinaryback to summary
public byte[] toBinary()

Encodes the polynomial to a byte array writing BITS_PER_INDEX bits for each coefficient.

Returns:byte[]

the encoded polynomial

toIntegerPolynomialback to summary
public IntegerPolynomial toIntegerPolynomial()

Implements org.bouncycastle.pqc.legacy.math.ntru.polynomial.Polynomial.toIntegerPolynomial.

Doc from org.bouncycastle.pqc.legacy.math.ntru.polynomial.Polynomial.toIntegerPolynomial.

Returns a polynomial that is equal to this polynomial (in the sense that mult(IntegerPolynomial, int) returns equal IntegerPolynomials). The new polynomial is guaranteed to be independent of the original.

Returns:IntegerPolynomial

a new IntegerPolynomial.