Skip to content

Commit d3ed581

Browse files
author
gefeili
committed
Refactor in snovaShake
1 parent 96a59e6 commit d3ed581

File tree

1 file changed

+4
-13
lines changed

1 file changed

+4
-13
lines changed

core/src/main/java/org/bouncycastle/pqc/crypto/snova/SnovaEngine.java

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import org.bouncycastle.crypto.params.KeyParameter;
99
import org.bouncycastle.crypto.params.ParametersWithIV;
1010
import org.bouncycastle.util.Arrays;
11+
import org.bouncycastle.util.Pack;
1112

1213
public class SnovaEngine
1314
{
@@ -589,14 +590,15 @@ public static void snovaShake(byte[] ptSeed, int outputBytes, byte[] out)
589590
long blockCounter = 0;
590591
int offset = 0;
591592
int remaining = outputBytes;
592-
593+
byte[] counterBytes = new byte[8];
593594
while (remaining > 0)
594595
{
595596
SHAKEDigest shake = new SHAKEDigest(128);
596597

597598
// Process seed + counter
598599
shake.update(ptSeed, 0, ptSeed.length);
599-
updateWithCounter(shake, blockCounter);
600+
Pack.longToLittleEndian(blockCounter, counterBytes, 0);
601+
shake.update(counterBytes, 0, 8);
600602

601603
// Calculate bytes to generate in this iteration
602604
int bytesToGenerate = Math.min(remaining, SHAKE128_RATE);
@@ -609,15 +611,4 @@ public static void snovaShake(byte[] ptSeed, int outputBytes, byte[] out)
609611
blockCounter++;
610612
}
611613
}
612-
613-
private static void updateWithCounter(SHAKEDigest shake, long counter)
614-
{
615-
byte[] counterBytes = new byte[8];
616-
// Little-endian conversion
617-
for (int i = 0; i < 8; i++)
618-
{
619-
counterBytes[i] = (byte)(counter >> (i * 8));
620-
}
621-
shake.update(counterBytes, 0, 8);
622-
}
623614
}

0 commit comments

Comments
 (0)