java.lang.Object
org.bouncycastle.pqc.crypto.mlkem.Ntt

class Nttextends Object
Number Theoretic Transform (NTT) implementation for ML-KEM operations. Provides efficient polynomial multiplication using number theoretic transforms.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static 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

    Constructors
    Constructor
    Description
    Ntt()
    Create an instance.
  • Method Summary

    All Methods
    Modifier and Type
    Method
    Description
    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.
    static short
    factorQMulMont(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.

    Methods inherited from class Object

    clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • nttZetas

      public static final short[] nttZetas
      Zeta multipliers for the forward transform, one per butterfly stage.
    • nttZetasInv

      public static final short[] nttZetasInv
      Zeta 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 coefficient
      b - 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 coefficients
      outIndex - the index in outPoly at which to store them
      a0 - the first coefficient of the left operand polynomial
      a1 - the second coefficient of the left operand polynomial
      b0 - the first coefficient of the right operand polynomial
      b1 - the second coefficient of the right operand polynomial
      zeta - the root of unity supplied by the caller for this butterfly stage