1- package org .bouncycastle .pqc .crypto .crystals . kyber ;
1+ package org .bouncycastle .pqc .crypto .mlkem ;
22
33import org .bouncycastle .crypto .digests .SHAKEDigest ;
44import org .bouncycastle .util .Arrays ;
5- import org .bouncycastle .util .Pack ;
65
7- class KyberIndCpa
6+ class MLKEMIndCpa
87{
9- private KyberEngine engine ;
8+ private MLKEMEngine engine ;
109 private int kyberK ;
1110 private int eta1 ;
1211 private int indCpaPublicKeyBytes ;
@@ -17,7 +16,7 @@ class KyberIndCpa
1716
1817 private Symmetric symmetric ;
1918
20- public KyberIndCpa ( KyberEngine engine )
19+ public MLKEMIndCpa ( MLKEMEngine engine )
2120 {
2221 this .engine = engine ;
2322 this .kyberK = engine .getKyberK ();
@@ -32,9 +31,9 @@ public KyberIndCpa(KyberEngine engine)
3231 KyberGenerateMatrixNBlocks =
3332 (
3433 (
35- 12 * KyberEngine .KyberN
34+ 12 * MLKEMEngine .KyberN
3635 / 8 * (1 << 12 )
37- / KyberEngine .KyberQ + symmetric .xofBlockBytes
36+ / MLKEMEngine .KyberQ + symmetric .xofBlockBytes
3837 )
3938 / symmetric .xofBlockBytes
4039 );
@@ -294,15 +293,15 @@ public byte[] packPublicKey(PolyVec publicKeyPolyVec, byte[] seed)
294293 {
295294 byte [] buf = new byte [indCpaPublicKeyBytes ];
296295 System .arraycopy (publicKeyPolyVec .toBytes (), 0 , buf , 0 , polyVecBytes );
297- System .arraycopy (seed , 0 , buf , polyVecBytes , KyberEngine .KyberSymBytes );
296+ System .arraycopy (seed , 0 , buf , polyVecBytes , MLKEMEngine .KyberSymBytes );
298297 return buf ;
299298 }
300299
301300 public byte [] unpackPublicKey (PolyVec publicKeyPolyVec , byte [] publicKey )
302301 {
303- byte [] outputSeed = new byte [KyberEngine .KyberSymBytes ];
302+ byte [] outputSeed = new byte [MLKEMEngine .KyberSymBytes ];
304303 publicKeyPolyVec .fromBytes (publicKey );
305- System .arraycopy (publicKey , polyVecBytes , outputSeed , 0 , KyberEngine .KyberSymBytes );
304+ System .arraycopy (publicKey , polyVecBytes , outputSeed , 0 , MLKEMEngine .KyberSymBytes );
306305 return outputSeed ;
307306 }
308307
@@ -338,9 +337,9 @@ public void generateMatrix(PolyVec[] aMatrix, byte[] seed, boolean transposed)
338337 symmetric .xofSqueezeBlocks (buf , 0 , symmetric .xofBlockBytes * KyberGenerateMatrixNBlocks );
339338
340339 int buflen = KyberGenerateMatrixNBlocks * symmetric .xofBlockBytes ;
341- ctr = rejectionSampling (aMatrix [i ].getVectorIndex (j ), 0 , KyberEngine .KyberN , buf , buflen );
340+ ctr = rejectionSampling (aMatrix [i ].getVectorIndex (j ), 0 , MLKEMEngine .KyberN , buf , buflen );
342341
343- while (ctr < KyberEngine .KyberN )
342+ while (ctr < MLKEMEngine .KyberN )
344343 {
345344 off = buflen % 3 ;
346345 for (k = 0 ; k < off ; k ++)
@@ -350,7 +349,7 @@ public void generateMatrix(PolyVec[] aMatrix, byte[] seed, boolean transposed)
350349 symmetric .xofSqueezeBlocks (buf , off , symmetric .xofBlockBytes * 2 );
351350 buflen = off + symmetric .xofBlockBytes ;
352351 // Error in code Section Unsure
353- ctr += rejectionSampling (aMatrix [i ].getVectorIndex (j ), ctr , KyberEngine .KyberN - ctr , buf , buflen );
352+ ctr += rejectionSampling (aMatrix [i ].getVectorIndex (j ), ctr , MLKEMEngine .KyberN - ctr , buf , buflen );
354353 }
355354 }
356355 }
@@ -367,12 +366,12 @@ private static int rejectionSampling(Poly outputBuffer, int coeffOff, int len, b
367366 val0 = (short )(((((short )(inpBuf [pos ] & 0xFF )) >> 0 ) | (((short )(inpBuf [pos + 1 ] & 0xFF )) << 8 )) & 0xFFF );
368367 val1 = (short )(((((short )(inpBuf [pos + 1 ] & 0xFF )) >> 4 ) | (((short )(inpBuf [pos + 2 ] & 0xFF )) << 4 )) & 0xFFF );
369368 pos = pos + 3 ;
370- if (val0 < (short )KyberEngine .KyberQ )
369+ if (val0 < (short )MLKEMEngine .KyberQ )
371370 {
372371 outputBuffer .setCoeffIndex (coeffOff + ctr , (short )val0 );
373372 ctr ++;
374373 }
375- if (ctr < len && val1 < (short )KyberEngine .KyberQ )
374+ if (ctr < len && val1 < (short )MLKEMEngine .KyberQ )
376375 {
377376 outputBuffer .setCoeffIndex (coeffOff + ctr , (short )val1 );
378377 ctr ++;
@@ -385,7 +384,7 @@ private static int rejectionSampling(Poly outputBuffer, int coeffOff, int len, b
385384 public byte [] decrypt (byte [] secretKey , byte [] cipherText )
386385 {
387386 int i ;
388- byte [] outputMessage = new byte [KyberEngine .getKyberIndCpaMsgBytes ()];
387+ byte [] outputMessage = new byte [MLKEMEngine .getKyberIndCpaMsgBytes ()];
389388
390389 PolyVec bp = new PolyVec (engine ), secretKeyPolyVec = new PolyVec (engine );
391390 Poly v = new Poly (engine ), mp = new Poly (engine );
0 commit comments