Наследование: Asn1Encodable
Пример #1
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();
            }
        }
Пример #2
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();
            }
        }
Пример #3
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();
     }
 }
Пример #4
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();
     }
 }
Пример #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 (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();
     }
 }