diff options
author | David Hook <david.hook@keyfactor.com> | 2023-07-23 20:34:35 +1000 |
---|---|---|
committer | David Hook <david.hook@keyfactor.com> | 2023-07-23 20:34:35 +1000 |
commit | 46590f15c9646b26e6d5ad8c10a083d25106bb58 (patch) | |
tree | f023e6c1ede20f00da42a3e560697e7b5f7f0341 | |
parent | fixed encapsulation length (diff) | |
download | BouncyCastle.NET-ed25519-46590f15c9646b26e6d5ad8c10a083d25106bb58.tar.xz |
adjusted HQC and BIKE keys for latest BC Java changes
-rw-r--r-- | crypto/src/pqc/crypto/utils/PqcPublicKeyFactory.cs | 35 | ||||
-rw-r--r-- | crypto/src/pqc/crypto/utils/PqcSubjectPublicKeyInfoFactory.cs | 4 |
2 files changed, 31 insertions, 8 deletions
diff --git a/crypto/src/pqc/crypto/utils/PqcPublicKeyFactory.cs b/crypto/src/pqc/crypto/utils/PqcPublicKeyFactory.cs index 146827034..77af73b41 100644 --- a/crypto/src/pqc/crypto/utils/PqcPublicKeyFactory.cs +++ b/crypto/src/pqc/crypto/utils/PqcPublicKeyFactory.cs @@ -403,11 +403,22 @@ namespace Org.BouncyCastle.Pqc.Crypto.Utilities { internal override AsymmetricKeyParameter GetPublicKeyParameters(SubjectPublicKeyInfo keyInfo, object defaultParams) { - byte[] keyEnc = Asn1OctetString.GetInstance(keyInfo.ParsePublicKey()).GetOctets(); + try + { + byte[] keyEnc = Asn1OctetString.GetInstance(keyInfo.ParsePublicKey()).GetOctets(); - BikeParameters bikeParams = PqcUtilities.BikeParamsLookup(keyInfo.Algorithm.Algorithm); + BikeParameters bikeParams = PqcUtilities.BikeParamsLookup(keyInfo.Algorithm.Algorithm); - return new BikePublicKeyParameters(bikeParams, keyEnc); + return new BikePublicKeyParameters(bikeParams, keyEnc); + } + catch (Exception e) + { + byte[] keyEnc = keyInfo.PublicKeyData.GetOctets(); + + BikeParameters bikeParams = PqcUtilities.BikeParamsLookup(keyInfo.Algorithm.Algorithm); + + return new BikePublicKeyParameters(bikeParams, keyEnc); + } } } @@ -415,11 +426,23 @@ namespace Org.BouncyCastle.Pqc.Crypto.Utilities { internal override AsymmetricKeyParameter GetPublicKeyParameters(SubjectPublicKeyInfo keyInfo, object defaultParams) { - byte[] keyEnc = Asn1OctetString.GetInstance(keyInfo.ParsePublicKey()).GetOctets(); + try + { + byte[] keyEnc = Asn1OctetString.GetInstance(keyInfo.ParsePublicKey()).GetOctets(); + + HqcParameters hqcParams = PqcUtilities.HqcParamsLookup(keyInfo.Algorithm.Algorithm); + + return new HqcPublicKeyParameters(hqcParams, keyEnc); + } + catch (Exception e) + { + // raw encoding + byte[] keyEnc = keyInfo.PublicKeyData.GetOctets(); - HqcParameters hqcParams = PqcUtilities.HqcParamsLookup(keyInfo.Algorithm.Algorithm); + HqcParameters hqcParams = PqcUtilities.HqcParamsLookup(keyInfo.Algorithm.Algorithm); - return new HqcPublicKeyParameters(hqcParams, keyEnc); + return new HqcPublicKeyParameters(hqcParams, keyEnc); + } } } } diff --git a/crypto/src/pqc/crypto/utils/PqcSubjectPublicKeyInfoFactory.cs b/crypto/src/pqc/crypto/utils/PqcSubjectPublicKeyInfoFactory.cs index 946aca963..7b1142607 100644 --- a/crypto/src/pqc/crypto/utils/PqcSubjectPublicKeyInfoFactory.cs +++ b/crypto/src/pqc/crypto/utils/PqcSubjectPublicKeyInfoFactory.cs @@ -141,7 +141,7 @@ namespace Org.BouncyCastle.Pqc.Crypto.Utilities AlgorithmIdentifier algorithmIdentifier = new AlgorithmIdentifier( PqcUtilities.BikeOidLookup(bikePublicKeyParameters.Parameters)); - return new SubjectPublicKeyInfo(algorithmIdentifier, new DerOctetString(encoding)); + return new SubjectPublicKeyInfo(algorithmIdentifier, encoding); } if (publicKey is HqcPublicKeyParameters hqcPublicKeyParameters) { @@ -150,7 +150,7 @@ namespace Org.BouncyCastle.Pqc.Crypto.Utilities AlgorithmIdentifier algorithmIdentifier = new AlgorithmIdentifier( PqcUtilities.HqcOidLookup(hqcPublicKeyParameters.Parameters)); - return new SubjectPublicKeyInfo(algorithmIdentifier, new DerOctetString(encoding)); + return new SubjectPublicKeyInfo(algorithmIdentifier, encoding); } throw new ArgumentException("Class provided no convertible: " + Platform.GetTypeName(publicKey)); |