summary refs log tree commit diff
path: root/crypto/test
diff options
context:
space:
mode:
authorPeter Dettman <peter.dettman@bouncycastle.org>2018-07-10 23:21:16 +0700
committerPeter Dettman <peter.dettman@bouncycastle.org>2018-07-10 23:21:16 +0700
commitaca10f3c38a70188b4caa29b1ca32b2dd04e16bc (patch)
treeefb31e973b61e1c32e49f1b9d7a6bc7f4067dcf9 /crypto/test
parentMake members private (diff)
downloadBouncyCastle.NET-ed25519-aca10f3c38a70188b4caa29b1ca32b2dd04e16bc.tar.xz
EC-related updates from bc-java
Diffstat (limited to 'crypto/test')
-rw-r--r--crypto/test/src/crypto/test/ECGOST3410Test.cs10
-rw-r--r--crypto/test/src/crypto/test/ECIESTest.cs12
-rw-r--r--crypto/test/src/crypto/test/ECNRTest.cs2
-rw-r--r--crypto/test/src/crypto/test/ECTest.cs55
-rw-r--r--crypto/test/src/crypto/test/SM2EngineTest.cs7
-rw-r--r--crypto/test/src/crypto/test/SM2KeyExchangeTest.cs7
-rw-r--r--crypto/test/src/crypto/test/SM2SignerTest.cs6
-rw-r--r--crypto/test/src/math/ec/test/ECPointTest.cs18
-rw-r--r--crypto/test/src/security/test/TestEncodings.cs31
-rw-r--r--crypto/test/src/security/test/TestSignerUtil.cs16
-rw-r--r--crypto/test/src/test/CertTest.cs25
-rw-r--r--crypto/test/src/test/DHTest.cs33
-rw-r--r--crypto/test/src/test/DSATest.cs66
-rw-r--r--crypto/test/src/test/GOST3410Test.cs20
-rw-r--r--crypto/test/src/test/IESTest.cs11
-rw-r--r--crypto/test/src/test/MqvTest.cs21
-rw-r--r--crypto/test/src/test/PKCS10CertRequestTest.cs25
-rw-r--r--crypto/test/src/x509/test/TestCertificateGen.cs21
18 files changed, 163 insertions, 223 deletions
diff --git a/crypto/test/src/crypto/test/ECGOST3410Test.cs b/crypto/test/src/crypto/test/ECGOST3410Test.cs
index 37cb23ecf..4c938378a 100644
--- a/crypto/test/src/crypto/test/ECGOST3410Test.cs
+++ b/crypto/test/src/crypto/test/ECGOST3410Test.cs
@@ -56,7 +56,7 @@ namespace Org.BouncyCastle.Crypto.Tests
                 curve.CreatePoint(
                     new BigInteger("2"), // x
                     new BigInteger("4018974056539037503335449422937059775635739389905545080690979365213431566280")), // y
-                mod_q);
+                mod_q, BigInteger.One);
 
             ECPrivateKeyParameters priKey = new ECPrivateKeyParameters(
                 "ECGOST3410",
@@ -127,7 +127,7 @@ namespace Org.BouncyCastle.Crypto.Tests
                 curve.CreatePoint(
                     new BigInteger("2"), // x
                     new BigInteger("4018974056539037503335449422937059775635739389905545080690979365213431566280")), // y
-                mod_q);
+                mod_q, BigInteger.One);
 
             ECKeyPairGenerator          pGen = new ECKeyPairGenerator();
             ECKeyGenerationParameters   genParam = new ECKeyGenerationParameters(
@@ -184,7 +184,7 @@ namespace Org.BouncyCastle.Crypto.Tests
                 curve.CreatePoint(
                     new BigInteger("1"), // x
                     new BigInteger("64033881142927202683649881450433473985931760268884941288852745803908878638612")), // y
-                mod_q);
+                mod_q, BigInteger.One);
 
             ECKeyPairGenerator pGen = new ECKeyPairGenerator("ECGOST3410");
             ECKeyGenerationParameters genParam = new ECKeyGenerationParameters(
@@ -234,7 +234,7 @@ namespace Org.BouncyCastle.Crypto.Tests
                 curve.CreatePoint(
                     new BigInteger("1"), // x
                     new BigInteger("28792665814854611296992347458380284135028636778229113005756334730996303888124")), // y
-                mod_q);
+                mod_q, BigInteger.One);
 
             ECKeyPairGenerator pGen = new ECKeyPairGenerator("ECGOST3410");
             ECKeyGenerationParameters genParam = new ECKeyGenerationParameters(
@@ -284,7 +284,7 @@ namespace Org.BouncyCastle.Crypto.Tests
                 curve.CreatePoint(
                     new BigInteger("0"), // x
                     new BigInteger("29818893917731240733471273240314769927240550812383695689146495261604565990247")), // y
-                mod_q);
+                mod_q, BigInteger.One);
 
             ECKeyPairGenerator pGen = new ECKeyPairGenerator("ECGOST3410");
             ECKeyGenerationParameters genParam = new ECKeyGenerationParameters(
diff --git a/crypto/test/src/crypto/test/ECIESTest.cs b/crypto/test/src/crypto/test/ECIESTest.cs
index e8cfd6df4..1e2e8f711 100644
--- a/crypto/test/src/crypto/test/ECIESTest.cs
+++ b/crypto/test/src/crypto/test/ECIESTest.cs
@@ -46,9 +46,9 @@ namespace Org.BouncyCastle.Crypto.Tests
                 n, BigInteger.One);
 
             ECDomainParameters parameters = new ECDomainParameters(
-                    curve,
-                    curve.DecodePoint(Hex.Decode("03188da80eb03090f67cbf20eb43a18800f4ff0afd82ff1012")), // G
-                    n);
+                curve,
+                curve.DecodePoint(Hex.Decode("03188da80eb03090f67cbf20eb43a18800f4ff0afd82ff1012")), // G
+                n, BigInteger.One);
 
             ECPrivateKeyParameters priKey = new ECPrivateKeyParameters(
                 "ECDH",
@@ -220,9 +220,9 @@ namespace Org.BouncyCastle.Crypto.Tests
                 n, BigInteger.One);
 
             ECDomainParameters parameters = new ECDomainParameters(
-                    curve,
-                    curve.DecodePoint(Hex.Decode("03188da80eb03090f67cbf20eb43a18800f4ff0afd82ff1012")), // G
-                    n);
+                curve,
+                curve.DecodePoint(Hex.Decode("03188da80eb03090f67cbf20eb43a18800f4ff0afd82ff1012")), // G
+                n, BigInteger.One);
 
             ECKeyPairGenerator eGen = new ECKeyPairGenerator();
             KeyGenerationParameters gParam = new ECKeyGenerationParameters(parameters, new SecureRandom());
diff --git a/crypto/test/src/crypto/test/ECNRTest.cs b/crypto/test/src/crypto/test/ECNRTest.cs
index 5eae9f097..1ab67546c 100644
--- a/crypto/test/src/crypto/test/ECNRTest.cs
+++ b/crypto/test/src/crypto/test/ECNRTest.cs
@@ -49,7 +49,7 @@ namespace Org.BouncyCastle.Crypto.Tests
             ECDomainParameters parameters = new ECDomainParameters(
                 curve,
                 curve.DecodePoint(Hex.Decode("020ffa963cdca8816ccc33b8642bedf905c3d358573d3f27fbbd3b3cb9aaaf")), // G
-                n);
+                n, BigInteger.One);
 
             ECPrivateKeyParameters priKey = new ECPrivateKeyParameters(
                 new BigInteger("876300101507107567501066130761671078357010671067781776716671676178726717"), // d
diff --git a/crypto/test/src/crypto/test/ECTest.cs b/crypto/test/src/crypto/test/ECTest.cs
index 5697f41eb..7dc847ebe 100644
--- a/crypto/test/src/crypto/test/ECTest.cs
+++ b/crypto/test/src/crypto/test/ECTest.cs
@@ -5,6 +5,7 @@ using NUnit.Framework;
 using Org.BouncyCastle.Asn1.Nist;
 using Org.BouncyCastle.Asn1.Sec;
 using Org.BouncyCastle.Asn1.X9;
+using Org.BouncyCastle.Crypto.EC;
 using Org.BouncyCastle.Math;
 using Org.BouncyCastle.Math.EC;
 using Org.BouncyCastle.Security;
@@ -52,7 +53,7 @@ namespace Org.BouncyCastle.Crypto.Tests
             ECDomainParameters parameters = new ECDomainParameters(
                 curve,
                 curve.DecodePoint(Hex.Decode("03188da80eb03090f67cbf20eb43a18800f4ff0afd82ff1012")), // G
-                n);
+                n, BigInteger.One);
 
             ECPrivateKeyParameters priKey = new ECPrivateKeyParameters(
                 "ECDSA",
@@ -98,12 +99,8 @@ namespace Org.BouncyCastle.Crypto.Tests
         [Test]
         public void TestDecode()
         {
-            FpCurve curve = new FpCurve(
-                new BigInteger("6277101735386680763835789423207666416083908700390324961279"), // q
-                new BigInteger("fffffffffffffffffffffffffffffffefffffffffffffffc", 16), // a
-                new BigInteger("64210519e59c80e70fa7e9ab72243049feb8deecc146b9b1", 16)); // b
-
-            ECPoint p = curve.DecodePoint(Hex.Decode("03188da80eb03090f67cbf20eb43a18800f4ff0afd82ff1012")).Normalize();
+            X9ECParameters x9 = ECNamedCurveTable.GetByName("prime192v1");
+            ECPoint p = x9.G;
 
             if (!p.AffineXCoord.ToBigInteger().Equals(new BigInteger("188da80eb03090f67cbf20eb43a18800f4ff0afd82ff1012", 16)))
             {
@@ -115,7 +112,7 @@ namespace Org.BouncyCastle.Crypto.Tests
                 Fail("y uncompressed incorrectly");
             }
 
-            byte[] encoding = p.GetEncoded();
+            byte[] encoding = p.GetEncoded(true);
 
             if (!AreEqual(encoding, Hex.Decode("03188da80eb03090f67cbf20eb43a18800f4ff0afd82ff1012")))
             {
@@ -149,7 +146,7 @@ namespace Org.BouncyCastle.Crypto.Tests
             ECDomainParameters parameters = new ECDomainParameters(
                 curve,
                 curve.DecodePoint(Hex.Decode("020ffa963cdca8816ccc33b8642bedf905c3d358573d3f27fbbd3b3cb9aaaf")), // G
-                n);
+                n, BigInteger.One);
 
             ECPrivateKeyParameters priKey = new ECPrivateKeyParameters(
                 "ECDSA",
@@ -651,7 +648,7 @@ namespace Org.BouncyCastle.Crypto.Tests
             ECDomainParameters parameters = new ECDomainParameters(
                 curve,
                 curve.DecodePoint(Hex.Decode("020ffa963cdca8816ccc33b8642bedf905c3d358573d3f27fbbd3b3cb9aaaf")), // G
-                n);
+                n, BigInteger.One);
 
             ECKeyPairGenerator pGen = new ECKeyPairGenerator();
             ECKeyGenerationParameters genParam = new ECKeyGenerationParameters(
@@ -683,7 +680,7 @@ namespace Org.BouncyCastle.Crypto.Tests
          * Basic Key Agreement Test
          */
         [Test]
-        public void TestECBasicAgreementTest()
+        public void TestECDHBasicAgreement()
         {
             SecureRandom random = new SecureRandom();
 
@@ -698,7 +695,7 @@ namespace Org.BouncyCastle.Crypto.Tests
             ECDomainParameters parameters = new ECDomainParameters(
                 curve,
                 curve.DecodePoint(Hex.Decode("020ffa963cdca8816ccc33b8642bedf905c3d358573d3f27fbbd3b3cb9aaaf")), // G
-                n);
+                n, BigInteger.One);
 
             ECKeyPairGenerator pGen = new ECKeyPairGenerator();
             ECKeyGenerationParameters genParam = new ECKeyGenerationParameters(parameters, random);
@@ -744,6 +741,35 @@ namespace Org.BouncyCastle.Crypto.Tests
         }
 
         [Test]
+        public void TestECDHBasicAgreementCofactor()
+        {
+            SecureRandom random = new SecureRandom();
+
+            X9ECParameters x9 = CustomNamedCurves.GetByName("curve25519");
+            ECDomainParameters ec = new ECDomainParameters(x9.Curve, x9.G, x9.N, x9.H, x9.GetSeed());
+
+            ECKeyPairGenerator kpg = new ECKeyPairGenerator();
+            kpg.Init(new ECKeyGenerationParameters(ec, random));
+
+            AsymmetricCipherKeyPair p1 = kpg.GenerateKeyPair();
+            AsymmetricCipherKeyPair p2 = kpg.GenerateKeyPair();
+
+            IBasicAgreement e1 = new ECDHBasicAgreement();
+            IBasicAgreement e2 = new ECDHBasicAgreement();
+
+            e1.Init(p1.Private);
+            e2.Init(p2.Private);
+
+            BigInteger k1 = e1.CalculateAgreement(p2.Public);
+            BigInteger k2 = e2.CalculateAgreement(p1.Public);
+
+            if (!k1.Equals(k2))
+            {
+                Fail("calculated agreement test failed");
+            }
+        }
+
+        [Test]
         public void TestECMqvTestVector1()
         {
             // Test Vector from GEC-2
@@ -843,7 +869,7 @@ namespace Org.BouncyCastle.Crypto.Tests
             ECDomainParameters parameters = new ECDomainParameters(
                 curve,
                 curve.DecodePoint(Hex.Decode("020ffa963cdca8816ccc33b8642bedf905c3d358573d3f27fbbd3b3cb9aaaf")), // G
-                n);
+                n, BigInteger.One);
 
             ECKeyPairGenerator pGen = new ECKeyPairGenerator();
 
@@ -909,7 +935,8 @@ namespace Org.BouncyCastle.Crypto.Tests
             TestECDsa191bitBinary();
             TestECDsa239bitBinary();
             TestECDsaKeyGenTest();
-            TestECBasicAgreementTest();
+            TestECDHBasicAgreement();
+            TestECDHBasicAgreementCofactor();
 
             TestECDsaP224Sha224();
             TestECDsaP224OneByteOver();
diff --git a/crypto/test/src/crypto/test/SM2EngineTest.cs b/crypto/test/src/crypto/test/SM2EngineTest.cs
index 8a1987d52..1a2d1d13e 100644
--- a/crypto/test/src/crypto/test/SM2EngineTest.cs
+++ b/crypto/test/src/crypto/test/SM2EngineTest.cs
@@ -28,10 +28,11 @@ namespace Org.BouncyCastle.Crypto.Tests
             BigInteger SM2_ECC_A = new BigInteger("787968B4FA32C3FD2417842E73BBFEFF2F3C848B6831D7E0EC65228B3937E498", 16);
             BigInteger SM2_ECC_B = new BigInteger("63E4C6D3B23B0C849CF84241484BFE48F61D59A5B16BA06E6E12D1DA27C5249A", 16);
             BigInteger SM2_ECC_N = new BigInteger("8542D69E4C044F18E8B92435BF6FF7DD297720630485628D5AE74EE7C32E79B7", 16);
+            BigInteger SM2_ECC_H = BigInteger.One;
             BigInteger SM2_ECC_GX = new BigInteger("421DEBD61B62EAB6746434EBC3CC315E32220B3BADD50BDC4C4E6C147FEDD43D", 16);
             BigInteger SM2_ECC_GY = new BigInteger("0680512BCBB42C07D47349D2153B70C4E5D7FDFCBFA36EA1A85841B9E46E09A2", 16);
 
-            ECCurve curve = new FpCurve(SM2_ECC_P, SM2_ECC_A, SM2_ECC_B);
+            ECCurve curve = new FpCurve(SM2_ECC_P, SM2_ECC_A, SM2_ECC_B, SM2_ECC_N, SM2_ECC_H);
 
             ECPoint g = curve.CreatePoint(SM2_ECC_GX, SM2_ECC_GY);
             ECDomainParameters domainParams = new ECDomainParameters(curve, g, SM2_ECC_N);
@@ -104,11 +105,11 @@ namespace Org.BouncyCastle.Crypto.Tests
             BigInteger SM2_ECC_A = new BigInteger("00", 16);
             BigInteger SM2_ECC_B = new BigInteger("E78BCD09746C202378A7E72B12BCE00266B9627ECB0B5A25367AD1AD4CC6242B", 16);
             BigInteger SM2_ECC_N = new BigInteger("7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFBC972CF7E6B6F900945B3C6A0CF6161D", 16);
+            BigInteger SM2_ECC_H = BigInteger.ValueOf(4);
             BigInteger SM2_ECC_GX = new BigInteger("00CDB9CA7F1E6B0441F658343F4B10297C0EF9B6491082400A62E7A7485735FADD", 16);
             BigInteger SM2_ECC_GY = new BigInteger("013DE74DA65951C4D76DC89220D5F7777A611B1C38BAE260B175951DC8060C2B3E", 16);
-            BigInteger SM2_ECC_H = BigInteger.ValueOf(4);
 
-            ECCurve curve = new F2mCurve(257, 12, SM2_ECC_A, SM2_ECC_B);
+            ECCurve curve = new F2mCurve(257, 12, SM2_ECC_A, SM2_ECC_B, SM2_ECC_N, SM2_ECC_H);
 
             ECPoint g = curve.CreatePoint(SM2_ECC_GX, SM2_ECC_GY);
             ECDomainParameters domainParams = new ECDomainParameters(curve, g, SM2_ECC_N, SM2_ECC_H);
diff --git a/crypto/test/src/crypto/test/SM2KeyExchangeTest.cs b/crypto/test/src/crypto/test/SM2KeyExchangeTest.cs
index d7a2650eb..39131f163 100644
--- a/crypto/test/src/crypto/test/SM2KeyExchangeTest.cs
+++ b/crypto/test/src/crypto/test/SM2KeyExchangeTest.cs
@@ -30,10 +30,11 @@ namespace Org.BouncyCastle.Crypto.Tests
             BigInteger SM2_ECC_A = new BigInteger("787968B4FA32C3FD2417842E73BBFEFF2F3C848B6831D7E0EC65228B3937E498", 16);
             BigInteger SM2_ECC_B = new BigInteger("63E4C6D3B23B0C849CF84241484BFE48F61D59A5B16BA06E6E12D1DA27C5249A", 16);
             BigInteger SM2_ECC_N = new BigInteger("8542D69E4C044F18E8B92435BF6FF7DD297720630485628D5AE74EE7C32E79B7", 16);
+            BigInteger SM2_ECC_H = BigInteger.One;
             BigInteger SM2_ECC_GX = new BigInteger("421DEBD61B62EAB6746434EBC3CC315E32220B3BADD50BDC4C4E6C147FEDD43D", 16);
             BigInteger SM2_ECC_GY = new BigInteger("0680512BCBB42C07D47349D2153B70C4E5D7FDFCBFA36EA1A85841B9E46E09A2", 16);
 
-            ECCurve curve = new FpCurve(SM2_ECC_P, SM2_ECC_A, SM2_ECC_B);
+            ECCurve curve = new FpCurve(SM2_ECC_P, SM2_ECC_A, SM2_ECC_B, SM2_ECC_N, SM2_ECC_H);
 
             ECPoint g = curve.CreatePoint(SM2_ECC_GX, SM2_ECC_GY);
             ECDomainParameters domainParams = new ECDomainParameters(curve, g, SM2_ECC_N);
@@ -119,11 +120,11 @@ namespace Org.BouncyCastle.Crypto.Tests
             BigInteger SM2_ECC_A = new BigInteger("00", 16);
             BigInteger SM2_ECC_B = new BigInteger("E78BCD09746C202378A7E72B12BCE00266B9627ECB0B5A25367AD1AD4CC6242B", 16);
             BigInteger SM2_ECC_N = new BigInteger("7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFBC972CF7E6B6F900945B3C6A0CF6161D", 16);
+            BigInteger SM2_ECC_H = BigInteger.ValueOf(4);
             BigInteger SM2_ECC_GX = new BigInteger("00CDB9CA7F1E6B0441F658343F4B10297C0EF9B6491082400A62E7A7485735FADD", 16);
             BigInteger SM2_ECC_GY = new BigInteger("013DE74DA65951C4D76DC89220D5F7777A611B1C38BAE260B175951DC8060C2B3E", 16);
-            BigInteger SM2_ECC_H = BigInteger.ValueOf(4);
 
-            ECCurve curve = new F2mCurve(257, 12, SM2_ECC_A, SM2_ECC_B);
+            ECCurve curve = new F2mCurve(257, 12, SM2_ECC_A, SM2_ECC_B, SM2_ECC_N, SM2_ECC_H);
 
             ECPoint g = curve.CreatePoint(SM2_ECC_GX, SM2_ECC_GY);
             ECDomainParameters domainParams = new ECDomainParameters(curve, g, SM2_ECC_N, SM2_ECC_H);
diff --git a/crypto/test/src/crypto/test/SM2SignerTest.cs b/crypto/test/src/crypto/test/SM2SignerTest.cs
index 5904c95a7..e3c9c21ae 100644
--- a/crypto/test/src/crypto/test/SM2SignerTest.cs
+++ b/crypto/test/src/crypto/test/SM2SignerTest.cs
@@ -29,10 +29,11 @@ namespace Org.BouncyCastle.Crypto.Tests
             BigInteger SM2_ECC_A = new BigInteger("787968B4FA32C3FD2417842E73BBFEFF2F3C848B6831D7E0EC65228B3937E498", 16);
             BigInteger SM2_ECC_B = new BigInteger("63E4C6D3B23B0C849CF84241484BFE48F61D59A5B16BA06E6E12D1DA27C5249A", 16);
             BigInteger SM2_ECC_N = new BigInteger("8542D69E4C044F18E8B92435BF6FF7DD297720630485628D5AE74EE7C32E79B7", 16);
+            BigInteger SM2_ECC_H = BigInteger.ValueOf(4);
             BigInteger SM2_ECC_GX = new BigInteger("421DEBD61B62EAB6746434EBC3CC315E32220B3BADD50BDC4C4E6C147FEDD43D", 16);
             BigInteger SM2_ECC_GY = new BigInteger("0680512BCBB42C07D47349D2153B70C4E5D7FDFCBFA36EA1A85841B9E46E09A2", 16);
 
-            ECCurve curve = new FpCurve(SM2_ECC_P, SM2_ECC_A, SM2_ECC_B);
+            ECCurve curve = new FpCurve(SM2_ECC_P, SM2_ECC_A, SM2_ECC_B, SM2_ECC_N, SM2_ECC_H);
 
             ECPoint g = curve.CreatePoint(SM2_ECC_GX, SM2_ECC_GY);
             ECDomainParameters domainParams = new ECDomainParameters(curve, g, SM2_ECC_N);
@@ -76,10 +77,11 @@ namespace Org.BouncyCastle.Crypto.Tests
             BigInteger SM2_ECC_A = new BigInteger("00", 16);
             BigInteger SM2_ECC_B = new BigInteger("E78BCD09746C202378A7E72B12BCE00266B9627ECB0B5A25367AD1AD4CC6242B", 16);
             BigInteger SM2_ECC_N = new BigInteger("7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFBC972CF7E6B6F900945B3C6A0CF6161D", 16);
+            BigInteger SM2_ECC_H = BigInteger.ValueOf(4);
             BigInteger SM2_ECC_GX = new BigInteger("00CDB9CA7F1E6B0441F658343F4B10297C0EF9B6491082400A62E7A7485735FADD", 16);
             BigInteger SM2_ECC_GY = new BigInteger("013DE74DA65951C4D76DC89220D5F7777A611B1C38BAE260B175951DC8060C2B3E", 16);
 
-            ECCurve curve = new F2mCurve(257, 12, SM2_ECC_A, SM2_ECC_B);
+            ECCurve curve = new F2mCurve(257, 12, SM2_ECC_A, SM2_ECC_B, SM2_ECC_N, SM2_ECC_H);
 
             ECPoint g = curve.CreatePoint(SM2_ECC_GX, SM2_ECC_GY);
             ECDomainParameters domainParams = new ECDomainParameters(curve, g, SM2_ECC_N);
diff --git a/crypto/test/src/math/ec/test/ECPointTest.cs b/crypto/test/src/math/ec/test/ECPointTest.cs
index 089fb88b3..a5ca083e2 100644
--- a/crypto/test/src/math/ec/test/ECPointTest.cs
+++ b/crypto/test/src/math/ec/test/ECPointTest.cs
@@ -442,6 +442,22 @@ namespace Org.BouncyCastle.Math.EC.Tests
             }
         }
 
+        private void ImplValidityTest(ECCurve c, ECPoint g)
+        {
+            Assert.IsTrue(g.IsValid());
+
+            BigInteger h = c.Cofactor;
+            if (h != null && h.CompareTo(BigInteger.One) > 0)
+            {
+                if (ECAlgorithms.IsF2mCurve(c))
+                {
+                    ECPoint order2 = c.CreatePoint(BigInteger.Zero, c.B.Sqrt().ToBigInteger());
+                    ECPoint bad = g.Add(order2);
+                    Assert.IsFalse(bad.IsValid());
+                }
+            }
+        }
+
         private void ImplAddSubtractMultiplyTwiceEncodingTestAllCoords(X9ECParameters x9ECParameters)
         {
             BigInteger n = x9ECParameters.N;
@@ -470,6 +486,8 @@ namespace Org.BouncyCastle.Math.EC.Tests
                     ImplAddSubtractMultiplyTwiceEncodingTest(c, q, n);
 
                     ImplSqrtTest(c);
+
+                    ImplValidityTest(c, g);
                 }
             }
         }
diff --git a/crypto/test/src/security/test/TestEncodings.cs b/crypto/test/src/security/test/TestEncodings.cs
index 557d2dc51..a70d5b5b7 100644
--- a/crypto/test/src/security/test/TestEncodings.cs
+++ b/crypto/test/src/security/test/TestEncodings.cs
@@ -32,24 +32,19 @@ namespace Org.BouncyCastle.Security.Tests
 			BigInteger ECPubQY = new BigInteger(Base64.Decode("JrlJfxu3WGhqwtL/55BOs/wsUeiDFsvXcGhB8DGx"));
 			BigInteger ECPrivD = new BigInteger(Base64.Decode("GYQmd/NF1B+He1iMkWt3by2Az6Eu07t0ynJ4YCAo"));
 
-			FpCurve curve = new FpCurve(
-				new BigInteger("883423532389192164791648750360308885314476597252960362792450860609699839"), // q
-				new BigInteger("7fffffffffffffffffffffff7fffffffffff8000000000007ffffffffffc", 16), // a
-				new BigInteger("6b016c3bdcf18941d0d654921475ca71a9db2fb27d1d37796185c2942c0a", 16)); // b
-
-			ECDomainParameters ecDomain =
-				new ECDomainParameters(
-					curve,
-					new FpPoint(curve,
-						curve.FromBigInteger(ECParraGX),
-						curve.FromBigInteger(ECParraGY)),
-				ECParraN);
-
-			ECPublicKeyParameters ecPub = new ECPublicKeyParameters(
-				new FpPoint(
-					curve,
-					curve.FromBigInteger(ECPubQX),
-					curve.FromBigInteger(ECPubQY)),
+            FpCurve curve = new FpCurve(
+                new BigInteger("883423532389192164791648750360308885314476597252960362792450860609699839"), // q
+                new BigInteger("7fffffffffffffffffffffff7fffffffffff8000000000007ffffffffffc", 16), // a
+                new BigInteger("6b016c3bdcf18941d0d654921475ca71a9db2fb27d1d37796185c2942c0a", 16), // b
+                ECParraN, ECParraH);
+
+			ECDomainParameters ecDomain = new ECDomainParameters(
+				curve,
+                curve.ValidatePoint(ECParraGX, ECParraGY),
+                ECParraN, ECParraH);
+
+            ECPublicKeyParameters ecPub = new ECPublicKeyParameters(
+                curve.ValidatePoint(ECPubQX, ECPubQY),
 				ecDomain);
 
 			ECPrivateKeyParameters ecPriv = new ECPrivateKeyParameters(ECPrivD, ecDomain);
diff --git a/crypto/test/src/security/test/TestSignerUtil.cs b/crypto/test/src/security/test/TestSignerUtil.cs
index 18b856e3f..f2ee4b048 100644
--- a/crypto/test/src/security/test/TestSignerUtil.cs
+++ b/crypto/test/src/security/test/TestSignerUtil.cs
@@ -56,18 +56,16 @@ namespace Org.BouncyCastle.Security.Tests
             FpCurve curve = new FpCurve(
                 new BigInteger("883423532389192164791648750360308885314476597252960362792450860609699839"), // q
                 new BigInteger("7fffffffffffffffffffffff7fffffffffff8000000000007ffffffffffc", 16), // a
-                new BigInteger("6b016c3bdcf18941d0d654921475ca71a9db2fb27d1d37796185c2942c0a", 16)); // b
+                new BigInteger("6b016c3bdcf18941d0d654921475ca71a9db2fb27d1d37796185c2942c0a", 16), // b
+                ECParraN, ECParraH);
 
-            ECDomainParameters ecDomain = new ECDomainParameters(curve,
-                new FpPoint(curve,
-                    curve.FromBigInteger(ECParraGX),
-                    curve.FromBigInteger(ECParraGY)),
-                ECParraN);
+            ECDomainParameters ecDomain = new ECDomainParameters(
+                curve,
+                curve.ValidatePoint(ECParraGX, ECParraGY),
+                ECParraN, ECParraH);
 
             ECPublicKeyParameters ecPub = new ECPublicKeyParameters(
-                new FpPoint(curve,
-                    curve.FromBigInteger(ECPubQX),
-                    curve.FromBigInteger(ECPubQY)),
+                curve.ValidatePoint(ECPubQX, ECPubQY),
                 ecDomain);
 
             ECPrivateKeyParameters ecPriv = new ECPrivateKeyParameters(ECPrivD, ecDomain);
diff --git a/crypto/test/src/test/CertTest.cs b/crypto/test/src/test/CertTest.cs
index d9af06c82..46276a75b 100644
--- a/crypto/test/src/test/CertTest.cs
+++ b/crypto/test/src/test/CertTest.cs
@@ -1391,15 +1391,9 @@ namespace Org.BouncyCastle.Tests
          */
         internal void checkCreation3()
         {
-            ECCurve curve = new FpCurve(
-                new BigInteger("883423532389192164791648750360308885314476597252960362792450860609699839"), // q
-                new BigInteger("7fffffffffffffffffffffff7fffffffffff8000000000007ffffffffffc", 16), // a
-                new BigInteger("6b016c3bdcf18941d0d654921475ca71a9db2fb27d1d37796185c2942c0a", 16)); // b
-
-            ECDomainParameters spec = new ECDomainParameters(
-                curve,
-                curve.DecodePoint(Hex.Decode("020ffa963cdca8816ccc33b8642bedf905c3d358573d3f27fbbd3b3cb9aaaf")), // G
-                new BigInteger("883423532389192164791648750360308884807550341691627752275345424702807307")); // n
+            X9ECParameters x9 = ECNamedCurveTable.GetByName("prime239v1");
+            ECCurve curve = x9.Curve;
+            ECDomainParameters spec = new ECDomainParameters(curve, x9.G, x9.N, x9.H);
 
             ECPrivateKeyParameters privKey = new ECPrivateKeyParameters(
                 "ECDSA",
@@ -1533,16 +1527,9 @@ namespace Org.BouncyCastle.Tests
             string				algorithm,
             DerObjectIdentifier	algOid)
         {
-            FpCurve curve = new FpCurve(
-                new BigInteger("6864797660130609714981900799081393217269435300143305409394463459185543183397656052122559640661454554977296311391480858037121987999716643812574028291115057151"), // q (or p)
-                new BigInteger("01FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFC", 16),   // a
-                new BigInteger("0051953EB9618E1C9A1F929A21A0B68540EEA2DA725B99B315F3B8B489918EF109E156193951EC7E937B1652C0BD3BB1BF073573DF883D2C34F1EF451FD46B503F00", 16));  // b
-
-            ECDomainParameters spec = new ECDomainParameters(
-                curve,
-//				curve.DecodePoint(Hex.Decode("02C6858E06B70404E9CD9E3ECB662395B4429C648139053FB521F828AF606B4D3DBAA14B5E77EFE75928FE1DC127A2FFA8DE3348B3C1856A429BF97E7E31C2E5BD66")), // G
-                curve.DecodePoint(Hex.Decode("0200C6858E06B70404E9CD9E3ECB662395B4429C648139053FB521F828AF606B4D3DBAA14B5E77EFE75928FE1DC127A2FFA8DE3348B3C1856A429BF97E7E31C2E5BD66")), // G
-                new BigInteger("01FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFA51868783BF2F966B7FCC0148F709A5D03BB5C9B8899C47AEBB6FB71E91386409", 16)); // n
+            X9ECParameters x9 = ECNamedCurveTable.GetByName("secp521r1");
+            ECCurve curve = x9.Curve;
+            ECDomainParameters spec = new ECDomainParameters(curve, x9.G, x9.N, x9.H);
 
             ECPrivateKeyParameters privKey = new ECPrivateKeyParameters(
                 "ECDSA",
diff --git a/crypto/test/src/test/DHTest.cs b/crypto/test/src/test/DHTest.cs
index 1acc0d603..3ed79ca84 100644
--- a/crypto/test/src/test/DHTest.cs
+++ b/crypto/test/src/test/DHTest.cs
@@ -2,6 +2,7 @@ using System;
 
 using NUnit.Framework;
 
+using Org.BouncyCastle.Asn1.X9;
 using Org.BouncyCastle.Crypto;
 using Org.BouncyCastle.Crypto.Parameters;
 using Org.BouncyCastle.Math;
@@ -375,37 +376,22 @@ namespace Org.BouncyCastle.Tests
         [Test]
         public void TestECDH()
         {
-            doTestECDH("ECDH");
+            DoTestECDH("ECDH");
         }
 
         [Test]
         public void TestECDHC()
         {
-            doTestECDH("ECDHC");
+            DoTestECDH("ECDHC");
         }
 
-        private void doTestECDH(
-            string algorithm)
+        private void DoTestECDH(string algorithm)
         {
             IAsymmetricCipherKeyPairGenerator g = GeneratorUtilities.GetKeyPairGenerator(algorithm);
 
-//			EllipticCurve curve = new EllipticCurve(
-//				new ECFieldFp(new BigInteger("883423532389192164791648750360308885314476597252960362792450860609699839")), // q
-//				new BigInteger("7fffffffffffffffffffffff7fffffffffff8000000000007ffffffffffc", 16), // a
-//				new BigInteger("6b016c3bdcf18941d0d654921475ca71a9db2fb27d1d37796185c2942c0a", 16)); // b
-            ECCurve curve = new FpCurve(
-                new BigInteger("883423532389192164791648750360308885314476597252960362792450860609699839"), // q
-                new BigInteger("7fffffffffffffffffffffff7fffffffffff8000000000007ffffffffffc", 16), // a
-                new BigInteger("6b016c3bdcf18941d0d654921475ca71a9db2fb27d1d37796185c2942c0a", 16)); // b
-
-            ECDomainParameters ecSpec = new ECDomainParameters(
-                curve,
-//				ECPointUtil.DecodePoint(curve, Hex.Decode("020ffa963cdca8816ccc33b8642bedf905c3d358573d3f27fbbd3b3cb9aaaf")), // G
-                curve.DecodePoint(Hex.Decode("020ffa963cdca8816ccc33b8642bedf905c3d358573d3f27fbbd3b3cb9aaaf")), // G
-                new BigInteger("883423532389192164791648750360308884807550341691627752275345424702807307"), // n
-                BigInteger.One); //1); // h
-
-//			g.initialize(ecSpec, new SecureRandom());
+            X9ECParameters x9 = ECNamedCurveTable.GetByName("prime239v1");
+            ECDomainParameters ecSpec = new ECDomainParameters(x9.Curve, x9.G, x9.N, x9.H);
+
             g.Init(new ECKeyGenerationParameters(ecSpec, new SecureRandom()));
 
             //
@@ -429,11 +415,6 @@ namespace Org.BouncyCastle.Tests
             //
             // agreement
             //
-//			aKeyAgreeBasic.doPhase(bKeyPair.Public, true);
-//			bKeyAgreeBasic.doPhase(aKeyPair.Public, true);
-//
-//			BigInteger k1 = new BigInteger(aKeyAgreeBasic.generateSecret());
-//			BigInteger k2 = new BigInteger(bKeyAgreeBasic.generateSecret());
             BigInteger k1 = aKeyAgreeBasic.CalculateAgreement(bKeyPair.Public);
             BigInteger k2 = bKeyAgreeBasic.CalculateAgreement(aKeyPair.Public);
 
diff --git a/crypto/test/src/test/DSATest.cs b/crypto/test/src/test/DSATest.cs
index a8b8bec3b..9ed1109e2 100644
--- a/crypto/test/src/test/DSATest.cs
+++ b/crypto/test/src/test/DSATest.cs
@@ -252,15 +252,9 @@ namespace Org.BouncyCastle.Tests
 
             SecureRandom k = FixedSecureRandom.From(kData);
 
-            ECCurve curve = new FpCurve(
-                new BigInteger("883423532389192164791648750360308885314476597252960362792450860609699839"), // q
-                new BigInteger("7fffffffffffffffffffffff7fffffffffff8000000000007ffffffffffc", 16), // a
-                new BigInteger("6b016c3bdcf18941d0d654921475ca71a9db2fb27d1d37796185c2942c0a", 16)); // b
-
-            ECDomainParameters spec = new ECDomainParameters(
-                curve,
-                curve.DecodePoint(Hex.Decode("020ffa963cdca8816ccc33b8642bedf905c3d358573d3f27fbbd3b3cb9aaaf")), // G
-                new BigInteger("883423532389192164791648750360308884807550341691627752275345424702807307")); // n
+            X9ECParameters x9 = ECNamedCurveTable.GetByName("prime239v1");
+            ECCurve curve = x9.Curve;
+            ECDomainParameters spec = new ECDomainParameters(curve, x9.G, x9.N, x9.H);
 
             ECPrivateKeyParameters priKey = new ECPrivateKeyParameters(
                 "ECDSA",
@@ -330,17 +324,9 @@ namespace Org.BouncyCastle.Tests
 
             SecureRandom k = FixedSecureRandom.From(kData);
 
-            ECCurve curve = new F2mCurve(
-                239, // m
-                36, // k
-                new BigInteger("32010857077C5431123A46B808906756F543423E8D27877578125778AC76", 16), // a
-                new BigInteger("790408F2EEDAF392B012EDEFB3392F30F4327C0CA3F31FC383C422AA8C16", 16)); // b
-
-            ECDomainParameters parameters = new ECDomainParameters(
-                curve,
-                curve.DecodePoint(Hex.Decode("0457927098FA932E7C0A96D3FD5B706EF7E5F5C156E16B7E7C86038552E91D61D8EE5077C33FECF6F1A16B268DE469C3C7744EA9A971649FC7A9616305")), // G
-                new BigInteger("220855883097298041197912187592864814557886993776713230936715041207411783"), // n
-                BigInteger.ValueOf(4)); // h
+            X9ECParameters x9 = ECNamedCurveTable.GetByName("c2tnb239v1");
+            ECCurve curve = x9.Curve;
+            ECDomainParameters parameters = new ECDomainParameters(curve, x9.G, x9.N, x9.H);
 
             ECPrivateKeyParameters sKey = new ECPrivateKeyParameters(
                 "ECDSA",
@@ -435,17 +421,9 @@ namespace Org.BouncyCastle.Tests
 
             SecureRandom k = FixedSecureRandom.From(kData);
 
-            ECCurve curve = new F2mCurve(
-                239, // m
-                36, // k
-                new BigInteger("32010857077C5431123A46B808906756F543423E8D27877578125778AC76", 16), // a
-                new BigInteger("790408F2EEDAF392B012EDEFB3392F30F4327C0CA3F31FC383C422AA8C16", 16)); // b
-
-            ECDomainParameters parameters = new ECDomainParameters(
-                curve,
-                curve.DecodePoint(Hex.Decode("0457927098FA932E7C0A96D3FD5B706EF7E5F5C156E16B7E7C86038552E91D61D8EE5077C33FECF6F1A16B268DE469C3C7744EA9A971649FC7A9616305")), // G
-                new BigInteger("220855883097298041197912187592864814557886993776713230936715041207411783"), // n
-                BigInteger.ValueOf(4)); // h
+            X9ECParameters x9 = ECNamedCurveTable.GetByName("c2tnb239v1");
+            ECCurve curve = x9.Curve;
+            ECDomainParameters parameters = new ECDomainParameters(curve, x9.G, x9.N, x9.H);
 
             ECPrivateKeyParameters sKey = new ECPrivateKeyParameters(
                 new BigInteger("145642755521911534651321230007534120304391871461646461466464667494947990"), // d
@@ -554,15 +532,9 @@ namespace Org.BouncyCastle.Tests
             //
             s = SignerUtilities.GetSigner("ECDSA");
 
-            ECCurve curve = new FpCurve(
-                new BigInteger("883423532389192164791648750360308885314476597252960362792450860609699839"), // q
-                new BigInteger("7fffffffffffffffffffffff7fffffffffff8000000000007ffffffffffc", 16), // a
-                new BigInteger("6b016c3bdcf18941d0d654921475ca71a9db2fb27d1d37796185c2942c0a", 16)); // b
-
-            ECDomainParameters ecSpec = new ECDomainParameters(
-                curve,
-                curve.DecodePoint(Hex.Decode("020ffa963cdca8816ccc33b8642bedf905c3d358573d3f27fbbd3b3cb9aaaf")), // G
-                new BigInteger("883423532389192164791648750360308884807550341691627752275345424702807307")); // n
+            X9ECParameters x9 = ECNamedCurveTable.GetByName("prime239v1");
+            ECCurve curve = x9.Curve;
+            ECDomainParameters ecSpec = new ECDomainParameters(curve, x9.G, x9.N, x9.H);
 
             g = GeneratorUtilities.GetKeyPairGenerator("ECDSA");
             g.Init(new ECKeyGenerationParameters(ecSpec, rand));
@@ -594,17 +566,9 @@ namespace Org.BouncyCastle.Tests
             //
             s = SignerUtilities.GetSigner("ECDSA");
 
-            curve = new F2mCurve(
-                    239, // m
-                    36, // k
-                    new BigInteger("32010857077C5431123A46B808906756F543423E8D27877578125778AC76", 16), // a
-                    new BigInteger("790408F2EEDAF392B012EDEFB3392F30F4327C0CA3F31FC383C422AA8C16", 16)); // b
-
-            ecSpec = new ECDomainParameters(
-                curve,
-                curve.DecodePoint(Hex.Decode("0457927098FA932E7C0A96D3FD5B706EF7E5F5C156E16B7E7C86038552E91D61D8EE5077C33FECF6F1A16B268DE469C3C7744EA9A971649FC7A9616305")), // G
-                new BigInteger("220855883097298041197912187592864814557886993776713230936715041207411783"), // n
-                BigInteger.ValueOf(4)); // h
+            x9 = ECNamedCurveTable.GetByName("c2tnb239v1");
+            curve = x9.Curve;
+            ecSpec = new ECDomainParameters(curve, x9.G, x9.N, x9.H);
 
             g = GeneratorUtilities.GetKeyPairGenerator("ECDSA");
             g.Init(new ECKeyGenerationParameters(ecSpec, rand));
diff --git a/crypto/test/src/test/GOST3410Test.cs b/crypto/test/src/test/GOST3410Test.cs
index db232c5a1..03dcf3144 100644
--- a/crypto/test/src/test/GOST3410Test.cs
+++ b/crypto/test/src/test/GOST3410Test.cs
@@ -29,19 +29,21 @@ namespace Org.BouncyCastle.Tests
 
             SecureRandom k = FixedSecureRandom.From(kData);
 
-            BigInteger mod_p = new BigInteger("57896044618658097711785492504343953926634992332820282019728792003956564821041"); //p
+            BigInteger mod_p = new BigInteger("57896044618658097711785492504343953926634992332820282019728792003956564821041");
+            BigInteger mod_q = new BigInteger("57896044618658097711785492504343953927082934583725450622380973592137631069619");
 
             ECCurve curve = new FpCurve(
-                mod_p, // p
+                mod_p,
                 new BigInteger("7"), // a
-                new BigInteger("43308876546767276905765904595650931995942111794451039583252968842033849580414")); // b
+                new BigInteger("43308876546767276905765904595650931995942111794451039583252968842033849580414"), // b
+                mod_q, BigInteger.One);
 
             ECDomainParameters spec = new ECDomainParameters(
                 curve,
                 curve.CreatePoint(
                     new BigInteger("2"),
                     new BigInteger("4018974056539037503335449422937059775635739389905545080690979365213431566280")),
-                new BigInteger("57896044618658097711785492504343953927082934583725450622380973592137631069619")); // q
+                mod_q, BigInteger.One);
 
             ECPrivateKeyParameters sKey = new ECPrivateKeyParameters(
                 "ECGOST3410",
@@ -193,19 +195,21 @@ namespace Org.BouncyCastle.Tests
             s = SignerUtilities.GetSigner("ECGOST3410");
             g = GeneratorUtilities.GetKeyPairGenerator("ECGOST3410");
 
-            BigInteger mod_p = new BigInteger("57896044618658097711785492504343953926634992332820282019728792003956564821041"); //p
+            BigInteger mod_p = new BigInteger("57896044618658097711785492504343953926634992332820282019728792003956564821041");
+            BigInteger mod_q = new BigInteger("57896044618658097711785492504343953927082934583725450622380973592137631069619");
 
             ECCurve curve = new FpCurve(
-                mod_p, // p
+                mod_p,
                 new BigInteger("7"), // a
-                new BigInteger("43308876546767276905765904595650931995942111794451039583252968842033849580414")); // b
+                new BigInteger("43308876546767276905765904595650931995942111794451039583252968842033849580414"), // b
+                mod_q, BigInteger.One);
 
             ECDomainParameters ecSpec = new ECDomainParameters(
                 curve,
                 curve.CreatePoint(
                     new BigInteger("2"),
                     new BigInteger("4018974056539037503335449422937059775635739389905545080690979365213431566280")),
-                new BigInteger("57896044618658097711785492504343953927082934583725450622380973592137631069619")); // q
+                mod_q, BigInteger.One);
 
             g.Init(new ECKeyGenerationParameters(ecSpec, new SecureRandom()));
 
diff --git a/crypto/test/src/test/IESTest.cs b/crypto/test/src/test/IESTest.cs
index 193fe1ae9..99aacc66d 100644
--- a/crypto/test/src/test/IESTest.cs
+++ b/crypto/test/src/test/IESTest.cs
@@ -32,15 +32,8 @@ namespace Org.BouncyCastle.Tests
 		{
 			IAsymmetricCipherKeyPairGenerator g = GeneratorUtilities.GetKeyPairGenerator("ECIES");
 
-			ECCurve curve = new FpCurve(
-				new BigInteger("883423532389192164791648750360308885314476597252960362792450860609699839"), // q
-				new BigInteger("7fffffffffffffffffffffff7fffffffffff8000000000007ffffffffffc", 16), // a
-				new BigInteger("6b016c3bdcf18941d0d654921475ca71a9db2fb27d1d37796185c2942c0a", 16)); // b
-
-			ECDomainParameters ecSpec = new ECDomainParameters(
-				curve,
-				curve.DecodePoint(Hex.Decode("020ffa963cdca8816ccc33b8642bedf905c3d358573d3f27fbbd3b3cb9aaaf")), // G
-				new BigInteger("883423532389192164791648750360308884807550341691627752275345424702807307")); // n
+            X9ECParameters x9 = ECNamedCurveTable.GetByName("prime239v1");
+            ECDomainParameters ecSpec = new ECDomainParameters(x9.Curve, x9.G, x9.N, x9.H);
 
 			g.Init(
 				new ECKeyGenerationParameters(
diff --git a/crypto/test/src/test/MqvTest.cs b/crypto/test/src/test/MqvTest.cs
index ef36e1a23..b26d5619b 100644
--- a/crypto/test/src/test/MqvTest.cs
+++ b/crypto/test/src/test/MqvTest.cs
@@ -2,6 +2,7 @@ using System;
 
 using NUnit.Framework;
 
+using Org.BouncyCastle.Asn1.X9;
 using Org.BouncyCastle.Crypto;
 using Org.BouncyCastle.Crypto.Parameters;
 using Org.BouncyCastle.Math;
@@ -31,24 +32,10 @@ namespace Org.BouncyCastle.Tests
 		{
 			IAsymmetricCipherKeyPairGenerator g = GeneratorUtilities.GetKeyPairGenerator("ECMQV");
 
-//			EllipticCurve curve = new EllipticCurve(
-//				new ECFieldFp(new BigInteger("883423532389192164791648750360308885314476597252960362792450860609699839")), // q
-//				new BigInteger("7fffffffffffffffffffffff7fffffffffff8000000000007ffffffffffc", 16), // a
-//				new BigInteger("6b016c3bdcf18941d0d654921475ca71a9db2fb27d1d37796185c2942c0a", 16)); // b
-			ECCurve curve = new FpCurve(
-				new BigInteger("883423532389192164791648750360308885314476597252960362792450860609699839"), // q
-				new BigInteger("7fffffffffffffffffffffff7fffffffffff8000000000007ffffffffffc", 16), // a
-				new BigInteger("6b016c3bdcf18941d0d654921475ca71a9db2fb27d1d37796185c2942c0a", 16)); // b
+            X9ECParameters x9 = ECNamedCurveTable.GetByName("prime239v1");
+            ECDomainParameters ecSpec = new ECDomainParameters(x9.Curve, x9.G, x9.N, x9.H);
 
-			ECDomainParameters ecSpec = new ECDomainParameters(
-				curve,
-//				ECPointUtil.DecodePoint(curve, Hex.Decode("020ffa963cdca8816ccc33b8642bedf905c3d358573d3f27fbbd3b3cb9aaaf")), // G
-				curve.DecodePoint(Hex.Decode("020ffa963cdca8816ccc33b8642bedf905c3d358573d3f27fbbd3b3cb9aaaf")), // G
-				new BigInteger("883423532389192164791648750360308884807550341691627752275345424702807307"), // n
-				BigInteger.One); //1); // h
-
-//			g.initialize(ecSpec, new SecureRandom());
-			g.Init(new ECKeyGenerationParameters(ecSpec, new SecureRandom()));
+            g.Init(new ECKeyGenerationParameters(ecSpec, new SecureRandom()));
 			
 			//
 			// U side
diff --git a/crypto/test/src/test/PKCS10CertRequestTest.cs b/crypto/test/src/test/PKCS10CertRequestTest.cs
index 9bad0a678..ea27d5111 100644
--- a/crypto/test/src/test/PKCS10CertRequestTest.cs
+++ b/crypto/test/src/test/PKCS10CertRequestTest.cs
@@ -126,16 +126,9 @@ namespace Org.BouncyCastle.Tests
             string				algorithm,
             DerObjectIdentifier	algOid)
         {
-            FpCurve curve = new FpCurve(
-                new BigInteger("6864797660130609714981900799081393217269435300143305409394463459185543183397656052122559640661454554977296311391480858037121987999716643812574028291115057151"), // q (or p)
-                new BigInteger("01FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFC", 16),   // a
-                new BigInteger("0051953EB9618E1C9A1F929A21A0B68540EEA2DA725B99B315F3B8B489918EF109E156193951EC7E937B1652C0BD3BB1BF073573DF883D2C34F1EF451FD46B503F00", 16));  // b
-
-            ECDomainParameters spec = new ECDomainParameters(
-                curve,
-//				curve.DecodePoint(Hex.Decode("02C6858E06B70404E9CD9E3ECB662395B4429C648139053FB521F828AF606B4D3DBAA14B5E77EFE75928FE1DC127A2FFA8DE3348B3C1856A429BF97E7E31C2E5BD66")), // G
-                curve.DecodePoint(Hex.Decode("0200C6858E06B70404E9CD9E3ECB662395B4429C648139053FB521F828AF606B4D3DBAA14B5E77EFE75928FE1DC127A2FFA8DE3348B3C1856A429BF97E7E31C2E5BD66")), // G
-                new BigInteger("01FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFA51868783BF2F966B7FCC0148F709A5D03BB5C9B8899C47AEBB6FB71E91386409", 16)); // n
+            X9ECParameters x9 = ECNamedCurveTable.GetByName("secp521r1");
+            ECCurve curve = x9.Curve;
+            ECDomainParameters spec = new ECDomainParameters(curve, x9.G, x9.N, x9.H);
 
             ECPrivateKeyParameters privKey = new ECPrivateKeyParameters(
                 new BigInteger("5769183828869504557786041598510887460263120754767955773309066354712783118202294874205844512909370791582896372147797293913785865682804434049019366394746072023"), // d
@@ -413,15 +406,9 @@ namespace Org.BouncyCastle.Tests
             // elliptic curve openSSL
             IAsymmetricCipherKeyPairGenerator g = GeneratorUtilities.GetKeyPairGenerator("ECDSA");
 
-            ECCurve curve = new FpCurve(
-                new BigInteger("883423532389192164791648750360308885314476597252960362792450860609699839"), // q
-                new BigInteger("7fffffffffffffffffffffff7fffffffffff8000000000007ffffffffffc", 16), // a
-                new BigInteger("6b016c3bdcf18941d0d654921475ca71a9db2fb27d1d37796185c2942c0a", 16)); // b
-
-            ECDomainParameters ecSpec = new ECDomainParameters(
-                curve,
-                curve.DecodePoint(Hex.Decode("020ffa963cdca8816ccc33b8642bedf905c3d358573d3f27fbbd3b3cb9aaaf")), // G
-                new BigInteger("883423532389192164791648750360308884807550341691627752275345424702807307")); // n
+            X9ECParameters x9 = ECNamedCurveTable.GetByName("prime239v1");
+            ECCurve curve = x9.Curve;
+            ECDomainParameters ecSpec = new ECDomainParameters(curve, x9.G, x9.N, x9.H);
 
 //			g.initialize(ecSpec, new SecureRandom());
             g.Init(new ECKeyGenerationParameters(ecSpec, new SecureRandom()));
diff --git a/crypto/test/src/x509/test/TestCertificateGen.cs b/crypto/test/src/x509/test/TestCertificateGen.cs
index e91a102f1..24dbdf08f 100644
--- a/crypto/test/src/x509/test/TestCertificateGen.cs
+++ b/crypto/test/src/x509/test/TestCertificateGen.cs
@@ -5,6 +5,7 @@ using System.Text;
 using NUnit.Framework;
 
 using Org.BouncyCastle.Asn1.X509;
+using Org.BouncyCastle.Asn1.X9;
 using Org.BouncyCastle.Crypto.Digests;
 using Org.BouncyCastle.Crypto.Parameters;
 using Org.BouncyCastle.Crypto.Signers;
@@ -222,20 +223,14 @@ namespace Org.BouncyCastle.X509.Tests
             BigInteger ECPubQX = new BigInteger(Base64.Decode("HWWi17Yb+Bm3PYr/DMjLOYNFhyOwX1QY7ZvqqM+l"));
             BigInteger ECPubQY = new BigInteger(Base64.Decode("JrlJfxu3WGhqwtL/55BOs/wsUeiDFsvXcGhB8DGx"));
             BigInteger ECPrivD = new BigInteger(Base64.Decode("GYQmd/NF1B+He1iMkWt3by2Az6Eu07t0ynJ4YCAo"));
-            FpCurve curve = new FpCurve(
-               new BigInteger("883423532389192164791648750360308885314476597252960362792450860609699839"), // q
-                new BigInteger("7fffffffffffffffffffffff7fffffffffff8000000000007ffffffffffc", 16), // a
-                new BigInteger("6b016c3bdcf18941d0d654921475ca71a9db2fb27d1d37796185c2942c0a", 16)); // b
-            ECDomainParameters ecDomain =
-                new ECDomainParameters(curve, new FpPoint(curve, curve.FromBigInteger(ECParraGX), curve.FromBigInteger(ECParraGY)), ECParraN);
-            ECPublicKeyParameters ecPub = new ECPublicKeyParameters(
-				"ECDSA",
-				new FpPoint(curve,
-					curve.FromBigInteger(ECPubQX),
-					curve.FromBigInteger(ECPubQY)),
-				ecDomain);
-            ECPrivateKeyParameters ecPriv = new ECPrivateKeyParameters("ECDSA", ECPrivD, ecDomain);
 
+            X9ECParameters x9 = ECNamedCurveTable.GetByName("prime239v1");
+            ECCurve curve = x9.Curve;
+            ECDomainParameters ecDomain = new ECDomainParameters(curve, curve.ValidatePoint(ECParraGX, ECParraGY), ECParraN, ECParraH);
+
+            ECPublicKeyParameters ecPub = new ECPublicKeyParameters("ECDSA",
+                curve.ValidatePoint(ECPubQX, ECPubQY), ecDomain);
+            ECPrivateKeyParameters ecPriv = new ECPrivateKeyParameters("ECDSA", ECPrivD, ecDomain);
 
             IDictionary attrs = new Hashtable();
 			attrs[X509Name.C] = "AU";