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

class PolyVecextends Object
Vector of polynomials for ML-KEM operations. Provides operations on collections of polynomials used in lattice cryptography.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private MLKEMEngine
    The engine whose arithmetic this vector uses.
    private int
    How many polynomials the vector holds.
    private int
    Length of the encoded vector, in bytes.
    (package private) Poly[]
    The polynomials held by this vector, in order, always kyberK long.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Create a vector that refuses to be sized.
    Create a vector sized from the engine's Kyber parameter set.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Add another vector's coefficients into this one, in place.
    byte[]
    Reduce every coefficient modulo q and pack the vector for transmission.
    void
    Conditionally subtract q from every coefficient, in place.
    void
    decompressPolyVec(byte[] compressedPolyVecCipherText)
    Expand a packed vector back into this vector's coefficients, in place.
    void
    fromBytes(byte[] inputBytes)
    Split a packed vector into this vector's polynomials, in place.
    Get the polynomial stored at a position in this vector.
    static void
    Multiply two vectors pointwise and sum the products into a polynomial.
    void
    Inverse number theoretic transform every polynomial in this vector, in place.
    void
    Forward number theoretic transform every polynomial in this vector, in place.
    void
    Reduce every polynomial in this vector, in place.
    byte[]
    Pack every polynomial in this vector into a single buffer.
    Render the vector as its polynomials' coefficient listings.

    Methods inherited from class Object

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

    • vec

      Poly[] vec
      The polynomials held by this vector, in order, always kyberK long.
    • engine

      private MLKEMEngine engine
      The engine whose arithmetic this vector uses.
    • kyberK

      private int kyberK
      How many polynomials the vector holds.
    • polyVecBytes

      private int polyVecBytes
      Length of the encoded vector, in bytes.
  • Constructor Details

    • PolyVec

      public PolyVec(MLKEMEngine engine)
      Create a vector sized from the engine's Kyber parameter set.
      Parameters:
      engine - the engine supplying the KyberK and vector byte-length parameters
    • PolyVec

      public PolyVec() throws Exception
      Create a vector that refuses to be sized.
      Throws:
      Exception - always, because an engine is required to size the vector
  • Method Details

    • getVectorIndex

      public Poly getVectorIndex(int i)
      Get the polynomial stored at a position in this vector.
      Parameters:
      i - the position in the vector, 0 to KyberK-1
      Returns:
      the polynomial stored at that position
    • polyVecNtt

      public void polyVecNtt()
      Forward number theoretic transform every polynomial in this vector, in place.
    • polyVecInverseNttToMont

      public void polyVecInverseNttToMont()
      Inverse number theoretic transform every polynomial in this vector, in place.
    • compressPolyVec

      public byte[] compressPolyVec()
      Reduce every coefficient modulo q and pack the vector for transmission.
      Returns:
      the packed vector, 320 or 352 bytes per polynomial depending on the engine's PolyVecCompressedBytes setting
    • decompressPolyVec

      public void decompressPolyVec(byte[] compressedPolyVecCipherText)
      Expand a packed vector back into this vector's coefficients, in place.
      Parameters:
      compressedPolyVecCipherText - the packed vector to expand back into the coefficients, in the 320 or 352 bytes per polynomial layout
    • pointwiseAccountMontgomery

      public static void pointwiseAccountMontgomery(Poly out, PolyVec inp1, PolyVec inp2, MLKEMEngine engine)
      Multiply two vectors pointwise and sum the products into a polynomial.
      Parameters:
      out - the polynomial accumulating the pointwise products
      inp1 - the first multiplicand vector
      inp2 - the second multiplicand vector
      engine - the engine supplying KyberK and the polynomial size
    • reducePoly

      public void reducePoly()
      Reduce every polynomial in this vector, in place.
    • addPoly

      public void addPoly(PolyVec b)
      Add another vector's coefficients into this one, in place.
      Parameters:
      b - the vector whose coefficients are added into this one
    • toBytes

      public byte[] toBytes()
      Pack every polynomial in this vector into a single buffer.
      Returns:
      every polynomial packed back to back at KyberPolyBytes each, giving a buffer of polyVecBytes bytes
    • fromBytes

      public void fromBytes(byte[] inputBytes)
      Split a packed vector into this vector's polynomials, in place.
      Parameters:
      inputBytes - the packed buffer, polyVecBytes long, holding each polynomial as KyberPolyBytes bytes back to back
    • conditionalSubQ

      public void conditionalSubQ()
      Conditionally subtract q from every coefficient, in place.
    • toString

      public String toString()
      Render the vector as its polynomials' coefficient listings.
      Overrides:
      toString in class Object