Beispiel #1
0
        /// <summary>
        /// Constructs an ECCGroup.
        /// <param name="p">The p parameter, representing the prime field domain for the
        /// x and y coordinate spaces.</param>
        /// <param name="a">The a parameter for the eliptic curve.</param>
        /// <param name="b">The b parameter for the eliptic curve.</param>
        /// <param name="g_x">The x coordinate of the generator point.</param>
        /// <param name="g_y">The y coordinate of the generator point.</param>
        /// <param name="n">The order of the group.</param>
        /// <param name="groupName">The known name of the group, or null.</param>
        /// <param name="curveName">The known name of the curve, or null.</param>
        /// </summary>
        public ECGroupBCImpl(
            byte[] p,
            byte[] a,
            byte[] b,
            byte[] g_x,
            byte[] g_y,
            byte[] n,
            string groupName,
            string curveName)
            : base(p, a, b, g_x, g_y, n, groupName, curveName)
        {
            this.curve = new BouncyCastle.FpCurve(
                new BCBigInt(1, p),
                new BCBigInt(1, a),
                new BCBigInt(1, b));

            BouncyCastle.ECPoint generator = this.curve.CreatePoint(
                new BCBigInt(1, g_x),
                new BCBigInt(1, g_y),
                false);

            this.domainParams = new BouncyCastle.ECDomainParameters(
                this.curve,
                generator,
                new BCBigInt(1, n));

            this.g = new ECGroupElementBCImpl(
                this.domainParams.G as BouncyCastle.FpPoint);
        }
Beispiel #2
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));
        }