88import org .bouncycastle .crypto .params .KeyParameter ;
99import org .bouncycastle .crypto .params .ParametersWithIV ;
1010import org .bouncycastle .util .Arrays ;
11+ import org .bouncycastle .util .Pack ;
1112
1213public 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