Ejemplo n.º 1
0
 protected bool Equals(
     F2mFieldElement other)
 {
     return(m == other.m &&
            k1 == other.k1 &&
            k2 == other.k2 &&
            k3 == other.k3 &&
            representation == other.representation &&
            base.Equals(other));
 }
Ejemplo n.º 2
0
        public override ECFieldElement Add(
            ECFieldElement b)
        {
            // No check performed here for performance reasons. Instead the
            // elements involved are checked in ECPoint.F2m
            // checkFieldElements(this, b);
            IntArray        iarrClone = (IntArray)this.x.Copy();
            F2mFieldElement bF2m      = (F2mFieldElement)b;

            iarrClone.AddShifted(bF2m.x, 0);
            return(new F2mFieldElement(m, k1, k2, k3, iarrClone));
        }
Ejemplo n.º 3
0
        public override ECFieldElement Multiply(
            ECFieldElement b)
        {
            // Right-to-left comb multiplication in the IntArray
            // Input: Binary polynomials a(z) and b(z) of degree at most m-1
            // Output: c(z) = a(z) * b(z) mod f(z)

            // No check performed here for performance reasons. Instead the
            // elements involved are checked in ECPoint.F2m
            // checkFieldElements(this, b);
            F2mFieldElement bF2m = (F2mFieldElement)b;
            IntArray        mult = x.Multiply(bF2m.x, m);

            mult.Reduce(m, new int[] { k1, k2, k3 });
            return(new F2mFieldElement(m, k1, k2, k3, mult));
        }
Ejemplo n.º 4
0
        public override bool Equals(
            object obj)
        {
            if (obj == this)
            {
                return(true);
            }

            F2mFieldElement other = obj as F2mFieldElement;

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

            return(Equals(other));
        }
Ejemplo n.º 5
0
        /**
         * Adds another <code>ECPoints.F2m</code> to <code>this</code> without
         * checking if both points are on the same curve. Used by multiplication
         * algorithms, because there all points are a multiple of the same point
         * and hence the checks can be omitted.
         * @param b The other <code>ECPoints.F2m</code> to add to
         * <code>this</code>.
         * @return <code>this + b</code>
         */
        internal F2mPoint AddSimple(F2mPoint b)
        {
            if (this.IsInfinity)
            {
                return(b);
            }

            if (b.IsInfinity)
            {
                return(this);
            }

            F2mFieldElement x2 = (F2mFieldElement)b.X;
            F2mFieldElement y2 = (F2mFieldElement)b.Y;

            // Check if b == this or b == -this
            if (this.x.Equals(x2))
            {
                // this == b, i.e. this must be doubled
                if (this.y.Equals(y2))
                {
                    return((F2mPoint)this.Twice());
                }

                // this = -other, i.e. the result is the point at infinity
                return((F2mPoint)this.curve.Infinity);
            }

            ECFieldElement xSum = this.x.Add(x2);

            F2mFieldElement lambda
                = (F2mFieldElement)(this.y.Add(y2)).Divide(xSum);

            F2mFieldElement x3
                = (F2mFieldElement)lambda.Square().Add(lambda).Add(xSum).Add(this.curve.A);

            F2mFieldElement y3
                = (F2mFieldElement)lambda.Multiply(this.x.Add(x3)).Add(x3).Add(this.y);

            return(new F2mPoint(curve, x3, y3, withCompression));
        }
Ejemplo n.º 6
0
        /**
         * @param curve base curve
         * @param x x point
         * @param y y point
         * @param withCompression true if encode with point compression.
         */
        public F2mPoint(
            ECCurve curve,
            ECFieldElement x,
            ECFieldElement y,
            bool withCompression)
            : base(curve, x, y, withCompression)
        {
            if ((x != null && y == null) || (x == null && y != null))
            {
                throw new ArgumentException("Exactly one of the field elements is null");
            }

            if (x != null)
            {
                // Check if x and y are elements of the same field
                F2mFieldElement.CheckFieldElements(this.x, this.y);

                // Check if x and a are elements of the same field
                F2mFieldElement.CheckFieldElements(this.x, this.curve.A);
            }
        }
Ejemplo n.º 7
0
        /* (non-Javadoc)
         * @see Org.BouncyCastle.Math.EC.ECPoint#twice()
         */
        public override ECPoint Twice()
        {
            // Twice identity element (point at infinity) is identity
            if (this.IsInfinity)
            {
                return(this);
            }

            // if x1 == 0, then (x1, y1) == (x1, x1 + y1)
            // and hence this = -this and thus 2(x1, y1) == infinity
            if (this.x.ToBigInteger().Sign == 0)
            {
                return(this.curve.Infinity);
            }

            F2mFieldElement lambda = (F2mFieldElement)this.x.Add(this.y.Divide(this.x));
            F2mFieldElement x2     = (F2mFieldElement)lambda.Square().Add(lambda).Add(this.curve.A);
            ECFieldElement  ONE    = this.curve.FromBigInteger(BigInteger.One);
            F2mFieldElement y2     = (F2mFieldElement)this.x.Square().Add(
                x2.Multiply(lambda.Add(ONE)));

            return(new F2mPoint(this.curve, x2, y2, withCompression));
        }
Ejemplo n.º 8
0
		protected bool Equals(
			F2mFieldElement other)
		{
			return m == other.m
				&& k1 == other.k1
				&& k2 == other.k2
				&& k3 == other.k3
				&& representation == other.representation
				&& base.Equals(other);
		}