java.lang.Object
org.bouncycastle.pqc.crypto.mlkem.Ntt
Number Theoretic Transform (NTT) implementation for ML-KEM operations. Provides efficient polynomial multiplication using number theoretic transforms.
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final short[]Zeta multipliers for the forward transform, one per butterfly stage.static final short[]Zeta multipliers for the inverse transform, in the reverse of the forward order.Constructor Summary
ConstructorsMethod Summary
All MethodsModifier and TypeMethodDescriptionstatic voidMultiply two degree-1 polynomials, scaling the leading product by a stage zeta.static shortfactorQMulMont(short a, short b) Multiply two coefficients modulo q, in Montgomery form.static short[]invNtt(short[] inp) Apply the inverse number theoretic transform to a transformed polynomial.static short[]ntt(short[] inp) Apply the forward number theoretic transform to a degree-254 polynomial.
Field Details
nttZetas
public static final short[] nttZetasZeta multipliers for the forward transform, one per butterfly stage.nttZetasInv
public static final short[] nttZetasInvZeta multipliers for the inverse transform, in the reverse of the forward order.
Constructor Details
Ntt
public Ntt()Create an instance. Every operation in this class is static, so the instance carries no state.
Method Details
ntt
public static short[] ntt(short[] inp) Apply the forward number theoretic transform to a degree-254 polynomial.- Parameters:
inp- the 256 coefficients to transform in place- Returns:
- a new array holding the forward number theoretic transform of inp
invNtt
public static short[] invNtt(short[] inp) Apply the inverse number theoretic transform to a transformed polynomial.- Parameters:
inp- the 256 coefficients to transform back- Returns:
- a new array holding the inverse number theoretic transform of inp
factorQMulMont
public static short factorQMulMont(short a, short b) Multiply two coefficients modulo q, in Montgomery form.- Parameters:
a- the first multiplicand, a signed short coefficientb- the second multiplicand, a signed short coefficient- Returns:
- the Montgomery reduction of the product of a and b, modulo q
baseMult
public static void baseMult(Poly outPoly, int outIndex, short a0, short a1, short b0, short b1, short zeta) Multiply two degree-1 polynomials, scaling the leading product by a stage zeta.- Parameters:
outPoly- the polynomial receiving the two computed coefficientsoutIndex- the index in outPoly at which to store thema0- the first coefficient of the left operand polynomiala1- the second coefficient of the left operand polynomialb0- the first coefficient of the right operand polynomialb1- the second coefficient of the right operand polynomialzeta- the root of unity supplied by the caller for this butterfly stage