java.lang.Object
org.bouncycastle.pqc.crypto.mlkem.PolyVec
Vector of polynomials for ML-KEM operations. Provides operations on collections of polynomials used in lattice cryptography.
Field Summary
FieldsModifier and TypeFieldDescriptionprivate MLKEMEngineThe engine whose arithmetic this vector uses.private intHow many polynomials the vector holds.private intLength of the encoded vector, in bytes.(package private) Poly[]The polynomials held by this vector, in order, always kyberK long.Constructor Summary
ConstructorsConstructorDescriptionPolyVec()Create a vector that refuses to be sized.PolyVec(MLKEMEngine engine) Create a vector sized from the engine's Kyber parameter set.Method Summary
Modifier and TypeMethodDescriptionvoidAdd another vector's coefficients into this one, in place.byte[]Reduce every coefficient modulo q and pack the vector for transmission.voidConditionally subtract q from every coefficient, in place.voiddecompressPolyVec(byte[] compressedPolyVecCipherText) Expand a packed vector back into this vector's coefficients, in place.voidfromBytes(byte[] inputBytes) Split a packed vector into this vector's polynomials, in place.getVectorIndex(int i) Get the polynomial stored at a position in this vector.static voidpointwiseAccountMontgomery(Poly out, PolyVec inp1, PolyVec inp2, MLKEMEngine engine) Multiply two vectors pointwise and sum the products into a polynomial.voidInverse number theoretic transform every polynomial in this vector, in place.voidForward number theoretic transform every polynomial in this vector, in place.voidReduce every polynomial in this vector, in place.byte[]toBytes()Pack every polynomial in this vector into a single buffer.toString()Render the vector as its polynomials' coefficient listings.
Field Details
vec
Poly[] vecThe polynomials held by this vector, in order, always kyberK long.engine
The engine whose arithmetic this vector uses.kyberK
private int kyberKHow many polynomials the vector holds.polyVecBytes
private int polyVecBytesLength of the encoded vector, in bytes.
Constructor Details
PolyVec
Create a vector sized from the engine's Kyber parameter set.- Parameters:
engine- the engine supplying the KyberK and vector byte-length parameters
PolyVec
Method Details
getVectorIndex
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 productsinp1- the first multiplicand vectorinp2- the second multiplicand vectorengine- the engine supplying KyberK and the polynomial size
reducePoly
public void reducePoly()Reduce every polynomial in this vector, in place.addPoly
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