summary refs log tree commit diff
path: root/crypto/src/pqc
diff options
context:
space:
mode:
authorPeter Dettman <peter.dettman@bouncycastle.org>2023-07-18 11:16:50 +0700
committerPeter Dettman <peter.dettman@bouncycastle.org>2023-07-18 11:16:50 +0700
commit24214b3eed3cc1b85ea228e88c42a29f14955f3a (patch)
tree35827d78fdea04902451715032f33a466c2bf7ec /crypto/src/pqc
parentRefactoring in Asn1 (diff)
downloadBouncyCastle.NET-ed25519-24214b3eed3cc1b85ea228e88c42a29f14955f3a.tar.xz
Refactoring around PrivateKeyInfo
Diffstat (limited to 'crypto/src/pqc')
-rw-r--r--crypto/src/pqc/crypto/utils/PqcPrivateKeyFactory.cs29
1 files changed, 8 insertions, 21 deletions
diff --git a/crypto/src/pqc/crypto/utils/PqcPrivateKeyFactory.cs b/crypto/src/pqc/crypto/utils/PqcPrivateKeyFactory.cs
index d140bb4a2..c1e3feb1b 100644
--- a/crypto/src/pqc/crypto/utils/PqcPrivateKeyFactory.cs
+++ b/crypto/src/pqc/crypto/utils/PqcPrivateKeyFactory.cs
@@ -57,7 +57,7 @@ namespace Org.BouncyCastle.Pqc.Crypto.Utilities
             if (algOid.Equals(PkcsObjectIdentifiers.IdAlgHssLmsHashsig))
             {
                 byte[] keyEnc = Asn1OctetString.GetInstance(keyInfo.ParsePrivateKey()).GetOctets();
-                DerBitString pubKey = keyInfo.PublicKeyData;
+                DerBitString pubKey = keyInfo.PublicKey;
 
                 if (Pack.BE_To_UInt32(keyEnc, 0) == 1)
                 {
@@ -169,7 +169,7 @@ namespace Org.BouncyCastle.Pqc.Crypto.Utilities
 
                 byte[] t1 = null;
 
-                DerBitString publicKeyData = keyInfo.PublicKeyData;
+                DerBitString publicKeyData = keyInfo.PublicKey;
                 if (publicKeyData != null)
                 {
                     var pubParams = PqcPublicKeyFactory.DilithiumConverter.GetPublicKeyParameters(spParams,
@@ -192,29 +192,16 @@ namespace Org.BouncyCastle.Pqc.Crypto.Utilities
             {
                 Asn1Sequence keyEnc = Asn1Sequence.GetInstance(keyInfo.ParsePrivateKey());
                 FalconParameters spParams = PqcUtilities.FalconParamsLookup(algOid);
-                    
-                DerBitString publicKeyData = keyInfo.PublicKeyData;
+
                 int version = DerInteger.GetInstance(keyEnc[0]).IntValueExact;
                 if (version != 1)
                     throw new IOException("unknown private key version: " + version);
 
-                if (keyInfo.PublicKeyData != null)
-                {
-                    //ASN1Sequence pubKey = ASN1Sequence.getInstance(keyInfo.getPublicKeyData().getOctets());
-                    return new FalconPrivateKeyParameters(spParams,
-                        Asn1OctetString.GetInstance(keyEnc[1]).GetOctets(),
-                        Asn1OctetString.GetInstance(keyEnc[2]).GetOctets(),
-                        Asn1OctetString.GetInstance(keyEnc[3]).GetOctets(),
-                        publicKeyData.GetOctets()); // encT1
-                }
-                else
-                {
-                    return new FalconPrivateKeyParameters(spParams,
-                        Asn1OctetString.GetInstance(keyEnc[1]).GetOctets(),
-                        Asn1OctetString.GetInstance(keyEnc[2]).GetOctets(),
-                        Asn1OctetString.GetInstance(keyEnc[3]).GetOctets(),
-                        null);
-                }
+                return new FalconPrivateKeyParameters(spParams,
+                    Asn1OctetString.GetInstance(keyEnc[1]).GetOctets(),
+                    Asn1OctetString.GetInstance(keyEnc[2]).GetOctets(),
+                    Asn1OctetString.GetInstance(keyEnc[3]).GetOctets(),
+                    keyInfo.PublicKey?.GetOctets()); // encT1
             }
 
             throw new Exception("algorithm identifier in private key not recognised");