summary refs log tree commit diff
path: root/crypto/src/security
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/security
parentRefactoring in Asn1 (diff)
downloadBouncyCastle.NET-ed25519-24214b3eed3cc1b85ea228e88c42a29f14955f3a.tar.xz
Refactoring around PrivateKeyInfo
Diffstat (limited to 'crypto/src/security')
-rw-r--r--crypto/src/security/PrivateKeyFactory.cs22
1 files changed, 16 insertions, 6 deletions
diff --git a/crypto/src/security/PrivateKeyFactory.cs b/crypto/src/security/PrivateKeyFactory.cs
index d6fa87943..205a604a8 100644
--- a/crypto/src/security/PrivateKeyFactory.cs
+++ b/crypto/src/security/PrivateKeyFactory.cs
@@ -148,10 +148,11 @@ namespace Org.BouncyCastle.Security
                         gostParams.DigestParamSet,
                         gostParams.EncryptionParamSet);
 
-                    Asn1OctetString privEnc = keyInfo.PrivateKeyData;
-                    if (privEnc.GetOctets().Length == 32 || privEnc.GetOctets().Length == 64)
+                    int privateKeyLength = keyInfo.PrivateKeyLength;
+
+                    if (privateKeyLength == 32 || privateKeyLength == 64)
                     {
-                        d = new BigInteger(1, privEnc.GetOctets(), bigEndian: false);
+                        d = new BigInteger(1, keyInfo.PrivateKey.GetOctets(), bigEndian: false);
                     }
                     else
                     {
@@ -241,10 +242,18 @@ namespace Org.BouncyCastle.Security
             else if (algOid.Equals(EdECObjectIdentifiers.id_X25519)
                 || algOid.Equals(CryptlibObjectIdentifiers.curvey25519))
             {
+                // Java 11 bug: exact length of X25519/X448 secret used in Java 11
+                if (X25519PrivateKeyParameters.KeySize == keyInfo.PrivateKeyLength)
+                    return new X25519PrivateKeyParameters(keyInfo.PrivateKey.GetOctets());
+
                 return new X25519PrivateKeyParameters(GetRawKey(keyInfo));
             }
             else if (algOid.Equals(EdECObjectIdentifiers.id_X448))
             {
+                // Java 11 bug: exact length of X25519/X448 secret used in Java 11
+                if (X448PrivateKeyParameters.KeySize == keyInfo.PrivateKeyLength)
+                    return new X448PrivateKeyParameters(keyInfo.PrivateKey.GetOctets());
+
                 return new X448PrivateKeyParameters(GetRawKey(keyInfo));
             }
             else if (algOid.Equals(EdECObjectIdentifiers.id_Ed25519)
@@ -277,10 +286,11 @@ namespace Org.BouncyCastle.Security
                             gostParams.DigestParamSet,
                             gostParams.EncryptionParamSet);
 
-                    Asn1OctetString privEnc = keyInfo.PrivateKeyData;
-                    if (privEnc.GetOctets().Length == 32 || privEnc.GetOctets().Length == 64)
+                    int privateKeyLength = keyInfo.PrivateKeyLength;
+
+                    if (privateKeyLength == 32 || privateKeyLength == 64)
                     {
-                        d = new BigInteger(1, privEnc.GetOctets(), bigEndian: false);
+                        d = new BigInteger(1, keyInfo.PrivateKey.GetOctets(), bigEndian: false);
                     }
                     else
                     {