Skip to content

Commit b429e94

Browse files
committed
Added support for previous generation of Falcon OIDs for key parsing.
1 parent 685f920 commit b429e94

File tree

5 files changed

+21
-3
lines changed

5 files changed

+21
-3
lines changed

core/src/main/java/org/bouncycastle/asn1/bc/BCObjectIdentifiers.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,10 @@ public interface BCObjectIdentifiers
290290
* Falcon
291291
*/
292292
ASN1ObjectIdentifier falcon = bc_sig.branch("7");
293+
294+
ASN1ObjectIdentifier old_falcon_512 = new ASN1ObjectIdentifier("1.3.9999.3.6"); // falcon.branch("1");
295+
ASN1ObjectIdentifier old_falcon_1024 = new ASN1ObjectIdentifier("1.3.9999.3.9"); // falcon.branch("2");
296+
293297
/** 1.3.9999.3.11 OQS_OID_FALCON512 */
294298
ASN1ObjectIdentifier falcon_512 = new ASN1ObjectIdentifier("1.3.9999.3.11");
295299
/** 1.3.9999.3.12 OQS_OID_P256_FALCON512 */

core/src/main/java/org/bouncycastle/pqc/crypto/util/PrivateKeyFactory.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,13 @@ else if (algOID.equals(BCObjectIdentifiers.falcon_512) || algOID.equals(BCObject
387387

388388
return new FalconPrivateKeyParameters(falconParams, falconKey.getf(), falconKey.getG(), falconKey.getF(), falconKey.getPublicKey().getH());
389389
}
390+
else if (algOID.equals(BCObjectIdentifiers.old_falcon_512) || algOID.equals(BCObjectIdentifiers.old_falcon_1024))
391+
{
392+
FalconPrivateKey falconKey = FalconPrivateKey.getInstance(keyInfo.parsePrivateKey());
393+
FalconParameters falconParams = Utils.falconParamsLookup(algOID);
394+
395+
return new FalconPrivateKeyParameters(falconParams, falconKey.getf(), falconKey.getG(), falconKey.getF(), falconKey.getPublicKey().getH());
396+
}
390397
else if (algOID.on(BCObjectIdentifiers.pqc_kem_bike))
391398
{
392399
byte[] keyEnc = ASN1OctetString.getInstance(keyInfo.parsePrivateKey()).getOctets();

core/src/main/java/org/bouncycastle/pqc/crypto/util/PublicKeyFactory.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,8 @@ public class PublicKeyFactory
189189
converters.put(BCObjectIdentifiers.ntruhrss1373, new NtruConverter());
190190
converters.put(BCObjectIdentifiers.falcon_512, new FalconConverter());
191191
converters.put(BCObjectIdentifiers.falcon_1024, new FalconConverter());
192+
converters.put(BCObjectIdentifiers.old_falcon_512, new FalconConverter());
193+
converters.put(BCObjectIdentifiers.old_falcon_1024, new FalconConverter());
192194
converters.put(NISTObjectIdentifiers.id_alg_ml_kem_512, new MLKEMConverter());
193195
converters.put(NISTObjectIdentifiers.id_alg_ml_kem_768, new MLKEMConverter());
194196
converters.put(NISTObjectIdentifiers.id_alg_ml_kem_1024, new MLKEMConverter());

core/src/main/java/org/bouncycastle/pqc/crypto/util/Utils.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,8 @@ class Utils
241241

242242
falconParams.put(BCObjectIdentifiers.falcon_512, FalconParameters.falcon_512);
243243
falconParams.put(BCObjectIdentifiers.falcon_1024, FalconParameters.falcon_1024);
244+
falconParams.put(BCObjectIdentifiers.old_falcon_512, FalconParameters.falcon_512);
245+
falconParams.put(BCObjectIdentifiers.old_falcon_1024, FalconParameters.falcon_1024);
244246

245247
mlkemOids.put(MLKEMParameters.ml_kem_512, NISTObjectIdentifiers.id_alg_ml_kem_512);
246248
mlkemOids.put(MLKEMParameters.ml_kem_768, NISTObjectIdentifiers.id_alg_ml_kem_768);

prov/src/main/java/org/bouncycastle/jce/provider/BouncyCastleProvider.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -407,13 +407,16 @@ private void loadPQCKeys()
407407
addKeyInfoConverter(IsaraObjectIdentifiers.id_alg_xmssmt, new XMSSMTKeyFactorySpi());
408408
addKeyInfoConverter(PKCSObjectIdentifiers.id_alg_hss_lms_hashsig, new LMSKeyFactorySpi());
409409
addKeyInfoConverter(BCObjectIdentifiers.picnic_key, new PicnicKeyFactorySpi());
410-
addKeyInfoConverter(BCObjectIdentifiers.falcon_512, new FalconKeyFactorySpi());
411-
addKeyInfoConverter(BCObjectIdentifiers.falcon_1024, new FalconKeyFactorySpi());
412410

413411
addKeyInfoConverter(NISTObjectIdentifiers.id_alg_ml_kem_512, new MLKEMKeyFactorySpi());
414412
addKeyInfoConverter(NISTObjectIdentifiers.id_alg_ml_kem_768, new MLKEMKeyFactorySpi());
415413
addKeyInfoConverter(NISTObjectIdentifiers.id_alg_ml_kem_1024, new MLKEMKeyFactorySpi());
416414

415+
addKeyInfoConverter(BCObjectIdentifiers.old_falcon_512, new FalconKeyFactorySpi(BCObjectIdentifiers.old_falcon_512));
416+
addKeyInfoConverter(BCObjectIdentifiers.old_falcon_1024, new FalconKeyFactorySpi(BCObjectIdentifiers.old_falcon_1024));
417+
addKeyInfoConverter(BCObjectIdentifiers.falcon_512, new FalconKeyFactorySpi(BCObjectIdentifiers.falcon_512));
418+
addKeyInfoConverter(BCObjectIdentifiers.falcon_1024, new FalconKeyFactorySpi(BCObjectIdentifiers.falcon_1024));
419+
417420
addKeyInfoConverter(BCObjectIdentifiers.dilithium2, new DilithiumKeyFactorySpi());
418421
addKeyInfoConverter(BCObjectIdentifiers.dilithium3, new DilithiumKeyFactorySpi());
419422
addKeyInfoConverter(BCObjectIdentifiers.dilithium5, new DilithiumKeyFactorySpi());
@@ -591,7 +594,7 @@ public static PrivateKey getPrivateKey(PrivateKeyInfo privateKeyInfo)
591594
AsymmetricKeyInfoConverter converter = getAsymmetricKeyInfoConverter(privateKeyInfo.getPrivateKeyAlgorithm().getAlgorithm());
592595

593596
if (converter == null)
594-
{
597+
{ System.err.println("returning null: " + privateKeyInfo.getPrivateKeyAlgorithm().getAlgorithm());
595598
return null;
596599
}
597600

0 commit comments

Comments
 (0)