Пример #1
0
 /// <summary>
 /// Constructs a FieldZqImpl.
 /// </summary>
 /// <param name="modulus">The field modulus</param>
 public FieldZqBCImpl(byte[] modulus)
 {
     if (modulus == null) throw new ArgumentNullException("modulus");
     this.modulusBytes = modulus;
     this.modulus = new BCBigInt(1, modulus);
     Zero = new FieldZqElementBCImpl(BCBigInt.Zero, this);
     One = new FieldZqElementBCImpl(BCBigInt.One, this);
 }
Пример #2
0
 /// <summary>
 /// Constructs a FieldZqImpl.
 /// </summary>
 /// <param name="modulus">The field modulus</param>
 public FieldZqBCImpl(byte[] modulus)
 {
     if (modulus == null)
     {
         throw new ArgumentNullException("modulus");
     }
     this.modulusBytes = modulus;
     this.modulus      = new BCBigInt(1, modulus);
     Zero = new FieldZqElementBCImpl(BCBigInt.Zero, this);
     One  = new FieldZqElementBCImpl(BCBigInt.One, this);
 }
        /// <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 (Object.ReferenceEquals(o, this))
            {
                return(true);
            }

            FieldZqElementBCImpl fe = o as FieldZqElementBCImpl;

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

            return(this.i.Equals(fe.i) && this.field.modulus.Equals(fe.field.modulus));
        }
Пример #4
0
        /// <summary>
        /// Returns true if the given element is an element from this field.
        /// </summary>
        /// <param name="element">The element to check.</param>
        /// <returns>True if the given element is an element from this field.</returns>
        public override bool IsElement(FieldZqElement element)
        {
            FieldZqElementBCImpl xdImpl = element as FieldZqElementBCImpl;

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

            if (((xdImpl.field) as FieldZqBCImpl).modulus != modulus)
            {
                return(false);
            }

            if (xdImpl.i < BCBigInt.Zero || xdImpl.i >= this.modulus)
            {
                return(false);
            }

            return(true);
        }
Пример #5
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));
        }