public void TestECNR192bitPrime()
        {
            IBigInteger r  = new BigInteger("2474388605162950674935076940284692598330235697454145648371");
            IBigInteger s  = new BigInteger("2997192822503471356158280167065034437828486078932532073836");

            byte[] kData = new BigInteger("dcc5d1f1020906df2782360d36b2de7a17ece37d503784af", 16).ToByteArrayUnsigned();

            SecureRandom k = FixedSecureRandom.From(kData);

            FPCurve curve = new FPCurve(
                new BigInteger("6277101735386680763835789423207666416083908700390324961279"), // q (or p)
                new BigInteger("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFFFFFFFFFFFC", 16),   // a
                new BigInteger("64210519E59C80E70FA7E9AB72243049FEB8DEECC146B9B1", 16));  // b

            ECDomainParameters spec = new ECDomainParameters(
                curve,
                curve.DecodePoint(Hex.Decode("03188DA80EB03090F67CBF20EB43A18800F4FF0AFD82FF1012")), // G
                new BigInteger("6277101735386680763835789423176059013767194773182842284081")); // n

            ECPrivateKeyParameters priKey = new ECPrivateKeyParameters(
                new BigInteger("651056770906015076056810763456358567190100156695615665659"), // d
                spec);

            ECPublicKeyParameters pubKey = new ECPublicKeyParameters(
                curve.DecodePoint(Hex.Decode("0262B12D60690CDCF330BABAB6E69763B471F994DD702D16A5")), // Q
                spec);

            ISigner sgr = SignerUtilities.GetSigner("SHA1withECNR");
            byte[] message = new byte[] { (byte)'a', (byte)'b', (byte)'c' };

            checkSignature(192, priKey, pubKey, sgr, k, message, r, s);
        }
        public void DecodeTest()
        {
            //			EllipticCurve curve = new EllipticCurve(
            //				new ECFieldFp(new BigInteger("6277101735386680763835789423207666416083908700390324961279")), // q
            //				new BigInteger("fffffffffffffffffffffffffffffffefffffffffffffffc", 16), // a
            //				new BigInteger("64210519e59c80e70fa7e9ab72243049feb8deecc146b9b1", 16)); // b
            ECCurve curve = new FPCurve(
                new BigInteger("6277101735386680763835789423207666416083908700390324961279"), // q
                new BigInteger("fffffffffffffffffffffffffffffffefffffffffffffffc", 16), // a
                new BigInteger("64210519e59c80e70fa7e9ab72243049feb8deecc146b9b1", 16)); // b

            //			ECPoint p = ECPointUtil.DecodePoint(curve, Hex.Decode("03188da80eb03090f67cbf20eb43a18800f4ff0afd82ff1012"));
            ECPoint p = curve.DecodePoint(Hex.Decode("03188da80eb03090f67cbf20eb43a18800f4ff0afd82ff1012"));

            IBigInteger x = p.X.ToBigInteger(); //p.getAffineX();

            if (!x.Equals(new BigInteger("188da80eb03090f67cbf20eb43a18800f4ff0afd82ff1012", 16)))
            {
                Fail("x uncompressed incorrectly");
            }

            IBigInteger y = p.Y.ToBigInteger(); //p.getAffineX();
            if (!y.Equals(new BigInteger("7192b95ffc8da78631011ed6b24cdd573f977a11e794811", 16)))
            {
                Fail("y uncompressed incorrectly");
            }
        }
Exemplo n.º 3
0
        public void TestDecode()
        {
            var curve = new FPCurve(
                new BigInteger("6277101735386680763835789423207666416083908700390324961279"), // q
                new BigInteger("fffffffffffffffffffffffffffffffefffffffffffffffc", 16), // a
                new BigInteger("64210519e59c80e70fa7e9ab72243049feb8deecc146b9b1", 16)); // b

            ECPoint p = curve.DecodePoint(Hex.Decode("03188da80eb03090f67cbf20eb43a18800f4ff0afd82ff1012"));

            if (!p.X.ToBigInteger().Equals(new BigInteger("188da80eb03090f67cbf20eb43a18800f4ff0afd82ff1012", 16)))
            {
                Fail("x uncompressed incorrectly");
            }

            if (!p.Y.ToBigInteger().Equals(new BigInteger("7192b95ffc8da78631011ed6b24cdd573f977a11e794811", 16)))
            {
                Fail("y uncompressed incorrectly");
            }

            byte[] encoding = p.GetEncoded();

            if (!AreEqual(encoding, Hex.Decode("03188da80eb03090f67cbf20eb43a18800f4ff0afd82ff1012")))
            {
                Fail("point compressed incorrectly");
            }
        }
        public override void PerformTest()
        {
            StaticTest();

            FPCurve curve = new FPCurve(
                new BigInteger("6277101735386680763835789423207666416083908700390324961279"), // q
                new BigInteger("fffffffffffffffffffffffffffffffefffffffffffffffc", 16), // a
                new BigInteger("64210519e59c80e70fa7e9ab72243049feb8deecc146b9b1", 16)); // b

            ECDomainParameters parameters = new ECDomainParameters(
                curve,
                curve.DecodePoint(Hex.Decode("03188da80eb03090f67cbf20eb43a18800f4ff0afd82ff1012")), // G
                new BigInteger("6277101735386680763835789423176059013767194773182842284081")); // n

            ECKeyPairGenerator eGen = new ECKeyPairGenerator();
            KeyGenerationParameters gParam = new ECKeyGenerationParameters(parameters, new SecureRandom());

            eGen.Init(gParam);

            IAsymmetricCipherKeyPair p1 = eGen.GenerateKeyPair();
            IAsymmetricCipherKeyPair p2 = eGen.GenerateKeyPair();

            DoTest(p1, p2);
        }
            protected override X9ECParameters CreateParameters()
            {
                // p = 2^384 - 2^128 - 2^96 + 2^32 - 1
                IBigInteger p = FromHex("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFFFF0000000000000000FFFFFFFF");
                IBigInteger a = FromHex("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFFFF0000000000000000FFFFFFFC");
                IBigInteger b = FromHex("B3312FA7E23EE7E4988E056BE3F82D19181D9C6EFE8141120314088F5013875AC656398D8A2ED19D2A85C8EDD3EC2AEF");
                byte[] S = Hex.Decode("A335926AA319A27A1D00896A6773A4827ACDAC73");
                IBigInteger n = FromHex("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFC7634D81F4372DDF581A0DB248B0A77AECEC196ACCC52973");
                IBigInteger h = BigInteger.ValueOf(1);

                ECCurve curve = new FPCurve(p, a, b);
                //ECPoint G = curve.DecodePoint(Hex.Decode("03"
                //+ "AA87CA22BE8B05378EB1C71EF320AD746E1D3B628BA79B9859F741E082542A385502F25DBF55296C3A545E3872760AB7"));
                ECPoint G = curve.DecodePoint(Hex.Decode("04"
                    + "AA87CA22BE8B05378EB1C71EF320AD746E1D3B628BA79B9859F741E082542A385502F25DBF55296C3A545E3872760AB7"
                    + "3617DE4A96262C6F5D9E98BF9292DC29F8F41DBD289A147CE9DA3113B5F0B8C00A60B1CE1D7E819D7A431D7C90EA0E5F"));

                return new X9ECParameters(curve, G, n, h, S);
            }
            protected override X9ECParameters CreateParameters()
            {
                // p = 2^256 - 2^32 - 2^9 - 2^8 - 2^7 - 2^6 - 2^4 - 1
                IBigInteger p = FromHex("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFC2F");
                IBigInteger a = BigInteger.Zero;
                IBigInteger b = BigInteger.ValueOf(7);
                byte[] S = null;
                IBigInteger n = FromHex("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141");
                IBigInteger h = BigInteger.ValueOf(1);

                ECCurve curve = new FPCurve(p, a, b);
                //ECPoint G = curve.DecodePoint(Hex.Decode("02"
                //+ "79BE667EF9DCBBAC55A06295CE870B07029BFCDB2DCE28D959F2815B16F81798"));
                ECPoint G = curve.DecodePoint(Hex.Decode("04"
                    + "79BE667EF9DCBBAC55A06295CE870B07029BFCDB2DCE28D959F2815B16F81798"
                    + "483ADA7726A3C4655DA4FBFC0E1108A8FD17B448A68554199C47D08FFB10D4B8"));

                return new X9ECParameters(curve, G, n, h, S);
            }
            protected override X9ECParameters CreateParameters()
            {
                // p = 2^224 - 2^32 - 2^12 - 2^11 - 2^9 - 2^7 - 2^4 - 2 - 1
                IBigInteger p = FromHex("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFE56D");
                IBigInteger a = BigInteger.Zero;
                IBigInteger b = BigInteger.ValueOf(5);
                byte[] S = null;
                IBigInteger n = FromHex("010000000000000000000000000001DCE8D2EC6184CAF0A971769FB1F7");
                IBigInteger h = BigInteger.ValueOf(1);

                ECCurve curve = new FPCurve(p, a, b);
                //ECPoint G = curve.DecodePoint(Hex.Decode("03"
                //+ "A1455B334DF099DF30FC28A169A467E9E47075A90F7E650EB6B7A45C"));
                ECPoint G = curve.DecodePoint(Hex.Decode("04"
                    + "A1455B334DF099DF30FC28A169A467E9E47075A90F7E650EB6B7A45C"
                    + "7E089FED7FBA344282CAFBD6F7E319F7C0B0BD59E2CA4BDB556D61A5"));

                return new X9ECParameters(curve, G, n, h, S);
            }
            protected override X9ECParameters CreateParameters()
            {
                // p = 2^192 - 2^32 - 2^12 - 2^8 - 2^7 - 2^6 - 2^3 - 1
                IBigInteger p = FromHex("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFEE37");
                IBigInteger a = BigInteger.Zero;
                IBigInteger b = BigInteger.ValueOf(3);
                byte[] S = null;
                IBigInteger n = FromHex("FFFFFFFFFFFFFFFFFFFFFFFE26F2FC170F69466A74DEFD8D");
                IBigInteger h = BigInteger.ValueOf(1);

                ECCurve curve = new FPCurve(p, a, b);
                //ECPoint G = curve.DecodePoint(Hex.Decode("03"
                //+ "DB4FF10EC057E9AE26B07D0280B7F4341DA5D1B1EAE06C7D"));
                ECPoint G = curve.DecodePoint(Hex.Decode("04"
                    + "DB4FF10EC057E9AE26B07D0280B7F4341DA5D1B1EAE06C7D"
                    + "9B2F2F6D9C5628A7844163D015BE86344082AA88D95E2F9D"));

                return new X9ECParameters(curve, G, n, h, S);
            }
            protected override X9ECParameters CreateParameters()
            {
                // p = 2^160 - 2^31 - 1
                IBigInteger p = FromHex("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF7FFFFFFF");
                IBigInteger a = FromHex("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF7FFFFFFC");
                IBigInteger b = FromHex("1C97BEFC54BD7A8B65ACF89F81D4D4ADC565FA45");
                byte[] S = Hex.Decode("1053CDE42C14D696E67687561517533BF3F83345");
                IBigInteger n = FromHex("0100000000000000000001F4C8F927AED3CA752257");
                IBigInteger h = BigInteger.ValueOf(1);

                ECCurve curve = new FPCurve(p, a, b);
                //ECPoint G = curve.DecodePoint(Hex.Decode("02"
                    //+ "4A96B5688EF573284664698968C38BB913CBFC82"));
                ECPoint G = curve.DecodePoint(Hex.Decode("04"
                    + "4A96B5688EF573284664698968C38BB913CBFC82"
                    + "23A628553168947D59DCC912042351377AC5FB32"));

                return new X9ECParameters(curve, G, n, h, S);
            }
            protected override X9ECParameters CreateParameters()
            {
                // p = 2^128 - 2^97 - 1
                IBigInteger p = FromHex("FFFFFFFDFFFFFFFFFFFFFFFFFFFFFFFF");
                IBigInteger a = FromHex("D6031998D1B3BBFEBF59CC9BBFF9AEE1");
                IBigInteger b = FromHex("5EEEFCA380D02919DC2C6558BB6D8A5D");
                byte[] S = Hex.Decode("004D696E67687561517512D8F03431FCE63B88F4");
                IBigInteger n = FromHex("3FFFFFFF7FFFFFFFBE0024720613B5A3");
                IBigInteger h = BigInteger.ValueOf(4);

                ECCurve curve = new FPCurve(p, a, b);
                //ECPoint G = curve.DecodePoint(Hex.Decode("02"
                //+ "7B6AA5D85E572983E6FB32A7CDEBC140"));
                ECPoint G = curve.DecodePoint(Hex.Decode("04"
                    + "7B6AA5D85E572983E6FB32A7CDEBC140"
                    + "27B6916A894D3AEE7106FE805FC34B44"));

                return new X9ECParameters(curve, G, n, h, S);
            }
            protected override X9ECParameters CreateParameters()
            {
                ECCurve cFp256v1 = new FPCurve(
                    new BigInteger("115792089210356248762697446949407573530086143415290314195533631308867097853951"),
                    new BigInteger("ffffffff00000001000000000000000000000000fffffffffffffffffffffffc", 16),
                    new BigInteger("5ac635d8aa3a93e7b3ebbd55769886bc651d06b0cc53b0f63bce3c3e27d2604b", 16));

                return new X9ECParameters(
                    cFp256v1,
                    cFp256v1.DecodePoint(
                        Hex.Decode("036b17d1f2e12c4247f8bce6e563a440f277037d812deb33a0f4a13945d898c296")),
                    new BigInteger("ffffffff00000000ffffffffffffffffbce6faada7179e84f3b9cac2fc632551", 16),
                    BigInteger.One,
                    Hex.Decode("c49d360886e704936a6678e1139d26b7819f7e90"));
            }
Exemplo n.º 12
0
        private void ecNR239bitPrime()
        {
            FPCurve curve = new FPCurve(
                new BigInteger("883423532389192164791648750360308885314476597252960362792450860609699839"), // q
                new BigInteger("7fffffffffffffffffffffff7fffffffffff8000000000007ffffffffffc", 16), // a
                new BigInteger("6b016c3bdcf18941d0d654921475ca71a9db2fb27d1d37796185c2942c0a", 16)); // b

            ECDomainParameters parameters = new ECDomainParameters(
                curve,
                curve.DecodePoint(Hex.Decode("020ffa963cdca8816ccc33b8642bedf905c3d358573d3f27fbbd3b3cb9aaaf")), // G
                new BigInteger("883423532389192164791648750360308884807550341691627752275345424702807307")); // n

            ECPrivateKeyParameters priKey = new ECPrivateKeyParameters(
                new BigInteger("876300101507107567501066130761671078357010671067781776716671676178726717"), // d
                parameters);

            ECNRSigner ecnr = new ECNRSigner();
            ParametersWithRandom param = new ParametersWithRandom(priKey, k);

            ecnr.Init(true, param);

            byte[] message = new BigInteger("968236873715988614170569073515315707566766479517").ToByteArray();
            IBigInteger[] sig = ecnr.GenerateSignature(message);

            if (!r.Equals(sig[0]))
            {
                Fail("r component wrong.", r, sig[0]);
            }

            if (!s.Equals(sig[1]))
            {
                Fail("s component wrong.", s, sig[1]);
            }

            // Verify the signature
            ECPublicKeyParameters pubKey = new ECPublicKeyParameters(
                curve.DecodePoint(Hex.Decode("025b6dc53bc61a2548ffb0f671472de6c9521a9d2d2534e65abfcbd5fe0c70")), // Q
                parameters);

            ecnr.Init(false, pubKey);
            if (!ecnr.VerifySignature(message, sig[0], sig[1]))
            {
                Fail("signature fails");
            }
        }
Exemplo n.º 13
0
        public void TestGeneration()
        {
            ISigner s = SignerUtilities.GetSigner("DSA");
            byte[] data = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 };
            SecureRandom rand = new SecureRandom();

            // KeyPairGenerator g = KeyPairGenerator.GetInstance("DSA");
            IAsymmetricCipherKeyPairGenerator g = GeneratorUtilities.GetKeyPairGenerator("DSA");

            // test exception
            //

            doTestBadStrength(513);
            doTestBadStrength(510);
            doTestBadStrength(1025);

            //g.initialize(512, rand);
            {
                DsaParametersGenerator pGen = new DsaParametersGenerator();
                pGen.Init(512, 80, rand);

                g.Init(new DsaKeyGenerationParameters(rand, pGen.GenerateParameters()));
            }

            IAsymmetricCipherKeyPair p = g.GenerateKeyPair();

            IAsymmetricKeyParameter sKey = p.Private;
            IAsymmetricKeyParameter vKey = p.Public;

            s.Init(true, sKey);

            s.BlockUpdate(data, 0, data.Length);

            byte[] sigBytes = s.GenerateSignature();

            s = SignerUtilities.GetSigner("DSA");

            s.Init(false, vKey);

            s.BlockUpdate(data, 0, data.Length);

            if (!s.VerifySignature(sigBytes))
            {
                Fail("DSA verification failed");
            }

            //
            // ECDSA Fp generation test
            //
            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

            g = GeneratorUtilities.GetKeyPairGenerator("ECDSA");
            g.Init(new ECKeyGenerationParameters(ecSpec, rand));

            p = g.GenerateKeyPair();

            sKey = p.Private;
            vKey = p.Public;

            s.Init(true, sKey);

            s.BlockUpdate(data, 0, data.Length);

            sigBytes = s.GenerateSignature();

            s = SignerUtilities.GetSigner("ECDSA");

            s.Init(false, vKey);

            s.BlockUpdate(data, 0, data.Length);

            if (!s.VerifySignature(sigBytes))
            {
                Fail("ECDSA verification failed");
            }

            //
            // ECDSA F2m generation test
            //
            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

            g = GeneratorUtilities.GetKeyPairGenerator("ECDSA");
            g.Init(new ECKeyGenerationParameters(ecSpec, rand));

            p = g.GenerateKeyPair();

            sKey = p.Private;
            vKey = p.Public;

            s.Init(true, sKey);

            s.BlockUpdate(data, 0, data.Length);

            sigBytes = s.GenerateSignature();

            s = SignerUtilities.GetSigner("ECDSA");

            s.Init(false, vKey);

            s.BlockUpdate(data, 0, data.Length);

            if (!s.VerifySignature(sigBytes))
            {
                Fail("ECDSA verification failed");
            }
        }
Exemplo n.º 14
0
        public void TestECDsa239BitPrime()
        {
            IBigInteger r = new BigInteger("308636143175167811492622547300668018854959378758531778147462058306432176");
            IBigInteger s = new BigInteger("323813553209797357708078776831250505931891051755007842781978505179448783");

            byte[] kData = BigIntegers.AsUnsignedByteArray(
                new BigInteger("700000017569056646655505781757157107570501575775705779575555657156756655"));

            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

            ECPrivateKeyParameters priKey = new ECPrivateKeyParameters(
                "ECDSA",
                new BigInteger("876300101507107567501066130761671078357010671067781776716671676178726717"), // d
                spec);

            ECPublicKeyParameters pubKey = new ECPublicKeyParameters(
                "ECDSA",
                curve.DecodePoint(Hex.Decode("025b6dc53bc61a2548ffb0f671472de6c9521a9d2d2534e65abfcbd5fe0c70")), // Q
                spec);

            ISigner sgr = SignerUtilities.GetSigner("ECDSA");

            //			KeyFactory f = KeyFactory.GetInstance("ECDSA");
            //			PrivateKey sKey = f.generatePrivate(priKey);
            //			PublicKey vKey = f.generatePublic(pubKey);
            IAsymmetricKeyParameter sKey = priKey;
            IAsymmetricKeyParameter vKey = pubKey;

            sgr.Init(true, new ParametersWithRandom(sKey, k));

            byte[] message = Encoding.ASCII.GetBytes("abc");

            sgr.BlockUpdate(message, 0, message.Length);

            byte[] sigBytes = sgr.GenerateSignature();

            sgr.Init(false, vKey);

            sgr.BlockUpdate(message, 0, message.Length);

            if (!sgr.VerifySignature(sigBytes))
            {
                Fail("239 Bit EC verification failed");
            }

            IBigInteger[] sig = DerDecode(sigBytes);

            if (!r.Equals(sig[0]))
            {
                Fail("r component wrong." + SimpleTest.NewLine
                        + " expecting: " + r + SimpleTest.NewLine
                        + " got      : " + sig[0]);
            }

            if (!s.Equals(sig[1]))
            {
                Fail("s component wrong." + SimpleTest.NewLine
                        + " expecting: " + s + SimpleTest.NewLine
                        + " got      : " + sig[1]);
            }
        }
Exemplo n.º 15
0
        public void TestECMqv()
        {
            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

            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()));

            //
            // U side
            //
            IAsymmetricCipherKeyPair U1 = g.GenerateKeyPair();
            IAsymmetricCipherKeyPair U2 = g.GenerateKeyPair();

            IBasicAgreement uAgree = AgreementUtilities.GetBasicAgreement("ECMQV");
            uAgree.Init(new MqvPrivateParameters(
                (ECPrivateKeyParameters)U1.Private,
                (ECPrivateKeyParameters)U2.Private,
                (ECPublicKeyParameters)U2.Public));

            //
            // V side
            //
            IAsymmetricCipherKeyPair V1 = g.GenerateKeyPair();
            IAsymmetricCipherKeyPair V2 = g.GenerateKeyPair();

            IBasicAgreement vAgree = AgreementUtilities.GetBasicAgreement("ECMQV");
            vAgree.Init(new MqvPrivateParameters(
                (ECPrivateKeyParameters)V1.Private,
                (ECPrivateKeyParameters)V2.Private,
                (ECPublicKeyParameters)V2.Public));

            //
            // agreement
            //
            IBigInteger ux = uAgree.CalculateAgreement(new MqvPublicParameters(
                (ECPublicKeyParameters)V1.Public,
                (ECPublicKeyParameters)V2.Public));
            IBigInteger vx = vAgree.CalculateAgreement(new MqvPublicParameters(
                (ECPublicKeyParameters)U1.Public,
                (ECPublicKeyParameters)U2.Public));

            if (!ux.Equals(vx))
            {
                Fail("Agreement failed");
            }
        }
            protected override X9ECParameters CreateParameters()
            {
                // p = (2^128 - 3) / 76439
                IBigInteger p = FromHex("DB7C2ABF62E35E668076BEAD208B");
                IBigInteger a = FromHex("6127C24C05F38A0AAAF65C0EF02C");
                IBigInteger b = FromHex("51DEF1815DB5ED74FCC34C85D709");
                byte[] S = Hex.Decode("002757A1114D696E6768756151755316C05E0BD4");
                IBigInteger n = FromHex("36DF0AAFD8B8D7597CA10520D04B");
                IBigInteger h = BigInteger.ValueOf(4);

                ECCurve curve = new FPCurve(p, a, b);
                //ECPoint G = curve.DecodePoint(Hex.Decode("03"
                //+ "4BA30AB5E892B4E1649DD0928643"));
                ECPoint G = curve.DecodePoint(Hex.Decode("04"
                    + "4BA30AB5E892B4E1649DD0928643"
                    + "ADCD46F5882E3747DEF36E956E97"));

                return new X9ECParameters(curve, G, n, h, S);
            }
            protected override X9ECParameters CreateParameters()
            {
                // p = 2^128 - 2^97 - 1
                IBigInteger p = FromHex("FFFFFFFDFFFFFFFFFFFFFFFFFFFFFFFF");
                IBigInteger a = FromHex("FFFFFFFDFFFFFFFFFFFFFFFFFFFFFFFC");
                IBigInteger b = FromHex("E87579C11079F43DD824993C2CEE5ED3");
                byte[] S = Hex.Decode("000E0D4D696E6768756151750CC03A4473D03679");
                IBigInteger n = FromHex("FFFFFFFE0000000075A30D1B9038A115");
                IBigInteger h = BigInteger.ValueOf(1);

                ECCurve curve = new FPCurve(p, a, b);
                //ECPoint G = curve.DecodePoint(Hex.Decode("03"
                //+ "161FF7528B899B2D0C28607CA52C5B86"));
                ECPoint G = curve.DecodePoint(Hex.Decode("04"
                    + "161FF7528B899B2D0C28607CA52C5B86"
                    + "CF5AC8395BAFEB13C02DA292DDED7A83"));

                return new X9ECParameters(curve, G, n, h, S);
            }
            protected override X9ECParameters CreateParameters()
            {
                ECCurve cFp192v1 = new FPCurve(
                    new BigInteger("6277101735386680763835789423207666416083908700390324961279"),
                    new BigInteger("fffffffffffffffffffffffffffffffefffffffffffffffc", 16),
                    new BigInteger("64210519e59c80e70fa7e9ab72243049feb8deecc146b9b1", 16));

                return new X9ECParameters(
                    cFp192v1,
                    cFp192v1.DecodePoint(
                        Hex.Decode("03188da80eb03090f67cbf20eb43a18800f4ff0afd82ff1012")),
                    new BigInteger("ffffffffffffffffffffffff99def836146bc9b1b4d22831", 16),
                    BigInteger.One,
                    Hex.Decode("3045AE6FC8422f64ED579528D38120EAE12196D5"));
            }
            protected override X9ECParameters CreateParameters()
            {
                // p = 2^160 - 2^32 - 2^14 - 2^12 - 2^9 - 2^8 - 2^7 - 2^3 - 2^2 - 1
                IBigInteger p = FromHex("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFAC73");
                IBigInteger a = BigInteger.Zero;
                IBigInteger b = BigInteger.ValueOf(7);
                byte[] S = null;
                IBigInteger n = FromHex("0100000000000000000001B8FA16DFAB9ACA16B6B3");
                IBigInteger h = BigInteger.ValueOf(1);

                ECCurve curve = new FPCurve(p, a, b);
                //ECPoint G = curve.DecodePoint(Hex.Decode("02"
                    //+ "3B4C382CE37AA192A4019E763036F4F5DD4D7EBB"));
                ECPoint G = curve.DecodePoint(Hex.Decode("04"
                    + "3B4C382CE37AA192A4019E763036F4F5DD4D7EBB"
                    + "938CF935318FDCED6BC28286531733C3F03C4FEE"));

                return new X9ECParameters(curve, G, n, h, S);
            }
            protected override X9ECParameters CreateParameters()
            {
                ECCurve cFp192v2 = new FPCurve(
                    new BigInteger("6277101735386680763835789423207666416083908700390324961279"),
                    new BigInteger("fffffffffffffffffffffffffffffffefffffffffffffffc", 16),
                    new BigInteger("cc22d6dfb95c6b25e49c0d6364a4e5980c393aa21668d953", 16));

                return new X9ECParameters(
                    cFp192v2,
                    cFp192v2.DecodePoint(
                        Hex.Decode("03eea2bae7e1497842f2de7769cfe9c989c072ad696f48034a")),
                    new BigInteger("fffffffffffffffffffffffe5fb1a724dc80418648d8dd31", 16),
                    BigInteger.One,
                    Hex.Decode("31a92ee2029fd10d901b113e990710f0d21ac6b6"));
            }
            protected override X9ECParameters CreateParameters()
            {
                // p = 2^160 - 2^32 - 2^14 - 2^12 - 2^9 - 2^8 - 2^7 - 2^3 - 2^2 - 1
                IBigInteger p = FromHex("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFAC73");
                IBigInteger a = FromHex("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFAC70");
                IBigInteger b = FromHex("B4E134D3FB59EB8BAB57274904664D5AF50388BA");
                byte[] S = Hex.Decode("B99B99B099B323E02709A4D696E6768756151751");
                IBigInteger n = FromHex("0100000000000000000000351EE786A818F3A1A16B");
                IBigInteger h = BigInteger.ValueOf(1);

                ECCurve curve = new FPCurve(p, a, b);
                //ECPoint G = curve.DecodePoint(Hex.Decode("02"
                //+ "52DCB034293A117E1F4FF11B30F7199D3144CE6D"));
                ECPoint G = curve.DecodePoint(Hex.Decode("04"
                    + "52DCB034293A117E1F4FF11B30F7199D3144CE6D"
                    + "FEAFFEF2E331F296E071FA0DF9982CFEA7D43F2E"));

                return new X9ECParameters(curve, G, n, h, S);
            }
            protected override X9ECParameters CreateParameters()
            {
                ECCurve cFp192v3 = new FPCurve(
                    new BigInteger("6277101735386680763835789423207666416083908700390324961279"),
                    new BigInteger("fffffffffffffffffffffffffffffffefffffffffffffffc", 16),
                    new BigInteger("22123dc2395a05caa7423daeccc94760a7d462256bd56916", 16));

                return new X9ECParameters(
                    cFp192v3,
                    cFp192v3.DecodePoint(
                        Hex.Decode("027d29778100c65a1da1783716588dce2b8b4aee8e228f1896")),
                    new BigInteger("ffffffffffffffffffffffff7a62d031c83f4294f640ec13", 16),
                    BigInteger.One,
                    Hex.Decode("c469684435deb378c4b65ca9591e2a5763059a2e"));
            }
            protected override X9ECParameters CreateParameters()
            {
                // p = 2^192 - 2^64 - 1
                IBigInteger p = FromHex("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFFFFFFFFFFFF");
                IBigInteger a = FromHex("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFFFFFFFFFFFC");
                IBigInteger b = FromHex("64210519E59C80E70FA7E9AB72243049FEB8DEECC146B9B1");
                byte[] S = Hex.Decode("3045AE6FC8422F64ED579528D38120EAE12196D5");
                IBigInteger n = FromHex("FFFFFFFFFFFFFFFFFFFFFFFF99DEF836146BC9B1B4D22831");
                IBigInteger h = BigInteger.ValueOf(1);

                ECCurve curve = new FPCurve(p, a, b);
                //ECPoint G = curve.DecodePoint(Hex.Decode("03"
                //+ "188DA80EB03090F67CBF20EB43A18800F4FF0AFD82FF1012"));
                ECPoint G = curve.DecodePoint(Hex.Decode("04"
                    + "188DA80EB03090F67CBF20EB43A18800F4FF0AFD82FF1012"
                    + "07192B95FFC8DA78631011ED6B24CDD573F977A11E794811"));

                return new X9ECParameters(curve, G, n, h, S);
            }
            protected override X9ECParameters CreateParameters()
            {
                ECCurve cFp239v1 = new FPCurve(
                    new BigInteger("883423532389192164791648750360308885314476597252960362792450860609699839"),
                    new BigInteger("7fffffffffffffffffffffff7fffffffffff8000000000007ffffffffffc", 16),
                    new BigInteger("6b016c3bdcf18941d0d654921475ca71a9db2fb27d1d37796185c2942c0a", 16));

                return new X9ECParameters(
                    cFp239v1,
                    cFp239v1.DecodePoint(
                        Hex.Decode("020ffa963cdca8816ccc33b8642bedf905c3d358573d3f27fbbd3b3cb9aaaf")),
                    new BigInteger("7fffffffffffffffffffffff7fffff9e5e9a9f5d9071fbd1522688909d0b", 16),
                    BigInteger.One,
                    Hex.Decode("e43bb460f0b80cc0c0b075798e948060f8321b7d"));
            }
            protected override X9ECParameters CreateParameters()
            {
                // p = 2^224 - 2^96 + 1
                IBigInteger p = FromHex("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF000000000000000000000001");
                IBigInteger a = FromHex("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFFFFFFFFFFFFFFFFFFFE");
                IBigInteger b = FromHex("B4050A850C04B3ABF54132565044B0B7D7BFD8BA270B39432355FFB4");
                byte[] S = Hex.Decode("BD71344799D5C7FCDC45B59FA3B9AB8F6A948BC5");
                IBigInteger n = FromHex("FFFFFFFFFFFFFFFFFFFFFFFFFFFF16A2E0B8F03E13DD29455C5C2A3D");
                IBigInteger h = BigInteger.ValueOf(1);

                ECCurve curve = new FPCurve(p, a, b);
                //ECPoint G = curve.DecodePoint(Hex.Decode("02"
                //+ "B70E0CBD6BB4BF7F321390B94A03C1D356C21122343280D6115C1D21"));
                ECPoint G = curve.DecodePoint(Hex.Decode("04"
                    + "B70E0CBD6BB4BF7F321390B94A03C1D356C21122343280D6115C1D21"
                    + "BD376388B5F723FB4C22DFE6CD4375A05A07476444D5819985007E34"));

                return new X9ECParameters(curve, G, n, h, S);
            }
            protected override X9ECParameters CreateParameters()
            {
                ECCurve cFp239v2 = new FPCurve(
                    new BigInteger("883423532389192164791648750360308885314476597252960362792450860609699839"),
                    new BigInteger("7fffffffffffffffffffffff7fffffffffff8000000000007ffffffffffc", 16),
                    new BigInteger("617fab6832576cbbfed50d99f0249c3fee58b94ba0038c7ae84c8c832f2c", 16));

                return new X9ECParameters(
                    cFp239v2,
                    cFp239v2.DecodePoint(
                        Hex.Decode("0238af09d98727705120c921bb5e9e26296a3cdcf2f35757a0eafd87b830e7")),
                    new BigInteger("7fffffffffffffffffffffff800000cfa7e8594377d414c03821bc582063", 16),
                    BigInteger.One,
                    Hex.Decode("e8b4011604095303ca3b8099982be09fcb9ae616"));
            }
            protected override X9ECParameters CreateParameters()
            {
                // p = 2^224 (2^32 - 1) + 2^192 + 2^96 - 1
                IBigInteger p = FromHex("FFFFFFFF00000001000000000000000000000000FFFFFFFFFFFFFFFFFFFFFFFF");
                IBigInteger a = FromHex("FFFFFFFF00000001000000000000000000000000FFFFFFFFFFFFFFFFFFFFFFFC");
                IBigInteger b = FromHex("5AC635D8AA3A93E7B3EBBD55769886BC651D06B0CC53B0F63BCE3C3E27D2604B");
                byte[] S = Hex.Decode("C49D360886E704936A6678E1139D26B7819F7E90");
                IBigInteger n = FromHex("FFFFFFFF00000000FFFFFFFFFFFFFFFFBCE6FAADA7179E84F3B9CAC2FC632551");
                IBigInteger h = BigInteger.ValueOf(1);

                ECCurve curve = new FPCurve(p, a, b);
                //ECPoint G = curve.DecodePoint(Hex.Decode("03"
                //+ "6B17D1F2E12C4247F8BCE6E563A440F277037D812DEB33A0F4A13945D898C296"));
                ECPoint G = curve.DecodePoint(Hex.Decode("04"
                    + "6B17D1F2E12C4247F8BCE6E563A440F277037D812DEB33A0F4A13945D898C296"
                    + "4FE342E2FE1A7F9B8EE7EB4A7C0F9E162BCE33576B315ECECBB6406837BF51F5"));

                return new X9ECParameters(curve, G, n, h, S);
            }
            protected override X9ECParameters CreateParameters()
            {
                ECCurve cFp239v3 = new FPCurve(
                    new BigInteger("883423532389192164791648750360308885314476597252960362792450860609699839"),
                    new BigInteger("7fffffffffffffffffffffff7fffffffffff8000000000007ffffffffffc", 16),
                    new BigInteger("255705fa2a306654b1f4cb03d6a750a30c250102d4988717d9ba15ab6d3e", 16));

                return new X9ECParameters(
                    cFp239v3,
                    cFp239v3.DecodePoint(
                        Hex.Decode("036768ae8e18bb92cfcf005c949aa2c6d94853d0e660bbf854b1c9505fe95a")),
                    new BigInteger("7fffffffffffffffffffffff7fffff975deb41b3a6057c3c432146526551", 16),
                    BigInteger.One,
                    Hex.Decode("7d7374168ffe3471b60a857686a19475d3bfa2ff"));
            }
            protected override X9ECParameters CreateParameters()
            {
                // p = 2^521 - 1
                IBigInteger p = FromHex("01FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF");
                IBigInteger a = FromHex("01FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFC");
                IBigInteger b = FromHex("0051953EB9618E1C9A1F929A21A0B68540EEA2DA725B99B315F3B8B489918EF109E156193951EC7E937B1652C0BD3BB1BF073573DF883D2C34F1EF451FD46B503F00");
                byte[] S = Hex.Decode("D09E8800291CB85396CC6717393284AAA0DA64BA");
                IBigInteger n = FromHex("01FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFA51868783BF2F966B7FCC0148F709A5D03BB5C9B8899C47AEBB6FB71E91386409");
                IBigInteger h = BigInteger.ValueOf(1);

                ECCurve curve = new FPCurve(p, a, b);
                //ECPoint G = curve.DecodePoint(Hex.Decode("02"
                //+ "00C6858E06B70404E9CD9E3ECB662395B4429C648139053FB521F828AF606B4D3DBAA14B5E77EFE75928FE1DC127A2FFA8DE3348B3C1856A429BF97E7E31C2E5BD66"));
                ECPoint G = curve.DecodePoint(Hex.Decode("04"
                    + "00C6858E06B70404E9CD9E3ECB662395B4429C648139053FB521F828AF606B4D3DBAA14B5E77EFE75928FE1DC127A2FFA8DE3348B3C1856A429BF97E7E31C2E5BD66"
                    + "011839296A789A3BC0045C8A5FB42C7D1BD998F54449579B446817AFBD17273E662C97EE72995EF42640C550B9013FAD0761353C7086A272C24088BE94769FD16650"));

                return new X9ECParameters(curve, G, n, h, S);
            }
            protected override X9ECParameters CreateParameters()
            {
                // p = (2^128 - 3) / 76439
                IBigInteger p = FromHex("DB7C2ABF62E35E668076BEAD208B");
                IBigInteger a = FromHex("DB7C2ABF62E35E668076BEAD2088");
                IBigInteger b = FromHex("659EF8BA043916EEDE8911702B22");
                byte[] S = Hex.Decode("00F50B028E4D696E676875615175290472783FB1");
                IBigInteger n = FromHex("DB7C2ABF62E35E7628DFAC6561C5");
                IBigInteger h = BigInteger.ValueOf(1);

                ECCurve curve = new FPCurve(p, a, b);
                //ECPoint G = curve.DecodePoint(Hex.Decode("02"
                //+ "09487239995A5EE76B55F9C2F098"));
                ECPoint G = curve.DecodePoint(Hex.Decode("04"
                    + "09487239995A5EE76B55F9C2F098"
                    + "A89CE5AF8724C0A23E0E0FF77500"));

                return new X9ECParameters(curve, G, n, h, S);
            }