Ejemplo n.º 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]);
         }
     }
 }
Ejemplo n.º 2
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");
 }
Ejemplo n.º 3
0
        public DSTU4145ECBinary(ECDomainParameters paramsValue)
        {
            ECCurve curve = paramsValue.Curve;

            if (!ECAlgorithms.IsF2mCurve(curve))
            {
                throw new ArgumentException("only binary domain is possible");
            }

            // We always use big-endian in parameter encoding

            IPolynomialExtensionField field = (IPolynomialExtensionField)curve.Field;

            int[] exponents = field.MinimalPolynomial.GetExponentsPresent();
            if (exponents.Length == 3)
            {
                f = new DSTU4145BinaryField(exponents[2], exponents[1]);
            }
            else if (exponents.Length == 5)
            {
                f = new DSTU4145BinaryField(exponents[4], exponents[1], exponents[2], exponents[3]);
            }
            else
            {
                throw new ArgumentException("curve must have a trinomial or pentanomial basis");
            }

            a  = new DerInteger(curve.A.ToBigInteger());
            b  = new DerOctetString(curve.B.GetEncoded());
            n  = new DerInteger(paramsValue.N);
            bp = new DerOctetString(DSTU4145PointEncoder.encodePoint(paramsValue.G));
        }
Ejemplo n.º 4
0
        public static void WriteExplicitECParameters(byte[] ecPointFormats, ECDomainParameters ecParameters,
                                                     Stream output)
        {
            ECCurve curve = ecParameters.Curve;

            if (ECAlgorithms.IsFpCurve(curve))
            {
                TlsUtilities.WriteUint8(ECCurveType.explicit_prime, output);

                WriteECParameter(curve.Field.Characteristic, output);
            }
            else if (ECAlgorithms.IsF2mCurve(curve))
            {
                IPolynomialExtensionField field = (IPolynomialExtensionField)curve.Field;
                int[] exponents = field.MinimalPolynomial.GetExponentsPresent();

                TlsUtilities.WriteUint8(ECCurveType.explicit_char2, output);

                int m = exponents[exponents.Length - 1];
                TlsUtilities.CheckUint16(m);
                TlsUtilities.WriteUint16(m, output);

                if (exponents.Length == 3)
                {
                    TlsUtilities.WriteUint8(ECBasisType.ec_basis_trinomial, output);
                    WriteECExponent(exponents[1], output);
                }
                else if (exponents.Length == 5)
                {
                    TlsUtilities.WriteUint8(ECBasisType.ec_basis_pentanomial, output);
                    WriteECExponent(exponents[1], output);
                    WriteECExponent(exponents[2], output);
                    WriteECExponent(exponents[3], output);
                }
                else
                {
                    throw new ArgumentException("Only trinomial and pentomial curves are supported");
                }
            }
            else
            {
                throw new ArgumentException("'ecParameters' not a known curve type");
            }

            WriteECFieldElement(curve.A, output);
            WriteECFieldElement(curve.B, output);
            TlsUtilities.WriteOpaque8(SerializeECPoint(ecPointFormats, ecParameters.G), output);
            WriteECParameter(ecParameters.N, output);
            WriteECParameter(ecParameters.H, output);
        }
Ejemplo n.º 5
0
        public static void WriteExplicitECParameters(byte[] ecPointFormats, ECDomainParameters ecParameters, Stream output)
        {
            //IL_00b2: Unknown result type (might be due to invalid IL or missing references)
            //IL_00bd: Unknown result type (might be due to invalid IL or missing references)
            ECCurve curve = ecParameters.Curve;

            if (ECAlgorithms.IsFpCurve(curve))
            {
                TlsUtilities.WriteUint8(1, output);
                WriteECParameter(curve.Field.Characteristic, output);
            }
            else
            {
                if (!ECAlgorithms.IsF2mCurve(curve))
                {
                    throw new ArgumentException("'ecParameters' not a known curve type");
                }
                IPolynomialExtensionField polynomialExtensionField = (IPolynomialExtensionField)curve.Field;
                int[] exponentsPresent = polynomialExtensionField.MinimalPolynomial.GetExponentsPresent();
                TlsUtilities.WriteUint8(2, output);
                int i = exponentsPresent[exponentsPresent.Length - 1];
                TlsUtilities.CheckUint16(i);
                TlsUtilities.WriteUint16(i, output);
                if (exponentsPresent.Length == 3)
                {
                    TlsUtilities.WriteUint8(1, output);
                    WriteECExponent(exponentsPresent[1], output);
                }
                else
                {
                    if (exponentsPresent.Length != 5)
                    {
                        throw new ArgumentException("Only trinomial and pentomial curves are supported");
                    }
                    TlsUtilities.WriteUint8(2, output);
                    WriteECExponent(exponentsPresent[1], output);
                    WriteECExponent(exponentsPresent[2], output);
                    WriteECExponent(exponentsPresent[3], output);
                }
            }
            WriteECFieldElement(curve.A, output);
            WriteECFieldElement(curve.B, output);
            TlsUtilities.WriteOpaque8(SerializeECPoint(ecPointFormats, ecParameters.G), output);
            WriteECParameter(ecParameters.N, output);
            WriteECParameter(ecParameters.H, output);
        }