summary refs log tree commit diff
path: root/crypto/src/security
diff options
context:
space:
mode:
authorPeter Dettman <peter.dettman@bouncycastle.org>2015-11-13 22:15:48 +0700
committerPeter Dettman <peter.dettman@bouncycastle.org>2015-11-13 22:15:48 +0700
commit938f65781f98d1581caa75e0ba34dd42a475974d (patch)
treec1def51702619644820581c66abc2c4af06502bc /crypto/src/security
parentObsolete sequence constructor and refactor (diff)
downloadBouncyCastle.NET-ed25519-938f65781f98d1581caa75e0ba34dd42a475974d.tar.xz
Update ECPrivateKeyStructure following Java API
Diffstat (limited to 'crypto/src/security')
-rw-r--r--crypto/src/security/PrivateKeyFactory.cs15
1 files changed, 7 insertions, 8 deletions
diff --git a/crypto/src/security/PrivateKeyFactory.cs b/crypto/src/security/PrivateKeyFactory.cs
index b9538b33d..8c2ecfdb0 100644
--- a/crypto/src/security/PrivateKeyFactory.cs
+++ b/crypto/src/security/PrivateKeyFactory.cs
@@ -117,8 +117,7 @@ namespace Org.BouncyCastle.Security
                     x9 = new X9ECParameters((Asn1Sequence)para.Parameters);
                 }
 
-                ECPrivateKeyStructure ec = new ECPrivateKeyStructure(
-                    Asn1Sequence.GetInstance(keyInfo.ParsePrivateKey()));
+                ECPrivateKeyStructure ec = ECPrivateKeyStructure.GetInstance(keyInfo.ParsePrivateKey());
                 BigInteger d = ec.GetKey();
 
                 if (para.IsNamedCurve)
@@ -134,24 +133,24 @@ namespace Org.BouncyCastle.Security
                 Gost3410PublicKeyAlgParameters gostParams = new Gost3410PublicKeyAlgParameters(
                     Asn1Sequence.GetInstance(algID.Parameters.ToAsn1Object()));
 
+                ECDomainParameters ecP = ECGost3410NamedCurves.GetByOid(gostParams.PublicKeyParamSet);
+
+                if (ecP == null)
+                    throw new ArgumentException("Unrecognized curve OID for GostR3410x2001 private key");
+
                 Asn1Object privKey = keyInfo.ParsePrivateKey();
                 ECPrivateKeyStructure ec;
 
                 if (privKey is DerInteger)
                 {
                     // TODO Do we need to pass any parameters here?
-                    ec = new ECPrivateKeyStructure(((DerInteger)privKey).Value);
+                    ec = new ECPrivateKeyStructure(ecP.N.BitLength, ((DerInteger)privKey).Value);
                 }
                 else
                 {
                     ec = ECPrivateKeyStructure.GetInstance(privKey);
                 }
 
-                ECDomainParameters ecP = ECGost3410NamedCurves.GetByOid(gostParams.PublicKeyParamSet);
-
-                if (ecP == null)
-                    throw new ArgumentException("Unrecognized curve OID for GostR3410x2001 private key");
-
                 return new ECPrivateKeyParameters("ECGOST3410", ec.GetKey(), gostParams.PublicKeyParamSet);
             }
             else if (algOid.Equals(CryptoProObjectIdentifiers.GostR3410x94))