Ejemplo n.º 1
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.º 2
0
        /* (non-Javadoc)
         * @see Al.Security.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().SignValue == 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));
        }