private void CheckOnCurve(GroupElement e)
        {
            ECGroupElementBCImpl ecge = e as ECGroupElementBCImpl;

            if (ecge == null)
            {
                throw new ArgumentNullException();
            }

            if (!ecge.Point.Y.Square().Equals(ecge.Point.X.Multiply(ecge.Point.X.Square().Add(domainParams.Curve.A)).Add(domainParams.Curve.B)))
            {
                throw new InvalidUProveArtifactException("point is not on curve");
            }
        }
        /// <summary>
        /// Returns a value indiciating whether this instance is equal to the
        /// specified object.
        /// </summary>
        /// <param name="o">An object to compare to this instance.</param>
        /// <returns>True if this object equals the other object.</returns>
        public override bool Equals(Object o)
        {
            if (o == null)
            {
                return(false);
            }

            ECGroupElementBCImpl e = o as ECGroupElementBCImpl;

            if (e == null)
            {
                return(false);
            }

            return(Point.Equals(e.Point));
        }
Exemple #3
0
        private void CheckOnCurve(GroupElement e)
        {
            ECGroupElementBCImpl ecge = e as ECGroupElementBCImpl;

            if (ecge == null)
            {
                throw new ArgumentNullException();
            }

            BouncyCastle.FpPoint        p = ecge.Point;
            BouncyCastle.ECFieldElement x = p.AffineXCoord, y = p.AffineYCoord;

            if (!y.Square().Equals(x.Multiply(x.Square().Add(domainParams.Curve.A)).Add(domainParams.Curve.B)))
            {
                throw new InvalidUProveArtifactException("point is not on curve");
            }
        }
Exemple #4
0
        /// <summary>
        /// Bouncy castle implementation of multi-exponentiation.
        /// </summary>
        /// <param name="g">bases</param>
        /// <param name="f">exponents</param>
        /// <returns></returns>
        public override GroupElement MultiExponentiate(GroupElement[] g, FieldZqElement[] f)
        {
            if (g == null || f == null || g.Length != f.Length)
            {
                throw new ArgumentException("g and f must be non-null and of the same length");
            }

            //GroupElement value = Identity;
            //for (int i = 0; i < g.Length; i++)
            //{
            //    value *= g[i].Exponentiate(f[i]);
            //}
            //return value;

            BouncyCastle.ECPoint p = curve.Infinity;

            int i = 0, limit = g.Length & ~1;

            while (i < limit)
            {
                ECGroupElementBCImpl gi0 = g[i] as ECGroupElementBCImpl;
                FieldZqElementBCImpl fi0 = f[i] as FieldZqElementBCImpl;
                ECGroupElementBCImpl gi1 = g[i + 1] as ECGroupElementBCImpl;
                FieldZqElementBCImpl fi1 = f[i + 1] as FieldZqElementBCImpl;

                p = p.Add(BouncyCastle.ECAlgorithms.SumOfTwoMultiplies(gi0.Point, fi0.i, gi1.Point, fi1.i));

                i += 2;
            }
            if (i < g.Length)
            {
                ECGroupElementBCImpl gi0 = g[i] as ECGroupElementBCImpl;
                FieldZqElementBCImpl fi0 = f[i] as FieldZqElementBCImpl;

                p = p.Add(gi0.Point.Multiply(fi0.i));
            }

            return(new ECGroupElementBCImpl(p as BouncyCastle.FpPoint));
        }