Beispiel #1
0
        private DSTU4145ECBinary(Asn1Sequence seq)
        {
            int index = 0;

            if (seq.GetObjectAt(index) is Asn1TaggedObject)
            {
                Asn1TaggedObject taggedVersion = (Asn1TaggedObject)seq.GetObjectAt(index);
                if (taggedVersion.IsExplicit() && 0 == taggedVersion.TagNo)
                {
                    version = DerInteger.GetInstance(taggedVersion.GetObject()).Value;
                    index++;
                }
                else
                {
                    throw new ArgumentException("object parse error");
                }
            }
            f = DSTU4145BinaryField.GetInstance(seq.GetObjectAt(index));
            index++;
            a = DerInteger.GetInstance(seq.GetObjectAt(index));
            index++;
            b = Asn1OctetString.GetInstance(seq.GetObjectAt(index));
            index++;
            n = DerInteger.GetInstance(seq.GetObjectAt(index));
            index++;
            bp = Asn1OctetString.GetInstance(seq.GetObjectAt(index));
        }
Beispiel #2
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));
        }