Inheritance: Asn1Encodable
Ejemplo n.º 1
0
        public X9ECParameters(
            Asn1Sequence seq)
        {
            if (!(seq[0] is DerInteger)
               || !((DerInteger) seq[0]).Value.Equals(BigInteger.One))
            {
                throw new ArgumentException("bad version in X9ECParameters");
            }

            X9Curve x9c = new X9Curve(
                X9FieldID.GetInstance(seq[1]),
                Asn1Sequence.GetInstance(seq[2]));

            this.curve = x9c.Curve;
            object p = seq[3];

            if (p is X9ECPoint)
            {
                this.g = ((X9ECPoint)p);
            }
            else
            {
                this.g = new X9ECPoint(curve, (Asn1OctetString)p);
            }

            this.n = ((DerInteger)seq[4]).Value;
            this.seed = x9c.GetSeed();

            if (seq.Count == 6)
            {
                this.h = ((DerInteger)seq[5]).Value;
            }
        }
Ejemplo n.º 2
0
 public X9ECParameters(
     ECCurve     curve,
     X9ECPoint   g,
     BigInteger  n,
     BigInteger  h)
     : this(curve, g, n, h, null)
 {
 }
Ejemplo n.º 3
0
        private void EncodePrivateKey()
        {
            X9ECParameters ecP = X962NamedCurves.GetByOid(X9ObjectIdentifiers.Prime239v3);

            //
            // named curve
            //
            X962Parameters _params = new X962Parameters(X9ObjectIdentifiers.Prime192v1);

            X9ECPoint pPoint = new X9ECPoint(
                new FpPoint(ecP.Curve, new FpFieldElement(BigInteger.Two, BigInteger.One),
                new FpFieldElement(BigInteger.ValueOf(4), BigInteger.ValueOf(3)),
                true));

            Asn1OctetString p = (Asn1OctetString) pPoint.ToAsn1Object();

            if (p == null)
                Fail("failed to convert to ASN.1");

            PrivateKeyInfo info = new PrivateKeyInfo(new AlgorithmIdentifier(X9ObjectIdentifiers.IdECPublicKey, _params), new ECPrivateKeyStructure(BigInteger.Ten).ToAsn1Object());

            if (!Arrays.AreEqual(info.GetEncoded(), namedPriv))
            {
                Fail("failed private named generation");
            }

            Asn1Object o = Asn1Object.FromByteArray(namedPriv);

            if (!info.Equals(o))
            {
                Fail("failed private named equality");
            }

            //
            // explicit curve parameters
            //
            _params = new X962Parameters(ecP);

            info = new PrivateKeyInfo(new AlgorithmIdentifier(X9ObjectIdentifiers.IdECPublicKey, _params), new ECPrivateKeyStructure(BigInteger.ValueOf(20)).ToAsn1Object());

            if (!Arrays.AreEqual(info.GetEncoded(), expPriv))
            {
                Fail("failed private explicit generation");
            }

            o = Asn1Object.FromByteArray(expPriv);

            if (!info.Equals(o))
            {
                Fail("failed private explicit equality");
            }
        }
Ejemplo n.º 4
0
            protected override X9ECParameters CreateParameters()
            {
                BigInteger p = FromHex("F1FD178C0B3AD58F10126DE8CE42435B3961ADBCABC8CA6DE8FCF353D86E9C03");
                BigInteger a = FromHex("F1FD178C0B3AD58F10126DE8CE42435B3961ADBCABC8CA6DE8FCF353D86E9C00");
                BigInteger b = FromHex("EE353FCA5428A9300D4ABA754A44C00FDFEC0C9AE4B1A1803075ED967B7BB73F");
                byte[] S = null;
                BigInteger n = FromHex("F1FD178C0B3AD58F10126DE8CE42435B53DC67E140D2BF941FFDD459C6D655E1");
                BigInteger h = BigInteger.One;

                ECCurve curve = ConfigureCurve(new FpCurve(p, a, b, n, h));
                X9ECPoint G = new X9ECPoint(curve, Hex.Decode("04"
                    + "B6B3D4C356C139EB31183D4749D423958C27D2DCAF98B70164C97A2DD98F5CFF"
                    + "6142E0F7C8B204911F9271F0F3ECEF8C2701C307E8E4C9E183115A1554062CFB"));

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

                ECCurve curve = ConfigureCurve(new FpCurve(p, a, b, n, h));
                X9ECPoint G = new X9ECPoint(curve, Hex.Decode("04"
                    + "09487239995A5EE76B55F9C2F098"
                    + "A89CE5AF8724C0A23E0E0FF77500"));

                return new X9ECParameters(curve, G, n, h, S);
            }
Ejemplo n.º 6
0
            protected override X9ECParameters CreateParameters()
            {
                byte[] S = null;
                ECCurve curve = ConfigureCurve(new Curve25519());

                /*
                 * NOTE: Curve25519 was specified in Montgomery form. Rewriting in Weierstrass form
                 * involves substitution of variables, so the base-point x coordinate is 9 + (486662 / 3).
                 * 
                 * The Curve25519 paper doesn't say which of the two possible y values the base
                 * point has. The choice here is guided by language in the Ed25519 paper.
                 * 
                 * (The other possible y value is 5F51E65E475F794B1FE122D388B72EB36DC2B28192839E4DD6163A5D81312C14) 
                 */
                X9ECPoint G = new X9ECPoint(curve, Hex.Decode("04"
                    + "2AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD245A"
                    + "20AE19A1B8A086B4E01EDD2C7748D14C923D4D7E6D7C61B229E9C5A27ECED3D9"));

                return new X9ECParameters(curve, G, curve.Order, curve.Cofactor, S);
            }
Ejemplo n.º 7
0
        public X9ECParameters(
            ECCurve curve,
            X9ECPoint g,
            BigInteger n,
            BigInteger h,
            byte[]      seed)
        {
            this.curve = curve;
            this.g     = g;
            this.n     = n;
            this.h     = h;
            this.seed  = seed;

            if (ECAlgorithms.IsFpCurve(curve))
            {
                this.fieldID = new X9FieldID(curve.Field.Characteristic);
            }
            else if (ECAlgorithms.IsF2mCurve(curve))
            {
                IPolynomialExtensionField field = (IPolynomialExtensionField)curve.Field;
                int[] exponents = field.MinimalPolynomial.GetExponentsPresent();
                if (exponents.Length == 3)
                {
                    this.fieldID = new X9FieldID(exponents[2], exponents[1]);
                }
                else if (exponents.Length == 5)
                {
                    this.fieldID = new X9FieldID(exponents[4], exponents[1], exponents[2], exponents[3]);
                }
                else
                {
                    throw new ArgumentException("Only trinomial and pentomial curves are supported");
                }
            }
            else
            {
                throw new ArgumentException("'curve' is of an unsupported type");
            }
        }
Ejemplo n.º 8
0
            protected override X9ECParameters CreateParameters()
            {
                BigInteger a = BigInteger.One;
                BigInteger b = FromHex("0066647EDE6C332C7F8C0923BB58213B333B20E9CE4281FE115F7D8F90AD");
                byte[] S = Hex.Decode("74D59FF07F6B413D0EA14B344B20A2DB049B50C3");
                BigInteger n = FromHex("01000000000000000000000000000013E974E72F8A6922031D2603CFE0D7");
                BigInteger h = BigInteger.ValueOf(2);

                ECCurve curve = new F2mCurve(m, k, a, b, n, h);
                X9ECPoint G = new X9ECPoint(curve, Hex.Decode("04"
                    + "00FAC9DFCBAC8313BB2139F1BB755FEF65BC391F8B36F8F8EB7371FD558B"
                    + "01006A08A41903350678E58528BEBF8A0BEFF867A7CA36716F7E01F81052"));

                return new X9ECParameters(curve, G, n, h, S);
            }
Ejemplo n.º 9
0
            protected override X9ECParameters CreateParameters()
            {
                BigInteger a = BigInteger.Zero;
                BigInteger b = BigInteger.One;
                byte[] S = null;
                BigInteger n = FromHex("8000000000000000000000000000069D5BB915BCD46EFB1AD5F173ABDF");
                BigInteger h = BigInteger.ValueOf(4);

                ECCurve curve = new F2mCurve(m, k, a, b, n, h);
                X9ECPoint G = new X9ECPoint(curve, Hex.Decode("04"
                    + "017232BA853A7E731AF129F22FF4149563A419C26BF50A4C9D6EEFAD6126"
                    + "01DB537DECE819B7F70F555A67C427A8CD9BF18AEB9B56E0C11056FAE6A3"));

                return new X9ECParameters(curve, G, n, h, S);
            }
Ejemplo n.º 10
0
            protected override X9ECParameters CreateParameters()
            {
                BigInteger a = FromHex("0163F35A5137C2CE3EA6ED8667190B0BC43ECD69977702709B");
                BigInteger b = FromHex("00C9BB9E8927D4D64C377E2AB2856A5B16E3EFB7F61D4316AE");
                byte[] S = Hex.Decode("10B7B4D696E676875615175137C8A16FD0DA2211");
                BigInteger n = FromHex("010000000000000000000000015AAB561B005413CCD4EE99D5");
                BigInteger h = BigInteger.ValueOf(2);

                ECCurve curve = new F2mCurve(m, k, a, b, n, h);
                X9ECPoint G = new X9ECPoint(curve, Hex.Decode("04"
                    + "00D9B67D192E0367C803F39E1A7E82CA14A651350AAE617E8F"
                    + "01CE94335607C304AC29E7DEFBD9CA01F596F927224CDECF6C"));

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

                GlvTypeBParameters glv = new GlvTypeBParameters(
                    new BigInteger("7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee", 16),
                    new BigInteger("5363ad4cc05c30e0a5261c028812645a122e22ea20816678df02967c1b23bd72", 16),
                    new BigInteger[]{
                        new BigInteger("3086d221a7d46bcde86c90e49284eb15", 16),
                        new BigInteger("-e4437ed6010e88286f547fa90abfe4c3", 16) },
                    new BigInteger[]{
                        new BigInteger("114ca50f7a8e2f3f657c1108d9d44cfd8", 16),
                        new BigInteger("3086d221a7d46bcde86c90e49284eb15", 16) },
                    new BigInteger("3086d221a7d46bcde86c90e49284eb153dab", 16),
                    new BigInteger("e4437ed6010e88286f547fa90abfe4c42212", 16),
                    272);

                ECCurve curve = ConfigureCurveGlv(new FpCurve(p, a, b, n, h), glv);
                X9ECPoint G = new X9ECPoint(curve, Hex.Decode("04"
                    + "79BE667EF9DCBBAC55A06295CE870B07029BFCDB2DCE28D959F2815B16F81798"
                    + "483ADA7726A3C4655DA4FBFC0E1108A8FD17B448A68554199C47D08FFB10D4B8"));

                return new X9ECParameters(curve, G, n, h, S);
            }
Ejemplo n.º 12
0
        private void EncodePublicKey()
        {
            X9ECParameters ecP = X962NamedCurves.GetByOid(X9ObjectIdentifiers.Prime239v3);

            if (X9IntegerConverter.GetByteLength(ecP.Curve) != 30)
            {
                Fail("wrong byte length reported for curve");
            }

            if (ecP.Curve.FieldSize != 239)
            {
                Fail("wrong field size reported for curve");
            }

            //
            // named curve
            //
            X962Parameters _params = new X962Parameters(X9ObjectIdentifiers.Prime192v1);

            X9ECPoint pPoint = new X9ECPoint(
                new FpPoint(ecP.Curve, new FpFieldElement(BigInteger.Two, BigInteger.One),
                new FpFieldElement(BigInteger.ValueOf(4), BigInteger.ValueOf(3)),
                true));

            Asn1OctetString p = (Asn1OctetString) pPoint.ToAsn1Object();

            if (p == null)
            {
                Fail("failed to convert to ASN.1");
            }

            SubjectPublicKeyInfo info = new SubjectPublicKeyInfo(new AlgorithmIdentifier(X9ObjectIdentifiers.IdECPublicKey, _params), p.GetOctets());

            if (!Arrays.AreEqual(info.GetEncoded(), namedPub))
            {
                Fail("failed public named generation");
            }

            Asn1Object o = Asn1Object.FromByteArray(namedPub);

            if (!info.Equals(o))
            {
                Fail("failed public named equality");
            }

            //
            // explicit curve parameters
            //
            _params = new X962Parameters(ecP);

            info = new SubjectPublicKeyInfo(new AlgorithmIdentifier(X9ObjectIdentifiers.IdECPublicKey, _params), p.GetOctets());

            if (!Arrays.AreEqual(info.GetEncoded(), expPub))
            {
                Fail("failed public explicit generation");
            }

            o = Asn1Object.FromByteArray(expPub);

            if (!info.Equals(o))
            {
                Fail("failed public explicit equality");
            }
        }
Ejemplo n.º 13
0
            protected override X9ECParameters CreateParameters()
            {
                BigInteger a = BigInteger.One;
                BigInteger b = FromHex("0021A5C2C8EE9FEB5C4B9A753B7B476B7FD6422EF1F3DD674761FA99D6AC27C8A9A197B272822F6CD57A55AA4F50AE317B13545F");
                byte[] S = Hex.Decode("4099B5A457F9D69F79213D094C4BCD4D4262210B");
                BigInteger n = FromHex("010000000000000000000000000000000000000000000000000001E2AAD6A612F33307BE5FA47C3C9E052F838164CD37D9A21173");
                BigInteger h = BigInteger.ValueOf(2);

                ECCurve curve = new F2mCurve(m, k, a, b, n, h);
                X9ECPoint G = new X9ECPoint(curve, Hex.Decode("04"
                    + "015D4860D088DDB3496B0C6064756260441CDE4AF1771D4DB01FFE5B34E59703DC255A868A1180515603AEAB60794E54BB7996A7"
                    + "0061B1CFAB6BE5F32BBFA78324ED106A7636B9C5A7BD198D0158AA4F5488D08F38514F1FDF4B4F40D2181B3681C364BA0273C706"));

                return new X9ECParameters(curve, G, n, h, S);
            }
Ejemplo n.º 14
0
            protected override X9ECParameters CreateParameters()
            {
                BigInteger a = BigInteger.One;
                BigInteger b = FromHex("027B680AC8B8596DA5A4AF8A19A0303FCA97FD7645309FA2A581485AF6263E313B79A2F5");
                byte[] S = Hex.Decode("77E2B07370EB0F832A6DD5B62DFC88CD06BB84BE");
                BigInteger n = FromHex("03FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEF90399660FC938A90165B042A7CEFADB307");
                BigInteger h = BigInteger.ValueOf(2);

                ECCurve curve = new F2mCurve(m, k1, k2, k3, a, b, n, h);
                X9ECPoint G = new X9ECPoint(curve, Hex.Decode("04"
                    + "05F939258DB7DD90E1934F8C70B0DFEC2EED25B8557EAC9C80E2E198F8CDBECD86B12053"
                    + "03676854FE24141CB98FE6D4B20D02B4516FF702350EDDB0826779C813F0DF45BE8112F4"));

                return new X9ECParameters(curve, G, n, h, S);
            }
Ejemplo n.º 15
0
            protected override X9ECParameters CreateParameters()
            {
                BigInteger a = BigInteger.One;
                BigInteger b = BigInteger.One;
                byte[] S = null;
                BigInteger n = FromHex("04000000000000000000020108A2E0CC0D99F8A5EF");
                BigInteger h = BigInteger.ValueOf(2);

                ECCurve curve = new F2mCurve(m, k1, k2, k3, a, b, n, h);
                X9ECPoint G = new X9ECPoint(curve, Hex.Decode("04"
                    + "02FE13C0537BBC11ACAA07D793DE4E6D5E5C94EEE8"
                    + "0289070FB05D38FF58321F2E800536D538CCDAA3D9"));

                return new X9ECParameters(curve, G, n, h, S);
            }
Ejemplo n.º 16
0
            protected override X9ECParameters CreateParameters()
            {
                BigInteger a = FromHex("03E5A88919D7CAFCBF415F07C2176573B2");
                BigInteger b = FromHex("04B8266A46C55657AC734CE38F018F2192");
                byte[] S = Hex.Decode("985BD3ADBAD4D696E676875615175A21B43A97E3");
                BigInteger n = FromHex("0400000000000000016954A233049BA98F");
                BigInteger h = BigInteger.ValueOf(2);

                ECCurve curve = new F2mCurve(m, k1, k2, k3, a, b, n, h);
                X9ECPoint G = new X9ECPoint(curve, Hex.Decode("04"
                    + "0356DCD8F2F95031AD652D23951BB366A8"
                    + "0648F06D867940A5366D9E265DE9EB240F"));

                return new X9ECParameters(curve, G, n, h, S);
            }
Ejemplo n.º 17
0
            protected override X9ECParameters CreateParameters()
            {
                BigInteger a = FromHex("07A11B09A76B562144418FF3FF8C2570B8");
                BigInteger b = FromHex("0217C05610884B63B9C6C7291678F9D341");
                byte[] S = Hex.Decode("4D696E676875615175985BD3ADBADA21B43A97E2");
                BigInteger n = FromHex("0400000000000000023123953A9464B54D");
                BigInteger h = BigInteger.ValueOf(2);

                ECCurve curve = new F2mCurve(m, k1, k2, k3, a, b, n, h);
                X9ECPoint G = new X9ECPoint(curve, Hex.Decode("04"
                    + "0081BAF91FDF9833C40F9C181343638399"
                    + "078C6E7EA38C001F73C8134B1B4EF9E150"));

                return new X9ECParameters(curve, G, n, h, S);
            }
Ejemplo n.º 18
0
            protected override X9ECParameters CreateParameters()
            {
                BigInteger a = FromHex("00689918DBEC7E5A0DD6DFC0AA55C7");
                BigInteger b = FromHex("0095E9A9EC9B297BD4BF36E059184F");
                byte[] S = Hex.Decode("10C0FB15760860DEF1EEF4D696E676875615175D");
                BigInteger n = FromHex("010000000000000108789B2496AF93");
                BigInteger h = BigInteger.ValueOf(2);

                ECCurve curve = new F2mCurve(m, k, a, b, n, h);
                X9ECPoint G = new X9ECPoint(curve, Hex.Decode("04"
                    + "01A57A6A7B26CA5EF52FCDB8164797"
                    + "00B3ADC94ED1FE674C06E695BABA1D"));

                return new X9ECParameters(curve, G, n, h, S);
            }
Ejemplo n.º 19
0
            protected override X9ECParameters CreateParameters()
            {
                BigInteger a = FromHex("003088250CA6E7C7FE649CE85820F7");
                BigInteger b = FromHex("00E8BEE4D3E2260744188BE0E9C723");
                byte[] S = Hex.Decode("10E723AB14D696E6768756151756FEBF8FCB49A9");
                BigInteger n = FromHex("0100000000000000D9CCEC8A39E56F");
                BigInteger h = BigInteger.ValueOf(2);

                ECCurve curve = new F2mCurve(m, k, a, b, n, h);
                X9ECPoint G = new X9ECPoint(curve, Hex.Decode("04"
                    + "009D73616F35F4AB1407D73562C10F"
                    + "00A52830277958EE84D1315ED31886"));

                return new X9ECParameters(curve, G, n, h, S);
            }
Ejemplo n.º 20
0
            protected override X9ECParameters CreateParameters()
            {
                // p = 2^521 - 1
                BigInteger p = FromHex("01FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF");
                BigInteger a = FromHex("01FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFC");
                BigInteger b = FromHex("0051953EB9618E1C9A1F929A21A0B68540EEA2DA725B99B315F3B8B489918EF109E156193951EC7E937B1652C0BD3BB1BF073573DF883D2C34F1EF451FD46B503F00");
                byte[] S = Hex.Decode("D09E8800291CB85396CC6717393284AAA0DA64BA");
                BigInteger n = FromHex("01FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFA51868783BF2F966B7FCC0148F709A5D03BB5C9B8899C47AEBB6FB71E91386409");
                BigInteger h = BigInteger.One;

                ECCurve curve = ConfigureCurve(new FpCurve(p, a, b, n, h));
                X9ECPoint G = new X9ECPoint(curve, Hex.Decode("04"
                    + "00C6858E06B70404E9CD9E3ECB662395B4429C648139053FB521F828AF606B4D3DBAA14B5E77EFE75928FE1DC127A2FFA8DE3348B3C1856A429BF97E7E31C2E5BD66"
                    + "011839296A789A3BC0045C8A5FB42C7D1BD998F54449579B446817AFBD17273E662C97EE72995EF42640C550B9013FAD0761353C7086A272C24088BE94769FD16650"));

                return new X9ECParameters(curve, G, n, h, S);
            }
Ejemplo n.º 21
0
            protected override X9ECParameters CreateParameters()
            {
                // p = 2^384 - 2^128 - 2^96 + 2^32 - 1
                BigInteger p = FromHex("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFFFF0000000000000000FFFFFFFF");
                BigInteger a = FromHex("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFFFF0000000000000000FFFFFFFC");
                BigInteger b = FromHex("B3312FA7E23EE7E4988E056BE3F82D19181D9C6EFE8141120314088F5013875AC656398D8A2ED19D2A85C8EDD3EC2AEF");
                byte[] S = Hex.Decode("A335926AA319A27A1D00896A6773A4827ACDAC73");
                BigInteger n = FromHex("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFC7634D81F4372DDF581A0DB248B0A77AECEC196ACCC52973");
                BigInteger h = BigInteger.One;

                ECCurve curve = ConfigureCurve(new FpCurve(p, a, b, n, h));
                X9ECPoint G = new X9ECPoint(curve, Hex.Decode("04"
                    + "AA87CA22BE8B05378EB1C71EF320AD746E1D3B628BA79B9859F741E082542A385502F25DBF55296C3A545E3872760AB7"
                    + "3617DE4A96262C6F5D9E98BF9292DC29F8F41DBD289A147CE9DA3113B5F0B8C00A60B1CE1D7E819D7A431D7C90EA0E5F"));

                return new X9ECParameters(curve, G, n, h, S);
            }
Ejemplo n.º 22
0
            protected override X9ECParameters CreateParameters()
            {
                BigInteger a = BigInteger.Zero;
                BigInteger b = BigInteger.One;
                byte[] S = null;
                BigInteger n = FromHex("2000000000000000000000000000005A79FEC67CB6E91F1C1DA800E478A5");
                BigInteger h = BigInteger.ValueOf(4);

                ECCurve curve = new F2mCurve(m, k, a, b, n, h);
                X9ECPoint G = new X9ECPoint(curve, Hex.Decode("04"
                    + "29A0B6A887A983E9730988A68727A8B2D126C44CC2CC7B2A6555193035DC"
                    + "76310804F12E549BDB011C103089E73510ACB275FC312A5DC6B76553F0CA"));

                return new X9ECParameters(curve, G, n, h, S);
            }
Ejemplo n.º 23
0
            protected override X9ECParameters CreateParameters()
            {
                BigInteger a = BigInteger.Zero;
                BigInteger b = BigInteger.One;
                byte[] S = null;
                BigInteger n = FromHex("01FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFE9AE2ED07577265DFF7F94451E061E163C61");
                BigInteger h = BigInteger.ValueOf(4);

                ECCurve curve = new F2mCurve(m, k1, k2, k3, a, b, n, h);
                X9ECPoint G = new X9ECPoint(curve, Hex.Decode("04"
                    + "0503213F78CA44883F1A3B8162F188E553CD265F23C1567A16876913B0C2AC2458492836"
                    + "01CCDA380F1C9E318D90F95D07E5426FE87E45C0E8184698E45962364E34116177DD2259"));

                return new X9ECParameters(curve, G, n, h, S);
            }
Ejemplo n.º 24
0
            protected override X9ECParameters CreateParameters()
            {
                // p = 2^224 - 2^96 + 1
                BigInteger p = FromHex("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF000000000000000000000001");
                BigInteger a = FromHex("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFFFFFFFFFFFFFFFFFFFE");
                BigInteger b = FromHex("B4050A850C04B3ABF54132565044B0B7D7BFD8BA270B39432355FFB4");
                byte[] S = Hex.Decode("BD71344799D5C7FCDC45B59FA3B9AB8F6A948BC5");
                BigInteger n = FromHex("FFFFFFFFFFFFFFFFFFFFFFFFFFFF16A2E0B8F03E13DD29455C5C2A3D");
                BigInteger h = BigInteger.One;

                ECCurve curve = ConfigureCurve(new FpCurve(p, a, b, n, h));
                X9ECPoint G = new X9ECPoint(curve, Hex.Decode("04"
                    + "B70E0CBD6BB4BF7F321390B94A03C1D356C21122343280D6115C1D21"
                    + "BD376388B5F723FB4C22DFE6CD4375A05A07476444D5819985007E34"));

                return new X9ECParameters(curve, G, n, h, S);
            }
Ejemplo n.º 25
0
            protected override X9ECParameters CreateParameters()
            {
                BigInteger a = BigInteger.Zero;
                BigInteger b = BigInteger.One;
                byte[] S = null;
                BigInteger n = FromHex("7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFE5F83B2D4EA20400EC4557D5ED3E3E7CA5B4B5C83B8E01E5FCF");
                BigInteger h = BigInteger.ValueOf(4);

                ECCurve curve = new F2mCurve(m, k, a, b, n, h);
                X9ECPoint G = new X9ECPoint(curve, Hex.Decode("04"
                    + "0060F05F658F49C1AD3AB1890F7184210EFD0987E307C84C27ACCFB8F9F67CC2C460189EB5AAAA62EE222EB1B35540CFE9023746"
                    + "01E369050B7C4E42ACBA1DACBF04299C3460782F918EA427E6325165E9EA10E3DA5F6C42E9C55215AA9CA27A5863EC48D8E0286B"));

                return new X9ECParameters(curve, G, n, h, S);
            }
Ejemplo n.º 26
0
            protected override X9ECParameters CreateParameters()
            {
                // p = (2^128 - 3) / 76439
                BigInteger p = FromHex("DB7C2ABF62E35E668076BEAD208B");
                BigInteger a = FromHex("6127C24C05F38A0AAAF65C0EF02C");
                BigInteger b = FromHex("51DEF1815DB5ED74FCC34C85D709");
                byte[] S = Hex.Decode("002757A1114D696E6768756151755316C05E0BD4");
                BigInteger n = FromHex("36DF0AAFD8B8D7597CA10520D04B");
                BigInteger h = BigInteger.ValueOf(4);

                ECCurve curve = ConfigureCurve(new FpCurve(p, a, b, n, h));
                X9ECPoint G = new X9ECPoint(curve, Hex.Decode("04"
                    + "4BA30AB5E892B4E1649DD0928643"
                    + "ADCD46F5882E3747DEF36E956E97"));

                return new X9ECParameters(curve, G, n, h, S);
            }
Ejemplo n.º 27
0
        public static AsymmetricKeyParameter CreateKey(
            SubjectPublicKeyInfo keyInfo)
        {
            AlgorithmIdentifier algID = keyInfo.AlgorithmID;
            DerObjectIdentifier algOid = algID.ObjectID;

            // TODO See RSAUtil.isRsaOid in Java build
            if (algOid.Equals(PkcsObjectIdentifiers.RsaEncryption)
                || algOid.Equals(X509ObjectIdentifiers.IdEARsa)
                || algOid.Equals(PkcsObjectIdentifiers.IdRsassaPss)
                || algOid.Equals(PkcsObjectIdentifiers.IdRsaesOaep))
            {
                RsaPublicKeyStructure pubKey = RsaPublicKeyStructure.GetInstance(
                    keyInfo.GetPublicKey());

                return new RsaKeyParameters(false, pubKey.Modulus, pubKey.PublicExponent);
            }
            else if (algOid.Equals(X9ObjectIdentifiers.DHPublicNumber))
            {
                Asn1Sequence seq = Asn1Sequence.GetInstance(algID.Parameters.ToAsn1Object());

                DHPublicKey dhPublicKey = DHPublicKey.GetInstance(keyInfo.GetPublicKey());

                BigInteger y = dhPublicKey.Y.Value;

                if (IsPkcsDHParam(seq))
                    return ReadPkcsDHParam(algOid, y, seq);

                DHDomainParameters dhParams = DHDomainParameters.GetInstance(seq);

                BigInteger p = dhParams.P.Value;
                BigInteger g = dhParams.G.Value;
                BigInteger q = dhParams.Q.Value;

                BigInteger j = null;
                if (dhParams.J != null)
                {
                    j = dhParams.J.Value;
                }

                DHValidationParameters validation = null;
                DHValidationParms dhValidationParms = dhParams.ValidationParms;
                if (dhValidationParms != null)
                {
                    byte[] seed = dhValidationParms.Seed.GetBytes();
                    BigInteger pgenCounter = dhValidationParms.PgenCounter.Value;

                    // TODO Check pgenCounter size?

                    validation = new DHValidationParameters(seed, pgenCounter.IntValue);
                }

                return new DHPublicKeyParameters(y, new DHParameters(p, g, q, j, validation));
            }
            else if (algOid.Equals(PkcsObjectIdentifiers.DhKeyAgreement))
            {
                Asn1Sequence seq = Asn1Sequence.GetInstance(algID.Parameters.ToAsn1Object());

                DerInteger derY = (DerInteger) keyInfo.GetPublicKey();

                return ReadPkcsDHParam(algOid, derY.Value, seq);
            }
            else if (algOid.Equals(OiwObjectIdentifiers.ElGamalAlgorithm))
            {
                ElGamalParameter para = new ElGamalParameter(
                    Asn1Sequence.GetInstance(algID.Parameters.ToAsn1Object()));
                DerInteger derY = (DerInteger) keyInfo.GetPublicKey();

                return new ElGamalPublicKeyParameters(
                    derY.Value,
                    new ElGamalParameters(para.P, para.G));
            }
            else if (algOid.Equals(X9ObjectIdentifiers.IdDsa)
                || algOid.Equals(OiwObjectIdentifiers.DsaWithSha1))
            {
                DerInteger derY = (DerInteger) keyInfo.GetPublicKey();
                Asn1Encodable ae = algID.Parameters;

                DsaParameters parameters = null;
                if (ae != null)
                {
                    DsaParameter para = DsaParameter.GetInstance(ae.ToAsn1Object());
                    parameters = new DsaParameters(para.P, para.Q, para.G);
                }

                return new DsaPublicKeyParameters(derY.Value, parameters);
            }
            else if (algOid.Equals(X9ObjectIdentifiers.IdECPublicKey))
            {
                X962Parameters para = new X962Parameters(algID.Parameters.ToAsn1Object());

                X9ECParameters x9;
                if (para.IsNamedCurve)
                {
                    x9 = ECKeyPairGenerator.FindECCurveByOid((DerObjectIdentifier)para.Parameters);
                }
                else
                {
                    x9 = new X9ECParameters((Asn1Sequence)para.Parameters);
                }

                Asn1OctetString key = new DerOctetString(keyInfo.PublicKeyData.GetBytes());
                X9ECPoint derQ = new X9ECPoint(x9.Curve, key);
                ECPoint q = derQ.Point;

                if (para.IsNamedCurve)
                {
                    return new ECPublicKeyParameters("EC", q, (DerObjectIdentifier)para.Parameters);
                }

                ECDomainParameters dParams = new ECDomainParameters(x9.Curve, x9.G, x9.N, x9.H, x9.GetSeed());
                return new ECPublicKeyParameters(q, dParams);
            }
            else if (algOid.Equals(CryptoProObjectIdentifiers.GostR3410x2001))
            {
                Gost3410PublicKeyAlgParameters gostParams = new Gost3410PublicKeyAlgParameters(
                    (Asn1Sequence) algID.Parameters);

                Asn1OctetString key;
                try
                {
                    key = (Asn1OctetString) keyInfo.GetPublicKey();
                }
                catch (IOException)
                {
                    throw new ArgumentException("invalid info structure in GOST3410 public key");
                }

                byte[] keyEnc = key.GetOctets();
                byte[] x = new byte[32];
                byte[] y = new byte[32];

                for (int i = 0; i != y.Length; i++)
                {
                    x[i] = keyEnc[32 - 1 - i];
                }

                for (int i = 0; i != x.Length; i++)
                {
                    y[i] = keyEnc[64 - 1 - i];
                }

                ECDomainParameters ecP = ECGost3410NamedCurves.GetByOid(gostParams.PublicKeyParamSet);

                if (ecP == null)
                    return null;

                ECPoint q = ecP.Curve.CreatePoint(new BigInteger(1, x), new BigInteger(1, y));

                return new ECPublicKeyParameters("ECGOST3410", q, gostParams.PublicKeyParamSet);
            }
            else if (algOid.Equals(CryptoProObjectIdentifiers.GostR3410x94))
            {
                Gost3410PublicKeyAlgParameters algParams = new Gost3410PublicKeyAlgParameters(
                    (Asn1Sequence) algID.Parameters);

                DerOctetString derY;
                try
                {
                    derY = (DerOctetString) keyInfo.GetPublicKey();
                }
                catch (IOException)
                {
                    throw new ArgumentException("invalid info structure in GOST3410 public key");
                }

                byte[] keyEnc = derY.GetOctets();
                byte[] keyBytes = new byte[keyEnc.Length];

                for (int i = 0; i != keyEnc.Length; i++)
                {
                    keyBytes[i] = keyEnc[keyEnc.Length - 1 - i]; // was little endian
                }

                BigInteger y = new BigInteger(1, keyBytes);

                return new Gost3410PublicKeyParameters(y, algParams.PublicKeyParamSet);
            }
            else
            {
                throw new SecurityUtilityException("algorithm identifier in key not recognised: " + algOid);
            }
        }
Ejemplo n.º 28
0
            protected override X9ECParameters CreateParameters()
            {
                BigInteger a = FromHex("0017858FEB7A98975169E171F77B4087DE098AC8A911DF7B01");
                BigInteger b = FromHex("00FDFB49BFE6C3A89FACADAA7A1E5BBC7CC1C2E5D831478814");
                byte[] S = Hex.Decode("103FAEC74D696E676875615175777FC5B191EF30");
                BigInteger n = FromHex("01000000000000000000000000C7F34A778F443ACC920EBA49");
                BigInteger h = BigInteger.ValueOf(2);

                ECCurve curve = new F2mCurve(m, k, a, b, n, h);
                X9ECPoint G = new X9ECPoint(curve, Hex.Decode("04"
                    + "01F481BC5F0FF84A74AD6CDF6FDEF4BF6179625372D8C0C5E1"
                    + "0025E399F2903712CCF3EA9E3A1AD17FB0B3201B6AF7CE1B05"));

                return new X9ECParameters(curve, G, n, h, S);
            }
Ejemplo n.º 29
0
            protected override X9ECParameters CreateParameters()
            {
                BigInteger a = FromHex("07B6882CAAEFA84F9554FF8428BD88E246D2782AE2");
                BigInteger b = FromHex("0713612DCDDCB40AAB946BDA29CA91F73AF958AFD9");
                byte[] S = Hex.Decode("24B7B137C8A14D696E6768756151756FD0DA2E5C");
                BigInteger n = FromHex("03FFFFFFFFFFFFFFFFFFFF48AAB689C29CA710279B");
                BigInteger h = BigInteger.ValueOf(2);

                ECCurve curve = new F2mCurve(m, k1, k2, k3, a, b, n, h);
                X9ECPoint G = new X9ECPoint(curve, Hex.Decode("04"
                    + "0369979697AB43897789566789567F787A7876A654"
                    + "00435EDB42EFAFB2989D51FEFCE3C80988F41FF883"));

                return new X9ECParameters(curve, G, n, h, S);
            }
Ejemplo n.º 30
0
            protected override X9ECParameters CreateParameters()
            {
                // p = 2^224 (2^32 - 1) + 2^192 + 2^96 - 1
                BigInteger p = FromHex("FFFFFFFF00000001000000000000000000000000FFFFFFFFFFFFFFFFFFFFFFFF");
                BigInteger a = FromHex("FFFFFFFF00000001000000000000000000000000FFFFFFFFFFFFFFFFFFFFFFFC");
                BigInteger b = FromHex("5AC635D8AA3A93E7B3EBBD55769886BC651D06B0CC53B0F63BCE3C3E27D2604B");
                byte[] S = Hex.Decode("C49D360886E704936A6678E1139D26B7819F7E90");
                BigInteger n = FromHex("FFFFFFFF00000000FFFFFFFFFFFFFFFFBCE6FAADA7179E84F3B9CAC2FC632551");
                BigInteger h = BigInteger.One;

                ECCurve curve = ConfigureCurve(new FpCurve(p, a, b, n, h));
                X9ECPoint G = new X9ECPoint(curve, Hex.Decode("04"
                    + "6B17D1F2E12C4247F8BCE6E563A440F277037D812DEB33A0F4A13945D898C296"
                    + "4FE342E2FE1A7F9B8EE7EB4A7C0F9E162BCE33576B315ECECBB6406837BF51F5"));

                return new X9ECParameters(curve, G, n, h, S);
            }
Ejemplo n.º 31
0
 public X9ECParameters(ECCurve curve, X9ECPoint g, BigInteger n, BigInteger h) : this(curve, g, n, h, null)
 {
 }
Ejemplo n.º 32
0
            protected override X9ECParameters CreateParameters()
            {
                BigInteger a = BigInteger.One;
                BigInteger b = FromHex("020A601907B8C953CA1481EB10512F78744A3205FD");
                byte[] S = Hex.Decode("85E25BFE5C86226CDB12016F7553F9D0E693A268");
                BigInteger n = FromHex("040000000000000000000292FE77E70C12A4234C33");
                BigInteger h = BigInteger.ValueOf(2);

                ECCurve curve = new F2mCurve(m, k1, k2, k3, a, b, n, h);
                X9ECPoint G = new X9ECPoint(curve, Hex.Decode("04"
                    + "03F0EBA16286A2D57EA0991168D4994637E8343E36"
                    + "00D51FBC6C71A0094FA2CDD545B11C5C0C797324F1"));

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