summary refs log tree commit diff
path: root/crypto/src
diff options
context:
space:
mode:
authorPeter Dettman <peter.dettman@bouncycastle.org>2015-03-23 19:18:52 +0700
committerPeter Dettman <peter.dettman@bouncycastle.org>2015-03-23 19:18:52 +0700
commitddd9150a66af5f9a9f18c51fccfbb4e4b01c43fa (patch)
treee42717d0c49c294c1a40aca5188a9a239d4f6cdf /crypto/src
parentMath.Raw support for custom binary curves (diff)
downloadBouncyCastle.NET-ed25519-ddd9150a66af5f9a9f18c51fccfbb4e4b01c43fa.tar.xz
Fix case-handling for custom curve names
Diffstat (limited to 'crypto/src')
-rw-r--r--crypto/src/crypto/ec/CustomNamedCurves.cs42
1 files changed, 26 insertions, 16 deletions
diff --git a/crypto/src/crypto/ec/CustomNamedCurves.cs b/crypto/src/crypto/ec/CustomNamedCurves.cs
index 8ff1d24c7..a7eb6a704 100644
--- a/crypto/src/crypto/ec/CustomNamedCurves.cs
+++ b/crypto/src/crypto/ec/CustomNamedCurves.cs
@@ -272,43 +272,53 @@ namespace Org.BouncyCastle.Crypto.EC
             }
         }
 
+
         private static readonly IDictionary nameToCurve = Platform.CreateHashtable();
         private static readonly IDictionary nameToOid = Platform.CreateHashtable();
         private static readonly IDictionary oidToCurve = Platform.CreateHashtable();
         private static readonly IDictionary oidToName = Platform.CreateHashtable();
+        private static readonly IList names = Platform.CreateArrayList();
 
         private static void DefineCurve(string name, X9ECParametersHolder holder)
         {
+            names.Add(name);
+            name = Platform.ToLowerInvariant(name);
             nameToCurve.Add(name, holder);
         }
 
-        private static void DefineCurve(string name, DerObjectIdentifier oid, X9ECParametersHolder holder)
+        private static void DefineCurveWithOid(string name, DerObjectIdentifier oid, X9ECParametersHolder holder)
         {
-            nameToCurve.Add(name, holder);
-            nameToOid.Add(name, oid);
+            names.Add(name);
             oidToName.Add(oid, name);
             oidToCurve.Add(oid, holder);
+            name = Platform.ToLowerInvariant(name);
+            nameToOid.Add(name, oid);
+            nameToCurve.Add(name, holder);
         }
 
-        private static void DefineCurveAlias(string alias, DerObjectIdentifier oid)
+        private static void DefineCurveAlias(string name, DerObjectIdentifier oid)
         {
-            alias = Platform.ToLowerInvariant(alias);
-            nameToOid.Add(alias, oid);
-            nameToCurve.Add(alias, oidToCurve[oid]);
+            object curve = oidToCurve[oid];
+            if (curve == null)
+                throw new InvalidOperationException();
+
+            name = Platform.ToLowerInvariant(name);
+            nameToOid.Add(name, oid);
+            nameToCurve.Add(name, curve);
         }
 
         static CustomNamedCurves()
         {
             DefineCurve("curve25519", Curve25519Holder.Instance);
 
-            DefineCurve("secp192k1", SecObjectIdentifiers.SecP192k1, Secp192k1Holder.Instance);
-            DefineCurve("secp192r1", SecObjectIdentifiers.SecP192r1, Secp192r1Holder.Instance);
-            DefineCurve("secp224k1", SecObjectIdentifiers.SecP224k1, Secp224k1Holder.Instance);
-            DefineCurve("secp224r1", SecObjectIdentifiers.SecP224r1, Secp224r1Holder.Instance);
-            DefineCurve("secp256k1", SecObjectIdentifiers.SecP256k1, Secp256k1Holder.Instance);
-            DefineCurve("secp256r1", SecObjectIdentifiers.SecP256r1, Secp256r1Holder.Instance);
-            DefineCurve("secp384r1", SecObjectIdentifiers.SecP384r1, Secp384r1Holder.Instance);
-            DefineCurve("secp521r1", SecObjectIdentifiers.SecP521r1, Secp521r1Holder.Instance);
+            DefineCurveWithOid("secp192k1", SecObjectIdentifiers.SecP192k1, Secp192k1Holder.Instance);
+            DefineCurveWithOid("secp192r1", SecObjectIdentifiers.SecP192r1, Secp192r1Holder.Instance);
+            DefineCurveWithOid("secp224k1", SecObjectIdentifiers.SecP224k1, Secp224k1Holder.Instance);
+            DefineCurveWithOid("secp224r1", SecObjectIdentifiers.SecP224r1, Secp224r1Holder.Instance);
+            DefineCurveWithOid("secp256k1", SecObjectIdentifiers.SecP256k1, Secp256k1Holder.Instance);
+            DefineCurveWithOid("secp256r1", SecObjectIdentifiers.SecP256r1, Secp256r1Holder.Instance);
+            DefineCurveWithOid("secp384r1", SecObjectIdentifiers.SecP384r1, Secp384r1Holder.Instance);
+            DefineCurveWithOid("secp521r1", SecObjectIdentifiers.SecP521r1, Secp521r1Holder.Instance);
 
             DefineCurveAlias("P-192", SecObjectIdentifiers.SecP192r1);
             DefineCurveAlias("P-224", SecObjectIdentifiers.SecP224r1);
@@ -360,7 +370,7 @@ namespace Org.BouncyCastle.Crypto.EC
          */
         public static IEnumerable Names
         {
-            get { return new EnumerableProxy(nameToCurve.Keys); }
+            get { return new EnumerableProxy(names); }
         }
     }
 }