Skip to content

Commit 0211400

Browse files
committed
Use test sampling with SNOVA
1 parent 2984a38 commit 0211400

File tree

3 files changed

+16
-13
lines changed

3 files changed

+16
-13
lines changed

core/src/test/java/org/bouncycastle/pqc/crypto/test/MayoTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,10 @@ public void testTestVectors()
4646
throws Exception
4747
{
4848
long start = System.currentTimeMillis();
49-
TestUtils.testTestVector(true, false, "pqc/crypto/mayo", files, new TestUtils.KeyGenerationOperation()
49+
TestUtils.testTestVector(false, true, false, "pqc/crypto/mayo", files, new TestUtils.KeyGenerationOperation()
5050
{
5151
@Override
52-
public SecureRandom getSecureRanom(byte[] seed)
52+
public SecureRandom getSecureRandom(byte[] seed)
5353
{
5454
return new NISTSecureRandom(seed, null);
5555
}

core/src/test/java/org/bouncycastle/pqc/crypto/test/SnovaTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,10 +126,10 @@ public void testTestVectors()
126126
throws Exception
127127
{
128128
long start = System.currentTimeMillis();
129-
TestUtils.testTestVector(true, false, "pqc/crypto/snova", files, new TestUtils.KeyGenerationOperation()
129+
TestUtils.testTestVector(true, true, false, "pqc/crypto/snova", files, new TestUtils.KeyGenerationOperation()
130130
{
131131
@Override
132-
public SecureRandom getSecureRanom(byte[] seed)
132+
public SecureRandom getSecureRandom(byte[] seed)
133133
{
134134
return new NISTSecureRandom(seed, null);
135135
}

core/src/test/java/org/bouncycastle/pqc/crypto/test/TestUtils.java

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ static boolean parseBoolean(String value)
3232

3333
public interface KeyGenerationOperation
3434
{
35-
SecureRandom getSecureRanom(byte[] seed);
35+
SecureRandom getSecureRandom(byte[] seed);
3636

3737
AsymmetricCipherKeyPairGenerator getAsymmetricCipherKeyPairGenerator(int fileIndex, SecureRandom random);
3838

@@ -45,17 +45,19 @@ public interface KeyGenerationOperation
4545
MessageSigner getMessageSigner();
4646
}
4747

48-
public static void testTestVector(boolean enableFactory, boolean isSigner, String homeDir, String[] files, KeyGenerationOperation operation)
48+
public static void testTestVector(boolean sampleOnly, boolean enableFactory, boolean isSigner, String homeDir, String[] files, KeyGenerationOperation operation)
4949
throws Exception
5050
{
5151
for (int fileIndex = 0; fileIndex != files.length; fileIndex++)
5252
{
5353
String name = files[fileIndex];
54+
5455
InputStream src = TestResourceFinder.findTestResource(homeDir, name);
5556
BufferedReader bin = new BufferedReader(new InputStreamReader(src));
56-
//System.out.println(files[fileIndex]);
57+
5758
String line;
5859
HashMap<String, String> buf = new HashMap<String, String>();
60+
TestSampler sampler = sampleOnly ? new TestSampler() : null;
5961
while ((line = bin.readLine()) != null)
6062
{
6163
line = line.trim();
@@ -68,18 +70,19 @@ public static void testTestVector(boolean enableFactory, boolean isSigner, Strin
6870
{
6971
if (buf.size() > 0)
7072
{
71-
int count = Integer.parseInt(buf.get("count"));
72-
// if (count == 99)
73-
// {
74-
// System.out.println("break");
75-
// }
73+
String count = (String)buf.get("count");
74+
if (sampler != null && sampler.skipTest(count))
75+
{
76+
continue;
77+
}
78+
7679
byte[] seed = Hex.decode((String)buf.get("seed"));
7780
byte[] pk = Hex.decode((String)buf.get("pk"));
7881
byte[] sk = Hex.decode((String)buf.get("sk"));
7982
byte[] message = Hex.decode((String)buf.get("msg"));
8083
byte[] signature = Hex.decode((String)buf.get("sm"));
8184

82-
SecureRandom random = operation.getSecureRanom(seed);
85+
SecureRandom random = operation.getSecureRandom(seed);
8386

8487
AsymmetricCipherKeyPairGenerator kpGen = operation.getAsymmetricCipherKeyPairGenerator(fileIndex, random);
8588

0 commit comments

Comments
 (0)