From b3a8c7160ce31e8b4ef03dc862f1dc7cfa0dd480 Mon Sep 17 00:00:00 2001 From: Peter Dettman Date: Thu, 3 Feb 2022 15:19:53 +0700 Subject: Improve curve registry laziness --- crypto/src/openpgp/PgpPublicKey.cs | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) (limited to 'crypto/src/openpgp/PgpPublicKey.cs') 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 + } + } } } } -- cgit 1.4.1