コード例 #1
0
ファイル: X9Curve.cs プロジェクト: Arsslensoft/ALFX
        public X9Curve(
            X9FieldID fieldID,
            Asn1Sequence seq)
        {
            if (fieldID == null)
            {
                throw new ArgumentNullException("fieldID");
            }
            if (seq == null)
            {
                throw new ArgumentNullException("seq");
            }

            this.fieldIdentifier = fieldID.Identifier;

            if (fieldIdentifier.Equals(X9ObjectIdentifiers.PrimeField))
            {
                BigInteger     q   = ((DerInteger)fieldID.Parameters).Value;
                X9FieldElement x9A = new X9FieldElement(q, (Asn1OctetString)seq[0]);
                X9FieldElement x9B = new X9FieldElement(q, (Asn1OctetString)seq[1]);
                curve = new FpCurve(q, x9A.Value.ToBigInteger(), x9B.Value.ToBigInteger());
            }
            else
            {
                if (fieldIdentifier.Equals(X9ObjectIdentifiers.CharacteristicTwoField))
                {
                    // Characteristic two field
                    DerSequence         parameters = (DerSequence)fieldID.Parameters;
                    int                 m          = ((DerInteger)parameters[0]).Value.IntValue;
                    DerObjectIdentifier representation
                        = (DerObjectIdentifier)parameters[1];

                    int k1 = 0;
                    int k2 = 0;
                    int k3 = 0;
                    if (representation.Equals(X9ObjectIdentifiers.TPBasis))
                    {
                        // Trinomial basis representation
                        k1 = ((DerInteger)parameters[2]).Value.IntValue;
                    }
                    else
                    {
                        // Pentanomial basis representation
                        DerSequence pentanomial = (DerSequence)parameters[2];
                        k1 = ((DerInteger)pentanomial[0]).Value.IntValue;
                        k2 = ((DerInteger)pentanomial[1]).Value.IntValue;
                        k3 = ((DerInteger)pentanomial[2]).Value.IntValue;
                    }
                    X9FieldElement x9A = new X9FieldElement(m, k1, k2, k3, (Asn1OctetString)seq[0]);
                    X9FieldElement x9B = new X9FieldElement(m, k1, k2, k3, (Asn1OctetString)seq[1]);
                    // TODO Is it possible to get the order (n) and cofactor(h) too?
                    curve = new F2mCurve(m, k1, k2, k3, x9A.Value.ToBigInteger(), x9B.Value.ToBigInteger());
                }
            }

            if (seq.Count == 3)
            {
                seed = ((DerBitString)seq[2]).GetBytes();
            }
        }
コード例 #2
0
        public X9ECParameters(
            ECCurve curve,
            ECPoint g,
            BigInteger n,
            BigInteger h,
            byte[]              seed)
        {
            this.curve = curve;
            this.g     = g;
            this.n     = n;
            this.h     = h;
            this.seed  = seed;

            if (curve is FpCurve)
            {
                this.fieldID = new X9FieldID(((FpCurve)curve).Q);
            }
            else if (curve is F2mCurve)
            {
                F2mCurve curveF2m = (F2mCurve)curve;
                this.fieldID = new X9FieldID(curveF2m.M, curveF2m.K1,
                                             curveF2m.K2, curveF2m.K3);
            }
        }