Skip to content

Commit d15aeff

Browse files
committed
confirmed test coverage on parameter specs and associated names...
1 parent 29ced27 commit d15aeff

File tree

3 files changed

+133
-33
lines changed

3 files changed

+133
-33
lines changed

prov/src/test/java/org/bouncycastle/pqc/jcajce/provider/test/MLDSATest.java

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import org.bouncycastle.jcajce.interfaces.MLDSAPrivateKey;
2727
import org.bouncycastle.jcajce.spec.MLDSAParameterSpec;
2828
import org.bouncycastle.jce.provider.BouncyCastleProvider;
29+
import org.bouncycastle.pqc.crypto.mldsa.MLDSAParameters;
2930
import org.bouncycastle.pqc.jcajce.provider.BouncyCastlePQCProvider;
3031
import org.bouncycastle.util.Arrays;
3132
import org.bouncycastle.util.Strings;
@@ -39,6 +40,15 @@ public class MLDSATest
3940
{
4041
byte[] msg = Strings.toByteArray("Hello World!");
4142

43+
static private final String[] names = new String[]{
44+
"ML-DSA-44",
45+
"ML-DSA-65",
46+
"ML-DSA-87",
47+
"ML-DSA-44-WITH-SHA512",
48+
"ML-DSA-65-WITH-SHA512",
49+
"ML-DSA-87-WITH-SHA512"
50+
};
51+
4252
public void setUp()
4353
{
4454
if (Security.getProvider(BouncyCastlePQCProvider.PROVIDER_NAME) == null)
@@ -48,6 +58,30 @@ public void setUp()
4858
Security.addProvider(new BouncyCastleProvider());
4959
}
5060

61+
public void testParametersAndParamSpecs()
62+
throws Exception
63+
{
64+
MLDSAParameters mldsaParameters[] = new MLDSAParameters[]
65+
{
66+
MLDSAParameters.ml_dsa_44,
67+
MLDSAParameters.ml_dsa_65,
68+
MLDSAParameters.ml_dsa_87,
69+
MLDSAParameters.ml_dsa_44_with_sha512,
70+
MLDSAParameters.ml_dsa_65_with_sha512,
71+
MLDSAParameters.ml_dsa_87_with_sha512
72+
};
73+
74+
for (int i = 0; i != names.length; i++)
75+
{
76+
assertEquals(names[i], MLDSAParameterSpec.fromName(mldsaParameters[i].getName()).getName());
77+
}
78+
79+
for (int i = 0; i != names.length; i++)
80+
{
81+
assertEquals(names[i], MLDSAParameterSpec.fromName(names[i]).getName());
82+
}
83+
}
84+
5185
public void testKeyFactory()
5286
throws Exception
5387
{

prov/src/test/java/org/bouncycastle/pqc/jcajce/provider/test/MLKEMTest.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import org.bouncycastle.jcajce.spec.KTSParameterSpec;
2626
import org.bouncycastle.jcajce.spec.MLKEMParameterSpec;
2727
import org.bouncycastle.jce.provider.BouncyCastleProvider;
28+
import org.bouncycastle.pqc.crypto.mlkem.MLKEMParameters;
2829
import org.bouncycastle.pqc.jcajce.provider.BouncyCastlePQCProvider;
2930
import org.bouncycastle.util.Arrays;
3031
import org.bouncycastle.util.encoders.Hex;
@@ -35,6 +36,12 @@
3536
public class MLKEMTest
3637
extends TestCase
3738
{
39+
static private final String[] names = new String[]{
40+
"ML-KEM-512",
41+
"ML-KEM-768",
42+
"ML-KEM-1024"
43+
};
44+
3845
public void setUp()
3946
{
4047
if (Security.getProvider(BouncyCastlePQCProvider.PROVIDER_NAME) == null)
@@ -44,6 +51,27 @@ public void setUp()
4451
Security.addProvider(new BouncyCastleProvider());
4552
}
4653

54+
public void testParametersAndParamSpecs()
55+
throws Exception
56+
{
57+
MLKEMParameters mldsaParameters[] = new MLKEMParameters[]
58+
{
59+
MLKEMParameters.ml_kem_512,
60+
MLKEMParameters.ml_kem_768,
61+
MLKEMParameters.ml_kem_1024
62+
};
63+
64+
for (int i = 0; i != names.length; i++)
65+
{
66+
assertEquals(names[i], MLKEMParameterSpec.fromName(mldsaParameters[i].getName()).getName());
67+
}
68+
69+
for (int i = 0; i != names.length; i++)
70+
{
71+
assertEquals(names[i], MLKEMParameterSpec.fromName(names[i]).getName());
72+
}
73+
}
74+
4775
public void testKeyFactory()
4876
throws Exception
4977
{

prov/src/test/java/org/bouncycastle/pqc/jcajce/provider/test/SLHDSATest.java

Lines changed: 71 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import org.bouncycastle.jcajce.interfaces.SLHDSAPrivateKey;
2222
import org.bouncycastle.jcajce.spec.SLHDSAParameterSpec;
2323
import org.bouncycastle.jce.provider.BouncyCastleProvider;
24+
import org.bouncycastle.pqc.crypto.slhdsa.SLHDSAParameters;
2425
import org.bouncycastle.pqc.jcajce.provider.BouncyCastlePQCProvider;
2526
import org.bouncycastle.util.Arrays;
2627
import org.bouncycastle.util.Strings;
@@ -34,7 +35,34 @@ public class SLHDSATest
3435
extends TestCase
3536
{
3637
// test vector courtesy the "Yawning Angel" GO implementation and the SUPERCOP reference implementation.
37-
byte[] msg = Strings.toByteArray("Cthulhu Fthagn --What a wonderful phrase!Cthulhu Fthagn --Say it and you're crazed!");
38+
static private final byte[] msg = Strings.toByteArray("Cthulhu Fthagn --What a wonderful phrase!Cthulhu Fthagn --Say it and you're crazed!");
39+
40+
static private final String[] names = new String[] {
41+
"SLH-DSA-SHA2-128F",
42+
"SLH-DSA-SHA2-128S",
43+
"SLH-DSA-SHA2-192F",
44+
"SLH-DSA-SHA2-192S",
45+
"SLH-DSA-SHA2-256F",
46+
"SLH-DSA-SHA2-256S",
47+
"SLH-DSA-SHAKE-128F",
48+
"SLH-DSA-SHAKE-128S",
49+
"SLH-DSA-SHAKE-192F",
50+
"SLH-DSA-SHAKE-192S",
51+
"SLH-DSA-SHAKE-256F",
52+
"SLH-DSA-SHAKE-256S",
53+
"SLH-DSA-SHA2-128F-WITH-SHA256",
54+
"SLH-DSA-SHA2-128S-WITH-SHA256",
55+
"SLH-DSA-SHA2-192F-WITH-SHA512",
56+
"SLH-DSA-SHA2-192S-WITH-SHA512",
57+
"SLH-DSA-SHA2-256F-WITH-SHA512",
58+
"SLH-DSA-SHA2-256S-WITH-SHA512",
59+
"SLH-DSA-SHAKE-128F-WITH-SHAKE128",
60+
"SLH-DSA-SHAKE-128S-WITH-SHAKE128",
61+
"SLH-DSA-SHAKE-192F-WITH-SHAKE256",
62+
"SLH-DSA-SHAKE-192S-WITH-SHAKE256",
63+
"SLH-DSA-SHAKE-256F-WITH-SHAKE256",
64+
"SLH-DSA-SHAKE-256S-WITH-SHAKE256",
65+
};
3866

3967
public void setUp()
4068
{
@@ -45,45 +73,55 @@ public void setUp()
4573
Security.addProvider(new BouncyCastleProvider());
4674
}
4775

48-
public void testKeyFactory()
76+
public void testParametersAndParamSpecs()
4977
throws Exception
5078
{
51-
KeyPairGenerator kpGen44 = KeyPairGenerator.getInstance("ML-DSA-44");
52-
KeyPair kp44 = kpGen44.generateKeyPair();
53-
54-
KeyFactory kFact = KeyFactory.getInstance("HASH-SLH-DSA", "BC");
79+
for (int i = 0; i != names.length; i++)
80+
{
81+
assertEquals(names[i], SLHDSAParameterSpec.fromName(names[i]).getName());
82+
}
5583

56-
String[] names = new String[] {
57-
"SLH-DSA-SHA2-128F",
58-
"SLH-DSA-SHA2-128S",
59-
"SLH-DSA-SHA2-192F",
60-
"SLH-DSA-SHA2-192S",
61-
"SLH-DSA-SHA2-256F",
62-
"SLH-DSA-SHA2-256S",
63-
"SLH-DSA-SHAKE-128F",
64-
"SLH-DSA-SHAKE-128S",
65-
"SLH-DSA-SHAKE-192F",
66-
"SLH-DSA-SHAKE-192S",
67-
"SLH-DSA-SHAKE-256F",
68-
"SLH-DSA-SHAKE-256S",
69-
"SLH-DSA-SHA2-128F-WITH-SHA256",
70-
"SLH-DSA-SHA2-128S-WITH-SHA256",
71-
"SLH-DSA-SHA2-192F-WITH-SHA512",
72-
"SLH-DSA-SHA2-192S-WITH-SHA512",
73-
"SLH-DSA-SHA2-256F-WITH-SHA512",
74-
"SLH-DSA-SHA2-256S-WITH-SHA512",
75-
"SLH-DSA-SHAKE-128F-WITH-SHAKE128",
76-
"SLH-DSA-SHAKE-128S-WITH-SHAKE128",
77-
"SLH-DSA-SHAKE-192F-WITH-SHAKE256",
78-
"SLH-DSA-SHAKE-192S-WITH-SHAKE256",
79-
"SLH-DSA-SHAKE-256F-WITH-SHAKE256",
80-
"SLH-DSA-SHAKE-256S-WITH-SHAKE256",
81-
};
84+
SLHDSAParameters slhdsaParameters[] = new SLHDSAParameters[]
85+
{
86+
SLHDSAParameters.sha2_128f,
87+
SLHDSAParameters.sha2_128s,
88+
SLHDSAParameters.sha2_192f,
89+
SLHDSAParameters.sha2_192s,
90+
SLHDSAParameters.sha2_256f,
91+
SLHDSAParameters.sha2_256s,
92+
SLHDSAParameters.shake_128f,
93+
SLHDSAParameters.shake_128s,
94+
SLHDSAParameters.shake_192f,
95+
SLHDSAParameters.shake_192s,
96+
SLHDSAParameters.shake_256f,
97+
SLHDSAParameters.shake_256s,
98+
SLHDSAParameters.sha2_128f_with_sha256,
99+
SLHDSAParameters.sha2_128s_with_sha256,
100+
SLHDSAParameters.sha2_192f_with_sha512,
101+
SLHDSAParameters.sha2_192s_with_sha512,
102+
SLHDSAParameters.sha2_256f_with_sha512,
103+
SLHDSAParameters.sha2_256s_with_sha512,
104+
SLHDSAParameters.shake_128f_with_shake128,
105+
SLHDSAParameters.shake_128s_with_shake128,
106+
SLHDSAParameters.shake_192f_with_shake256,
107+
SLHDSAParameters.shake_192s_with_shake256,
108+
SLHDSAParameters.shake_256f_with_shake256,
109+
SLHDSAParameters.shake_256s_with_shake256
110+
};
82111

83112
for (int i = 0; i != names.length; i++)
84113
{
85-
assertEquals(names[i], SLHDSAParameterSpec.fromName(names[i]).getName());
114+
assertEquals(names[i], SLHDSAParameterSpec.fromName(slhdsaParameters[i].getName()).getName());
86115
}
116+
}
117+
118+
public void testKeyFactory()
119+
throws Exception
120+
{
121+
KeyPairGenerator kpGen44 = KeyPairGenerator.getInstance("ML-DSA-44");
122+
KeyPair kp44 = kpGen44.generateKeyPair();
123+
124+
KeyFactory kFact = KeyFactory.getInstance("HASH-SLH-DSA", "BC");
87125

88126
ASN1ObjectIdentifier[] oids = new ASN1ObjectIdentifier[] {
89127
NISTObjectIdentifiers.id_slh_dsa_sha2_128f,

0 commit comments

Comments
 (0)