11package org .bouncycastle .pqc .jcajce .provider .test ;
22
3+ import java .security .Key ;
34import java .security .KeyFactory ;
45import java .security .KeyPair ;
56import java .security .KeyPairGenerator ;
67import java .security .SecureRandom ;
78import java .security .Security ;
9+ import java .security .Signature ;
810import java .security .spec .PKCS8EncodedKeySpec ;
911import java .security .spec .X509EncodedKeySpec ;
1012
@@ -69,7 +71,7 @@ public void testKeySpecs()
6971 PKCS8EncodedKeySpec privSpec = kf .getKeySpec (kp .getPrivate (), PKCS8EncodedKeySpec .class );
7072
7173 assertTrue (Arrays .areEqual (kp .getPrivate ().getEncoded (), privSpec .getEncoded ()));
72-
74+
7375 X509EncodedKeySpec pubSpec = kf .getKeySpec (kp .getPublic (), X509EncodedKeySpec .class );
7476
7577 assertTrue (Arrays .areEqual (kp .getPublic ().getEncoded (), pubSpec .getEncoded ()));
@@ -110,7 +112,7 @@ public void testKeyPairEncoding()
110112 SLHDSAParameterSpec .slh_dsa_shake_256s_with_shake256 ,
111113 SLHDSAParameterSpec .slh_dsa_shake_256f_with_shake256 ,
112114 };
113-
115+
114116 // expected object identifiers
115117 ASN1ObjectIdentifier [] oids =
116118 {
@@ -139,9 +141,9 @@ public void testKeyPairEncoding()
139141 NISTObjectIdentifiers .id_hash_slh_dsa_shake_256s_with_shake256 ,
140142 NISTObjectIdentifiers .id_hash_slh_dsa_shake_256f_with_shake256
141143 };
142-
144+
143145 kpg = KeyPairGenerator .getInstance ("HASH-SLH-DSA" , "BC" );
144-
146+
145147 for (int i = 0 ; i != params .length ; i ++)
146148 {
147149 kpg .initialize (params [i ], new SecureRandom ());
@@ -151,4 +153,47 @@ public void testKeyPairEncoding()
151153 }
152154 }
153155
156+ public void testCrossNaming ()
157+ throws Exception
158+ {
159+ ASN1ObjectIdentifier [] nistOids = new ASN1ObjectIdentifier []
160+ {
161+ NISTObjectIdentifiers .id_slh_dsa_sha2_128s ,
162+ NISTObjectIdentifiers .id_slh_dsa_sha2_128f ,
163+ NISTObjectIdentifiers .id_slh_dsa_shake_128s ,
164+ NISTObjectIdentifiers .id_slh_dsa_shake_128f ,
165+ NISTObjectIdentifiers .id_slh_dsa_sha2_192s ,
166+ NISTObjectIdentifiers .id_slh_dsa_sha2_192f ,
167+ NISTObjectIdentifiers .id_slh_dsa_shake_192s ,
168+ NISTObjectIdentifiers .id_slh_dsa_shake_192f ,
169+ NISTObjectIdentifiers .id_slh_dsa_sha2_256s ,
170+ NISTObjectIdentifiers .id_slh_dsa_sha2_256f ,
171+ NISTObjectIdentifiers .id_slh_dsa_shake_256s ,
172+ NISTObjectIdentifiers .id_slh_dsa_shake_256f ,
173+ NISTObjectIdentifiers .id_hash_slh_dsa_sha2_128s_with_sha256 ,
174+ NISTObjectIdentifiers .id_hash_slh_dsa_sha2_128f_with_sha256 ,
175+ NISTObjectIdentifiers .id_hash_slh_dsa_shake_128s_with_shake128 ,
176+ NISTObjectIdentifiers .id_hash_slh_dsa_shake_128f_with_shake128 ,
177+ NISTObjectIdentifiers .id_hash_slh_dsa_sha2_192s_with_sha512 ,
178+ NISTObjectIdentifiers .id_hash_slh_dsa_sha2_192f_with_sha512 ,
179+ NISTObjectIdentifiers .id_hash_slh_dsa_shake_192s_with_shake256 ,
180+ NISTObjectIdentifiers .id_hash_slh_dsa_shake_192f_with_shake256 ,
181+ NISTObjectIdentifiers .id_hash_slh_dsa_sha2_256s_with_sha512 ,
182+ NISTObjectIdentifiers .id_hash_slh_dsa_sha2_256f_with_sha512 ,
183+ NISTObjectIdentifiers .id_hash_slh_dsa_shake_256s_with_shake256 ,
184+ NISTObjectIdentifiers .id_hash_slh_dsa_shake_256f_with_shake256
185+ };
186+
187+ for (int i = 0 ; i != nistOids .length ; i ++)
188+ {
189+ KeyPairGenerator ml_dsa_kp = KeyPairGenerator .getInstance (nistOids [i ].getId (), "BC" );
190+ Signature ml_dsa_sig = deriveSignatureFromKey (ml_dsa_kp .generateKeyPair ().getPrivate ());
191+ }
192+ }
193+
194+ private static Signature deriveSignatureFromKey (Key key )
195+ throws Exception
196+ {
197+ return Signature .getInstance (key .getAlgorithm (), "BC" );
198+ }
154199}
0 commit comments