Skip to content

Commit 86e904a

Browse files
committed
Merge branch '2172-kangaroo'
2 parents c040eb3 + 73ded27 commit 86e904a

File tree

2 files changed

+27
-13
lines changed

2 files changed

+27
-13
lines changed

core/src/main/java/org/bouncycastle/crypto/digests/Kangaroo.java

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
package org.bouncycastle.crypto.digests;
22

3-
import org.bouncycastle.crypto.*;
3+
import org.bouncycastle.crypto.CipherParameters;
4+
import org.bouncycastle.crypto.CryptoServicePurpose;
5+
import org.bouncycastle.crypto.CryptoServicesRegistrar;
6+
import org.bouncycastle.crypto.ExtendedDigest;
7+
import org.bouncycastle.crypto.Xof;
48
import org.bouncycastle.util.Arrays;
59
import org.bouncycastle.util.Bytes;
610
import org.bouncycastle.util.Pack;
@@ -220,8 +224,6 @@ abstract static class KangarooBase
220224
*/
221225
private int theProcessed;
222226

223-
private final CryptoServicePurpose purpose;
224-
225227
/**
226228
* Constructor.
227229
*
@@ -241,7 +243,6 @@ abstract static class KangarooBase
241243

242244
/* Build personalisation */
243245
buildPersonal(null);
244-
this.purpose = purpose;
245246

246247
CryptoServicesRegistrar.checkConstraints(Utils.getDefaultProperties(this, pStrength, purpose));
247248

@@ -542,7 +543,7 @@ private static class KangarooSponge
542543
/**
543544
* The round constants.
544545
*/
545-
private static long[] KeccakRoundConstants = new long[]{0x0000000000000001L, 0x0000000000008082L,
546+
private static final long[] KeccakRoundConstants = new long[]{0x0000000000000001L, 0x0000000000008082L,
546547
0x800000000000808aL, 0x8000000080008000L, 0x000000000000808bL, 0x0000000080000001L, 0x8000000080008081L,
547548
0x8000000000008009L, 0x000000000000008aL, 0x0000000000000088L, 0x0000000080008009L, 0x000000008000000aL,
548549
0x000000008000808bL, 0x800000000000008bL, 0x8000000000008089L, 0x8000000000008003L, 0x8000000000008002L,
@@ -625,6 +626,12 @@ private void absorb(final byte[] data,
625626
int count = 0;
626627
while (count < len)
627628
{
629+
if (bytesInQueue == theRateBytes)
630+
{
631+
KangarooAbsorb(theQueue, 0);
632+
bytesInQueue = 0;
633+
}
634+
628635
if (bytesInQueue == 0 && count <= (len - theRateBytes))
629636
{
630637
do
@@ -642,12 +649,6 @@ private void absorb(final byte[] data,
642649

643650
bytesInQueue += partialBlock;
644651
count += partialBlock;
645-
646-
if (bytesInQueue == theRateBytes)
647-
{
648-
KangarooAbsorb(theQueue, 0);
649-
bytesInQueue = 0;
650-
}
651652
}
652653
}
653654
}

core/src/test/java/org/bouncycastle/crypto/test/KangarooTest.java

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88

99
/**
1010
* Test Cases for Kangaroo12. No TestVectors are available for MarsupilamiFourteen.
11-
* Test Vectors taken from https://tools.ietf.org/html/draft-viguier-kangarootwelve-04.
11+
* Test Vectors taken from https://tools.ietf.org/html/draft-viguier-kangarootwelve-04,
12+
* and generated using the reference implementation given in https://keccak.team/files/KangarooTwelve.pdf.
1213
*/
1314
public class KangarooTest
1415
extends SimpleTest
@@ -147,7 +148,13 @@ static class Kangaroo12Test
147148
"FAB658DB63E94A246188BF7AF69A133045F46EE984C56E3C3328CAAF1AA1A583",
148149
"D848C5068CED736F4462159B9867FD4C20B808ACC3D5BC48E0B06BA0A3762EC4",
149150
"C389E5009AE57120854C2E8C64670AC01358CF4C1BAF89447A724234DC7CED74",
150-
"75D2F86A2E644566726B4FBCFC5657B9DBCF070C7B0DCA06450AB291D7443BCF"
151+
"75D2F86A2E644566726B4FBCFC5657B9DBCF070C7B0DCA06450AB291D7443BCF",
152+
"61F2AD5657F4F2632A0822138EFE20C6A68A1885E1C0643EBF5587103219301D",
153+
"CBBE9DD1E423F20003FBA7BB219491C8D1F445FA5C4199D6C6C70C9FDC101964",
154+
"77DF46FD2D22BCE26E636E02CE10F9A42AE925E071F9056A9236328DB01BA411",
155+
"711835517A182DD4BC0E816BF5C72A278B227AE0B3D68F82577F97AD3CBFCA6A",
156+
"640728E5B4BE29F04A4FFFA645CB308102170F4D2B69D61F030CDC569BC74BAC",
157+
"5D7D68B49A5D999B8699FC4EDBEF0F0B4E4E7E904FE4B2B6B10C7C922407CF66"
151158
};
152159

153160
/**
@@ -170,6 +177,12 @@ void checkDigests(final KangarooTest pTest)
170177
pTest.testKangaroo(1, false, 41, EXPECTED[11]);
171178
pTest.testKangaroo(3, false, 41*41, EXPECTED[12]);
172179
pTest.testKangaroo(7, false, 41*41*41, EXPECTED[13]);
180+
pTest.testKangaroo(165, true, 0, EXPECTED[14]);
181+
pTest.testKangaroo(166, true, 0, EXPECTED[15]);
182+
pTest.testKangaroo(167, true, 0, EXPECTED[16]);
183+
pTest.testKangaroo(8192 + 165, false, 0, EXPECTED[17]);
184+
pTest.testKangaroo(8192 + 166, false, 0, EXPECTED[18]);
185+
pTest.testKangaroo(8192 + 167, false, 0, EXPECTED[19]);
173186
}
174187
}
175188

0 commit comments

Comments
 (0)