diff options
author | Peter Dettman <peter.dettman@bouncycastle.org> | 2022-02-03 15:19:53 +0700 |
---|---|---|
committer | Peter Dettman <peter.dettman@bouncycastle.org> | 2022-02-03 15:19:53 +0700 |
commit | b3a8c7160ce31e8b4ef03dc862f1dc7cfa0dd480 (patch) | |
tree | 241a1811db06dc3ceed1e61281f5e6ecb6388058 /crypto/src/openpgp/PgpPublicKey.cs | |
parent | Remove Obsolete methods (diff) | |
download | BouncyCastle.NET-ed25519-b3a8c7160ce31e8b4ef03dc862f1dc7cfa0dd480.tar.xz |
Improve curve registry laziness
Diffstat (limited to 'crypto/src/openpgp/PgpPublicKey.cs')
-rw-r--r-- | crypto/src/openpgp/PgpPublicKey.cs | 25 |
1 files changed, 22 insertions, 3 deletions
diff --git a/crypto/src/openpgp/PgpPublicKey.cs b/crypto/src/openpgp/PgpPublicKey.cs index 33fabc8aa..0fcffc35a 100644 --- a/crypto/src/openpgp/PgpPublicKey.cs +++ b/crypto/src/openpgp/PgpPublicKey.cs @@ -2,11 +2,11 @@ using System; using System.Collections; using System.IO; -using Org.BouncyCastle.Asn1.Sec; +using Org.BouncyCastle.Asn1; +using Org.BouncyCastle.Asn1.Gnu; using Org.BouncyCastle.Asn1.X9; using Org.BouncyCastle.Crypto; using Org.BouncyCastle.Crypto.Generators; -using Org.BouncyCastle.Crypto.IO; using Org.BouncyCastle.Crypto.Parameters; using Org.BouncyCastle.Math; using Org.BouncyCastle.Math.EC; @@ -126,7 +126,26 @@ namespace Org.BouncyCastle.Bcpg.OpenPgp } else if (key is ECPublicBcpgKey) { - this.keyStrength = ECKeyPairGenerator.FindECCurveByOid(((ECPublicBcpgKey)key).CurveOid).Curve.FieldSize; + DerObjectIdentifier curveOid = ((ECPublicBcpgKey)key).CurveOid; + if (GnuObjectIdentifiers.Ed25519.Equals(curveOid) + //|| CryptlibObjectIdentifiers.curvey25519.Equals(curveOid) + ) + { + this.keyStrength = 256; + } + else + { + X9ECParametersHolder ecParameters = ECKeyPairGenerator.FindECCurveByOidLazy(curveOid); + + if (ecParameters != null) + { + this.keyStrength = ecParameters.Curve.FieldSize; + } + else + { + this.keyStrength = -1; // unknown + } + } } } } |