2121import org .bouncycastle .jcajce .interfaces .SLHDSAPrivateKey ;
2222import org .bouncycastle .jcajce .spec .SLHDSAParameterSpec ;
2323import org .bouncycastle .jce .provider .BouncyCastleProvider ;
24+ import org .bouncycastle .pqc .crypto .slhdsa .SLHDSAParameters ;
2425import org .bouncycastle .pqc .jcajce .provider .BouncyCastlePQCProvider ;
2526import org .bouncycastle .util .Arrays ;
2627import 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