Skip to content

Commit

Permalink
Add new threadstorm test and update keyfactory test
Browse files Browse the repository at this point in the history
  • Loading branch information
sp717 committed Aug 6, 2024
1 parent a6577c9 commit 1b5738e
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,7 @@ public static void setupParameters() throws Exception {
}

for (String algorithm : ALGORITHMS) {
KeyPairGenerator kpg;
if (algorithm.equals("EdDSA")) {
kpg = KeyPairGenerator.getInstance("Ed25519");
} else {
kpg = KeyPairGenerator.getInstance(algorithm);
}
KeyPairGenerator kpg = KeyPairGenerator.getInstance(algorithm);
List<Arguments> keys = new ArrayList<>();
if (algorithm.equals("EC")) {
// Different curves can excercise different areas of ASN.1/DER and so should all be tested.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,14 @@
public class KeyReuseThreadStormTest {
private static final KeyPairGenerator RSA_KEY_GEN;
private static final KeyPairGenerator EC_KEY_GEN;
private static final KeyPairGenerator ED_KEY_GEN;
private static final KeyPair PAIR_RSA_1024_OR_DEFAULT;
private static final KeyPair PAIR_RSA_2048;
private static final KeyPair PAIR_RSA_4096;
private static final KeyPair PAIR_EC_P256;
private static final KeyPair PAIR_EC_P384;
private static final KeyPair PAIR_EC_P521;
private static final KeyPair PAIR_ED25519;

static {
try {
Expand All @@ -62,6 +64,8 @@ public class KeyReuseThreadStormTest {
PAIR_EC_P384 = EC_KEY_GEN.generateKeyPair();
EC_KEY_GEN.initialize(new ECGenParameterSpec("NIST P-521"));
PAIR_EC_P521 = EC_KEY_GEN.generateKeyPair();
ED_KEY_GEN = KeyPairGenerator.getInstance("Ed25519", NATIVE_PROVIDER);
PAIR_ED25519 = ED_KEY_GEN.generateKeyPair();
} catch (final GeneralSecurityException ex) {
throw new AssertionError(ex);
}
Expand Down Expand Up @@ -203,6 +207,30 @@ public void ecThreadStorm() throws Throwable {
executeThreads(threads);
}

@Test
public void edThreadStorm() throws Throwable {
final byte[] rngSeed = TestUtil.getRandomBytes(20);
System.out.println("RNG Seed: " + Arrays.toString(rngSeed));
final SecureRandom rng = SecureRandom.getInstance("SHA1PRNG");
rng.setSeed(rngSeed);
final int iterations = 500;
final int threadCount = 48;

final List<TestThread> threads = new ArrayList<>();
for (int x = 0; x < threadCount; x++) {
final List<KeyPair> keys = new ArrayList<KeyPair>();
while (keys.size() < 2) {
if (rng.nextBoolean()) {
keys.add(PAIR_ED25519);
}
}
final TestThread t;
t = new SignatureTestThread("EddsaThread-" + x, rng, iterations, "Ed25519", keys);
threads.add(t);
}
executeThreads(threads);
}

private abstract static class TestThread extends Thread {
public volatile Throwable result = null;
protected final SecureRandom rnd_;
Expand Down

0 comments on commit 1b5738e

Please sign in to comment.