Inheritance: Asn1Encodable
示例#1
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))
         {
             throw new ArgumentException("'curve' is of an unsupported type");
         }
         IPolynomialExtensionField field = (IPolynomialExtensionField)curve.Field;
         int[] exponentsPresent          = field.MinimalPolynomial.GetExponentsPresent();
         if (exponentsPresent.Length == 3)
         {
             this.fieldID = new X9FieldID(exponentsPresent[2], exponentsPresent[1]);
         }
         else
         {
             if (exponentsPresent.Length != 5)
             {
                 throw new ArgumentException("Only trinomial and pentomial curves are supported");
             }
             this.fieldID = new X9FieldID(exponentsPresent[4], exponentsPresent[1], exponentsPresent[2], exponentsPresent[3]);
         }
     }
 }
示例#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(X9ObjectIdentifiers.prime_field, ((FpCurve)curve).GetQ());
//            }
//            else
//            {
//                this.fieldID = new X9FieldID(X9ObjectIdentifiers.characteristic_two_field, null);
//            }
            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);
            }
        }
示例#3
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 curve = new X9Curve(X9FieldID.GetInstance(seq[1]), Asn1Sequence.GetInstance(seq[2]));

            this.curve = curve.Curve;
            object obj2 = seq[3];

            if (obj2 is X9ECPoint)
            {
                this.g = (X9ECPoint)obj2;
            }
            else
            {
                this.g = new X9ECPoint(this.curve, (Asn1OctetString)obj2);
            }
            this.n    = ((DerInteger)seq[4]).Value;
            this.seed = curve.GetSeed();
            if (seq.Count == 6)
            {
                this.h = ((DerInteger)seq[5]).Value;
            }
        }
示例#4
0
        public X9ECParameters(Asn1Sequence seq)
        {
            //IL_0036: Unknown result type (might be due to invalid IL or missing references)
            if (!(seq[0] is DerInteger) || !((DerInteger)seq[0]).Value.Equals(BigInteger.One))
            {
                throw new ArgumentException("bad version in X9ECParameters");
            }
            X9Curve x9Curve = new X9Curve(X9FieldID.GetInstance(seq[1]), Asn1Sequence.GetInstance(seq[2]));

            curve = x9Curve.Curve;
            object obj = seq[3];

            if (obj is X9ECPoint)
            {
                g = (X9ECPoint)obj;
            }
            else
            {
                g = new X9ECPoint(curve, (Asn1OctetString)obj);
            }
            n    = ((DerInteger)seq[4]).Value;
            seed = x9Curve.GetSeed();
            if (seq.Count == 6)
            {
                h = ((DerInteger)seq[5]).Value;
            }
        }
示例#5
0
        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();
            }
        }
示例#6
0
 public X9ECParameters(ECCurve curve, X9ECPoint g, BigInteger n, BigInteger h, byte[] seed)
 {
     //IL_00a5: Unknown result type (might be due to invalid IL or missing references)
     //IL_00b0: Unknown result type (might be due to invalid IL or missing references)
     this.curve = curve;
     this.g     = g;
     this.n     = n;
     this.h     = h;
     this.seed  = seed;
     if (ECAlgorithms.IsFpCurve(curve))
     {
         fieldID = new X9FieldID(curve.Field.Characteristic);
         return;
     }
     if (ECAlgorithms.IsF2mCurve(curve))
     {
         IPolynomialExtensionField polynomialExtensionField = (IPolynomialExtensionField)curve.Field;
         int[] exponentsPresent = polynomialExtensionField.MinimalPolynomial.GetExponentsPresent();
         if (exponentsPresent.Length == 3)
         {
             fieldID = new X9FieldID(exponentsPresent[2], exponentsPresent[1]);
             return;
         }
         if (exponentsPresent.Length == 5)
         {
             fieldID = new X9FieldID(exponentsPresent[4], exponentsPresent[1], exponentsPresent[2], exponentsPresent[3]);
             return;
         }
         throw new ArgumentException("Only trinomial and pentomial curves are supported");
     }
     throw new ArgumentException("'curve' is of an unsupported type");
 }
示例#7
0
        public X9ECParameters(
            Asn1Sequence seq)
        {
            if (!(seq[0] is DerInteger) ||
                !((DerInteger)seq[0]).HasValue(1))
            {
                throw new ArgumentException("bad version in X9ECParameters");
            }

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

            if (seq.Count == 6)
            {
                this.h = ((DerInteger)seq[5]).Value;
            }

            X9Curve x9c = new X9Curve(
                X9FieldID.GetInstance(seq[1]), n, h,
                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.seed = x9c.GetSeed();
        }
示例#8
0
		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();
            }
        }
示例#9
0
 public X9Curve(X9FieldID fieldID, Asn1Sequence seq)
 {
     //IL_000e: Unknown result type (might be due to invalid IL or missing references)
     //IL_001c: Unknown result type (might be due to invalid IL or missing references)
     if (fieldID == null)
     {
         throw new ArgumentNullException("fieldID");
     }
     if (seq == null)
     {
         throw new ArgumentNullException("seq");
     }
     fieldIdentifier = fieldID.Identifier;
     if (fieldIdentifier.Equals(X9ObjectIdentifiers.PrimeField))
     {
         BigInteger     value           = ((DerInteger)fieldID.Parameters).Value;
         X9FieldElement x9FieldElement  = new X9FieldElement(value, (Asn1OctetString)seq[0]);
         X9FieldElement x9FieldElement2 = new X9FieldElement(value, (Asn1OctetString)seq[1]);
         curve = new FpCurve(value, x9FieldElement.Value.ToBigInteger(), x9FieldElement2.Value.ToBigInteger());
     }
     else if (fieldIdentifier.Equals(X9ObjectIdentifiers.CharacteristicTwoField))
     {
         DerSequence         derSequence         = (DerSequence)fieldID.Parameters;
         int                 intValue            = ((DerInteger)derSequence[0]).Value.IntValue;
         DerObjectIdentifier derObjectIdentifier = (DerObjectIdentifier)derSequence[1];
         int                 num = 0;
         int                 k   = 0;
         int                 k2  = 0;
         if (derObjectIdentifier.Equals(X9ObjectIdentifiers.TPBasis))
         {
             num = ((DerInteger)derSequence[2]).Value.IntValue;
         }
         else
         {
             DerSequence derSequence2 = (DerSequence)derSequence[2];
             num = ((DerInteger)derSequence2[0]).Value.IntValue;
             k   = ((DerInteger)derSequence2[1]).Value.IntValue;
             k2  = ((DerInteger)derSequence2[2]).Value.IntValue;
         }
         X9FieldElement x9FieldElement3 = new X9FieldElement(intValue, num, k, k2, (Asn1OctetString)seq[0]);
         X9FieldElement x9FieldElement4 = new X9FieldElement(intValue, num, k, k2, (Asn1OctetString)seq[1]);
         curve = new F2mCurve(intValue, num, k, k2, x9FieldElement3.Value.ToBigInteger(), x9FieldElement4.Value.ToBigInteger());
     }
     if (seq.Count == 3)
     {
         seed = ((DerBitString)seq[2]).GetBytes();
     }
 }
示例#10
0
 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 (this.fieldIdentifier.Equals(X9ObjectIdentifiers.PrimeField))
     {
         BigInteger     p        = ((DerInteger)fieldID.Parameters).Value;
         X9FieldElement element  = new X9FieldElement(p, (Asn1OctetString)seq[0]);
         X9FieldElement element2 = new X9FieldElement(p, (Asn1OctetString)seq[1]);
         this.curve = new FpCurve(p, element.Value.ToBigInteger(), element2.Value.ToBigInteger());
     }
     else if (this.fieldIdentifier.Equals(X9ObjectIdentifiers.CharacteristicTwoField))
     {
         DerSequence         parameters = (DerSequence)fieldID.Parameters;
         int                 intValue   = ((DerInteger)parameters[0]).Value.IntValue;
         DerObjectIdentifier identifier = (DerObjectIdentifier)parameters[1];
         int                 num2       = 0;
         int                 num3       = 0;
         int                 num4       = 0;
         if (identifier.Equals(X9ObjectIdentifiers.TPBasis))
         {
             num2 = ((DerInteger)parameters[2]).Value.IntValue;
         }
         else
         {
             DerSequence sequence2 = (DerSequence)parameters[2];
             num2 = ((DerInteger)sequence2[0]).Value.IntValue;
             num3 = ((DerInteger)sequence2[1]).Value.IntValue;
             num4 = ((DerInteger)sequence2[2]).Value.IntValue;
         }
         X9FieldElement element3 = new X9FieldElement(intValue, num2, num3, num4, (Asn1OctetString)seq[0]);
         X9FieldElement element4 = new X9FieldElement(intValue, num2, num3, num4, (Asn1OctetString)seq[1]);
         this.curve = new F2mCurve(intValue, num2, num3, num4, element3.Value.ToBigInteger(), element4.Value.ToBigInteger());
     }
     if (seq.Count == 3)
     {
         this.seed = ((DerBitString)seq[2]).GetBytes();
     }
 }
示例#11
0
 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 (this.fieldIdentifier.Equals(X9ObjectIdentifiers.PrimeField))
     {
         BigInteger     value           = ((DerInteger)fieldID.Parameters).Value;
         X9FieldElement x9FieldElement  = new X9FieldElement(value, (Asn1OctetString)seq[0]);
         X9FieldElement x9FieldElement2 = new X9FieldElement(value, (Asn1OctetString)seq[1]);
         this.curve = new FpCurve(value, x9FieldElement.Value.ToBigInteger(), x9FieldElement2.Value.ToBigInteger());
     }
     else if (this.fieldIdentifier.Equals(X9ObjectIdentifiers.CharacteristicTwoField))
     {
         DerSequence         derSequence         = (DerSequence)fieldID.Parameters;
         int                 intValue            = ((DerInteger)derSequence[0]).Value.IntValue;
         DerObjectIdentifier derObjectIdentifier = (DerObjectIdentifier)derSequence[1];
         int                 k  = 0;
         int                 k2 = 0;
         int                 intValue2;
         if (derObjectIdentifier.Equals(X9ObjectIdentifiers.TPBasis))
         {
             intValue2 = ((DerInteger)derSequence[2]).Value.IntValue;
         }
         else
         {
             DerSequence derSequence2 = (DerSequence)derSequence[2];
             intValue2 = ((DerInteger)derSequence2[0]).Value.IntValue;
             k         = ((DerInteger)derSequence2[1]).Value.IntValue;
             k2        = ((DerInteger)derSequence2[2]).Value.IntValue;
         }
         X9FieldElement x9FieldElement3 = new X9FieldElement(intValue, intValue2, k, k2, (Asn1OctetString)seq[0]);
         X9FieldElement x9FieldElement4 = new X9FieldElement(intValue, intValue2, k, k2, (Asn1OctetString)seq[1]);
         this.curve = new F2mCurve(intValue, intValue2, k, k2, x9FieldElement3.Value.ToBigInteger(), x9FieldElement4.Value.ToBigInteger());
     }
     if (seq.Count == 3)
     {
         this.seed = ((DerBitString)seq[2]).GetBytes();
     }
 }
        public X9ECParameters(
            ECCurve curve,
            ECPoint g,
            IBigInteger n,
            IBigInteger 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);
            }
        }
示例#13
0
        public X9ECParameters(
            ECCurve		curve,
            ECPoint		g,
            BigInteger	n,
            BigInteger	h,
            byte[]		seed)
        {
            this.curve = curve;
            this.g = g.Normalize();
            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");
            }
        }
示例#14
0
        public X9Curve(
            X9FieldID fieldID,
            BigInteger order,
            BigInteger cofactor,
            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 p = ((DerInteger)fieldID.Parameters).Value;
                BigInteger A = new BigInteger(1, Asn1OctetString.GetInstance(seq[0]).GetOctets());
                BigInteger B = new BigInteger(1, Asn1OctetString.GetInstance(seq[1]).GetOctets());
                curve = new FpCurve(p, A, B, order, cofactor);
            }
            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;
                }
                BigInteger A = new BigInteger(1, Asn1OctetString.GetInstance(seq[0]).GetOctets());
                BigInteger B = new BigInteger(1, Asn1OctetString.GetInstance(seq[1]).GetOctets());
                curve = new F2mCurve(m, k1, k2, k3, A, B, order, cofactor);
            }
            else
            {
                throw new ArgumentException("This type of ECCurve is not implemented");
            }

            if (seq.Count == 3)
            {
                seed = ((DerBitString)seq[2]).GetBytes();
            }
        }
示例#15
0
 public X9Curve(
     X9FieldID fieldID,
     Asn1Sequence seq)
     : this(fieldID, null, null, seq)
 {
 }
		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);
			}
        }
示例#17
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(X9ObjectIdentifiers.prime_field, ((FpCurve)curve).GetQ());
            //            }
            //            else
            //            {
            //                this.fieldID = new X9FieldID(X9ObjectIdentifiers.characteristic_two_field, null);
            //            }
            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);
            }
        }