File tree Expand file tree Collapse file tree 2 files changed +27
-1
lines changed
core/src/main/java/org/bouncycastle/pqc/crypto/lms
prov/src/test/java/org/bouncycastle/pqc/jcajce/provider/test Expand file tree Collapse file tree 2 files changed +27
-1
lines changed Original file line number Diff line number Diff line change @@ -121,7 +121,16 @@ else if (src instanceof byte[])
121121 try // 1.5 / 1.6 compatibility
122122 {
123123 in = new DataInputStream (new ByteArrayInputStream ((byte [])src ));
124- return getInstance (in );
124+ try
125+ {
126+ return getInstance (in );
127+ }
128+ catch (Exception e )
129+ {
130+ // old style single LMS key.
131+ LMSPrivateKeyParameters lmsKey = LMSPrivateKeyParameters .getInstance (src );
132+ return new HSSPrivateKeyParameters (lmsKey , lmsKey .getIndex (), lmsKey .getIndex () + lmsKey .getUsagesRemaining ());
133+ }
125134 }
126135 finally
127136 {
Original file line number Diff line number Diff line change @@ -34,6 +34,9 @@ public class LMSTest
3434 private static final byte [] nestedPublicKey = Base64 .decode ("MFAwDQYLKoZIhvcNAQkQAxEDPwAEPAAAAAEAAAAFAAAAAa3sRFhG3xQtT/xfuJJswgV80jvx/sFlYxteNrZ0hheITiUL/bJ8wJpphIpoSB/E9g==" );
3535 private static final byte [] nestedPrivateKey = Base64 .decode ("MIG6AgEBMA0GCyqGSIb3DQEJEAMRBGcEZQAAAAEAAAAAAAAAAQAAAAAAAAAAAAAAAAAAACAAAAAAAAAAAAUAAAABrexEWEbfFC1P/F+4kmzCBQAAAAAAAAAgAAAAIO01yI+Hj7eX+P2clcPDW0SzllJ4uzQt1JenbcllHpQngT0AAAAAAQAAAAUAAAABrexEWEbfFC1P/F+4kmzCBXzSO/H+wWVjG142tnSGF4hOJQv9snzAmmmEimhIH8T2" );
3636
37+ private static byte [] lmsPublicEnc = Base64 .decode ("MFAwDQYLKoZIhvcNAQkQAxEDPwAEPAAAAAEAAAAFAAAAAXjGRFXZMjGgOKA/sHWwYWNl6eTf5nI+RcEvlnIKQHQXpxNDreZCkeFm6x9CBN4YlA==" );
38+ private static byte [] lmsPrivateEnc = Base64 .decode ("MIGhAgEBMA0GCyqGSIb3DQEJEAMRBE4ETAAAAAEAAAAAAAAABQAAAAF4xkRV2TIxoDigP7B1sGFjAAAAAAAAACAAAAAghIRA7xa5TChn4+0KIh1LvGLp14alEkmcz3m3v7kTiBeBPQAAAAABAAAABQAAAAF4xkRV2TIxoDigP7B1sGFjZenk3+ZyPkXBL5ZyCkB0F6cTQ63mQpHhZusfQgTeGJQ=" );
39+
3740 public void setUp ()
3841 {
3942 if (Security .getProvider (BouncyCastleProvider .PROVIDER_NAME ) == null )
@@ -42,6 +45,20 @@ public void setUp()
4245 }
4346 }
4447
48+ public void testLmsOldKeyEncoding ()
49+ throws Exception
50+ {
51+ PKCS8EncodedKeySpec lmsPrivateKeySpec = new PKCS8EncodedKeySpec (lmsPrivateEnc );
52+ X509EncodedKeySpec lmsPublicKeySpec = new X509EncodedKeySpec (lmsPublicEnc );
53+
54+ KeyFactory kFact = KeyFactory .getInstance ("LMS" , "BC" );
55+
56+ PrivateKey lmsPrivateKey = kFact .generatePrivate (lmsPrivateKeySpec );
57+ PublicKey lmsPublicKey = kFact .generatePublic (lmsPublicKeySpec );
58+
59+ trySigning (new KeyPair (lmsPublicKey , lmsPrivateKey ));
60+ }
61+
4562 public void testKeyPairGenerators ()
4663 throws Exception
4764 {
You can’t perform that action at this time.
0 commit comments