summary refs log tree commit diff
path: root/crypto/src/asn1/gm/GMNamedCurves.cs
diff options
context:
space:
mode:
Diffstat (limited to 'crypto/src/asn1/gm/GMNamedCurves.cs')
-rw-r--r--crypto/src/asn1/gm/GMNamedCurves.cs48
1 files changed, 35 insertions, 13 deletions
diff --git a/crypto/src/asn1/gm/GMNamedCurves.cs b/crypto/src/asn1/gm/GMNamedCurves.cs
index 866733cc6..9cb2cef14 100644
--- a/crypto/src/asn1/gm/GMNamedCurves.cs
+++ b/crypto/src/asn1/gm/GMNamedCurves.cs
@@ -44,19 +44,26 @@ namespace Org.BouncyCastle.Asn1.GM
 
             internal static readonly X9ECParametersHolder Instance = new SM2P256V1Holder();
 
-            protected override X9ECParameters CreateParameters()
+            protected override ECCurve CreateCurve()
             {
                 BigInteger p = FromHex("FFFFFFFEFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF00000000FFFFFFFFFFFFFFFF");
                 BigInteger a = FromHex("FFFFFFFEFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF00000000FFFFFFFFFFFFFFFC");
                 BigInteger b = FromHex("28E9FA9E9D9F5E344D5A9E4BCF6509A7F39789F515AB8F92DDBCBD414D940E93");
-                byte[] S = null;
                 BigInteger n = FromHex("FFFFFFFEFFFFFFFFFFFFFFFFFFFFFFFF7203DF6B21C6052B53BBF40939D54123");
                 BigInteger h = BigInteger.One;
 
-                ECCurve curve = ConfigureCurve(new FpCurve(p, a, b, n, h));
+                return ConfigureCurve(new FpCurve(p, a, b, n, h));
+            }
+
+            protected override X9ECParameters CreateParameters()
+            {
+                byte[] S = null;
+                ECCurve curve = Curve;
+
                 X9ECPoint G = ConfigureBasepoint(curve,
                     "0432C4AE2C1F1981195F9904466A39C9948FE30BBFF2660BE1715A4589334C74C7BC3736A2F4F6779C59BDCEE36B692153D0A9877CC62A474002DF32E52139F0A0");
-                return new X9ECParameters(curve, G, n, h, S);
+
+                return new X9ECParameters(curve, G, curve.Order, curve.Cofactor, S);
             }
         }
 
@@ -70,20 +77,26 @@ namespace Org.BouncyCastle.Asn1.GM
 
             internal static readonly X9ECParametersHolder Instance = new WapiP192V1Holder();
 
-            protected override X9ECParameters CreateParameters()
+            protected override ECCurve CreateCurve()
             {
                 BigInteger p = FromHex("BDB6F4FE3E8B1D9E0DA8C0D46F4C318CEFE4AFE3B6B8551F");
                 BigInteger a = FromHex("BB8E5E8FBC115E139FE6A814FE48AAA6F0ADA1AA5DF91985");
                 BigInteger b = FromHex("1854BEBDC31B21B7AEFC80AB0ECD10D5B1B3308E6DBF11C1");
-                byte[] S = null;
                 BigInteger n = FromHex("BDB6F4FE3E8B1D9E0DA8C0D40FC962195DFAE76F56564677");
                 BigInteger h = BigInteger.One;
 
-                ECCurve curve = ConfigureCurve(new FpCurve(p, a, b, n, h));
+                return ConfigureCurve(new FpCurve(p, a, b, n, h));
+            }
+
+            protected override X9ECParameters CreateParameters()
+            {
+                byte[] S = null;
+                ECCurve curve = Curve;
+
                 X9ECPoint G = ConfigureBasepoint(curve,
                     "044AD5F7048DE709AD51236DE65E4D4B482C836DC6E410664002BB3A02D4AAADACAE24817A4CA3A1B014B5270432DB27D2");
 
-                return new X9ECParameters(curve, G, n, h, S);
+                return new X9ECParameters(curve, G, curve.Order, curve.Cofactor, S);
             }
         }
 
@@ -108,26 +121,35 @@ namespace Org.BouncyCastle.Asn1.GM
             DefineCurve("sm2p256v1", GMObjectIdentifiers.sm2p256v1, SM2P256V1Holder.Instance);
         }
 
-        public static X9ECParameters GetByName(
-            string name)
+        public static X9ECParameters GetByName(string name)
         {
             DerObjectIdentifier oid = GetOid(name);
             return oid == null ? null : GetByOid(oid);
         }
 
+        public static X9ECParametersHolder GetByNameLazy(string name)
+        {
+            DerObjectIdentifier oid = GetOid(name);
+            return oid == null ? null : GetByOidLazy(oid);
+        }
+
         /**
          * return the X9ECParameters object for the named curve represented by
          * the passed in object identifier. Null if the curve isn't present.
          *
          * @param oid an object identifier representing a named curve, if present.
          */
-        public static X9ECParameters GetByOid(
-            DerObjectIdentifier oid)
+        public static X9ECParameters GetByOid(DerObjectIdentifier oid)
         {
-            X9ECParametersHolder holder = (X9ECParametersHolder)curves[oid];
+            X9ECParametersHolder holder = GetByOidLazy(oid);
             return holder == null ? null : holder.Parameters;
         }
 
+        public static X9ECParametersHolder GetByOidLazy(DerObjectIdentifier oid)
+        {
+            return (X9ECParametersHolder)curves[oid];
+        }
+
         /**
          * return the object identifier signified by the passed in name. Null
          * if there is no object identifier associated with name.