Skip to content

Commit d02fceb

Browse files
committed
Ascon: more thorough multi-output XOF tests
1 parent e2df273 commit d02fceb

File tree

1 file changed

+58
-4
lines changed

1 file changed

+58
-4
lines changed

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

Lines changed: 58 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,15 @@ public void performTest()
7070
testExceptionsEngine_ascon80pq();
7171

7272
testExceptionsXof_AsconXof128();
73-
testExceptionsXof_AsconCxof128();
73+
testExceptionsXof_AsconCXof128();
7474
testExceptionsXof_AsconXof();
7575
testExceptionsXof_AsconXofA();
7676

77+
testOutputXof_AsconXof128();
78+
testOutputXof_AsconCXof128();
79+
testOutputXof_AsconXof();
80+
testOutputXof_AsconXofA();
81+
7782
testParametersDigest_AsconHash256();
7883
testParametersDigest_AsconHash();
7984
testParametersDigest_AsconHashA();
@@ -84,7 +89,7 @@ public void performTest()
8489
testParametersEngine_ascon80pq();
8590

8691
testParametersXof_AsconXof128();
87-
testParametersXof_AsconCxof128();
92+
testParametersXof_AsconCXof128();
8893
testParametersXof_AsconXof();
8994
testParametersXof_AsconXofA();
9095

@@ -331,7 +336,7 @@ public ExtendedDigest createDigest()
331336
});
332337
}
333338

334-
public void testExceptionsXof_AsconCxof128()
339+
public void testExceptionsXof_AsconCXof128()
335340
throws Exception
336341
{
337342
implTestExceptionsXof(new CreateDigest()
@@ -344,6 +349,26 @@ public ExtendedDigest createDigest()
344349
});
345350
}
346351

352+
public void testOutputXof_AsconXof()
353+
{
354+
implTestOutputXof(new AsconXof(AsconXof.AsconParameters.AsconXof));
355+
}
356+
357+
public void testOutputXof_AsconXofA()
358+
{
359+
implTestOutputXof(new AsconXof(AsconXof.AsconParameters.AsconXofA));
360+
}
361+
362+
public void testOutputXof_AsconXof128()
363+
{
364+
implTestOutputXof(new AsconXof128());
365+
}
366+
367+
public void testOutputXof_AsconCXof128()
368+
{
369+
implTestOutputXof(new AsconCXof128());
370+
}
371+
347372
public void testParametersDigest_AsconHash()
348373
throws Exception
349374
{
@@ -460,7 +485,7 @@ public ExtendedDigest createDigest()
460485
}, 32);
461486
}
462487

463-
public void testParametersXof_AsconCxof128()
488+
public void testParametersXof_AsconCXof128()
464489
throws Exception
465490
{
466491
implTestParametersDigest(new CreateDigest()
@@ -1005,6 +1030,35 @@ private void implTestExceptionsXof(CreateDigest operator)
10051030
}
10061031
}
10071032

1033+
private void implTestOutputXof(Xof ascon)
1034+
{
1035+
Random random = new Random();
1036+
1037+
byte[] expected = new byte[64];
1038+
ascon.doFinal(expected, 0, expected.length);
1039+
1040+
byte[] output = new byte[64];
1041+
for (int i = 0; i < 64; ++i)
1042+
{
1043+
random.nextBytes(output);
1044+
1045+
int pos = 0;
1046+
while (pos <= output.length - 16)
1047+
{
1048+
int len = random.nextInt(17);
1049+
ascon.doOutput(output, pos, len);
1050+
pos += len;
1051+
}
1052+
1053+
ascon.doFinal(output, pos, output.length - pos);
1054+
1055+
if (!areEqual(expected, output))
1056+
{
1057+
fail("");
1058+
}
1059+
}
1060+
}
1061+
10081062
private void implTestParametersDigest(CreateDigest operator, int digestSize)
10091063
{
10101064
ExtendedDigest ascon = operator.createDigest();

0 commit comments

Comments
 (0)