ToBigInteger() public abstract method

public abstract ToBigInteger ( ) : BigInteger
return BigInteger
Exemplo n.º 1
0
 public virtual bool Equals(ECFieldElement other)
 {
     if (this == other)
         return true;
     if (null == other)
         return false;
     return ToBigInteger().Equals(other.ToBigInteger());
 }
Exemplo n.º 2
0
        public override ECFieldElement SquarePlusProduct(ECFieldElement x, ECFieldElement y)
        {
            BigInteger ax = this.x, xx = x.ToBigInteger(), yx = y.ToBigInteger();
            BigInteger aa  = ax.Multiply(ax);
            BigInteger xy  = xx.Multiply(yx);
            BigInteger sum = aa.Add(xy);

            if (r != null && r.SignValue < 0 && sum.BitLength > (q.BitLength << 1))
            {
                sum = sum.Subtract(q.ShiftLeft(q.BitLength));
            }
            return(new FpFieldElement(q, r, ModReduce(sum)));
        }
Exemplo n.º 3
0
        public override ECFieldElement SquarePlusProduct(ECFieldElement x, ECFieldElement y)
        {
            BigInteger val      = this.x;
            BigInteger integer2 = x.ToBigInteger();
            BigInteger integer3 = y.ToBigInteger();
            BigInteger integer4 = val.Multiply(val);
            BigInteger integer5 = integer2.Multiply(integer3);
            BigInteger integer6 = integer4.Add(integer5);

            if (((this.r != null) && (this.r.SignValue < 0)) && (integer6.BitLength > (this.q.BitLength << 1)))
            {
                integer6 = integer6.Subtract(this.q.ShiftLeft(this.q.BitLength));
            }
            return(new FpFieldElement(this.q, this.r, this.ModReduce(integer6)));
        }
Exemplo n.º 4
0
        public override ECFieldElement SquarePlusProduct(ECFieldElement x, ECFieldElement y)
        {
            BigInteger bigInteger  = this.x;
            BigInteger bigInteger2 = x.ToBigInteger();
            BigInteger val         = y.ToBigInteger();
            BigInteger bigInteger3 = bigInteger.Multiply(bigInteger);
            BigInteger value       = bigInteger2.Multiply(val);
            BigInteger bigInteger4 = bigInteger3.Add(value);

            if (r != null && r.SignValue < 0 && bigInteger4.BitLength > q.BitLength << 1)
            {
                bigInteger4 = bigInteger4.Subtract(q.ShiftLeft(q.BitLength));
            }
            return(new FpFieldElement(q, r, ModReduce(bigInteger4)));
        }
Exemplo n.º 5
0
        public override ECFieldElement MultiplyPlusProduct(ECFieldElement b, ECFieldElement x, ECFieldElement y)
        {
            BigInteger bigInteger  = this.x;
            BigInteger val         = b.ToBigInteger();
            BigInteger bigInteger2 = x.ToBigInteger();
            BigInteger val2        = y.ToBigInteger();
            BigInteger bigInteger3 = bigInteger.Multiply(val);
            BigInteger value       = bigInteger2.Multiply(val2);
            BigInteger bigInteger4 = bigInteger3.Add(value);

            if (this.r != null && this.r.SignValue < 0 && bigInteger4.BitLength > this.q.BitLength << 1)
            {
                bigInteger4 = bigInteger4.Subtract(this.q.ShiftLeft(this.q.BitLength));
            }
            return(new FpFieldElement(this.q, this.r, this.ModReduce(bigInteger4)));
        }
Exemplo n.º 6
0
        public override ECFieldElement MultiplyPlusProduct(ECFieldElement b, ECFieldElement x, ECFieldElement y)
        {
            BigInteger integer  = this.x;
            BigInteger val      = b.ToBigInteger();
            BigInteger integer3 = x.ToBigInteger();
            BigInteger integer4 = y.ToBigInteger();
            BigInteger integer5 = integer.Multiply(val);
            BigInteger integer6 = integer3.Multiply(integer4);
            BigInteger integer7 = integer5.Add(integer6);

            if (((this.r != null) && (this.r.SignValue < 0)) && (integer7.BitLength > (this.q.BitLength << 1)))
            {
                integer7 = integer7.Subtract(this.q.ShiftLeft(this.q.BitLength));
            }
            return(new FpFieldElement(this.q, this.r, this.ModReduce(integer7)));
        }
Exemplo n.º 7
0
        protected internal override ECPoint DecompressPoint(
            int yTilde,
            BigInteger X1)
        {
            ECFieldElement xp = FromBigInteger(X1);
            ECFieldElement yp = null;

            if (xp.ToBigInteger().SignValue == 0)
            {
                yp = (F2mFieldElement)b;
                for (int i = 0; i < m - 1; i++)
                {
                    yp = yp.Square();
                }
            }
            else
            {
                ECFieldElement beta = xp.Add(a).Add(
                    b.Multiply(xp.Square().Invert()));
                ECFieldElement z = solveQuadradicEquation(beta);

                if (z == null)
                {
                    throw new ArithmeticException("Invalid point compression");
                }

                int zBit = z.ToBigInteger().TestBit(0) ? 1 : 0;
                if (zBit != yTilde)
                {
                    z = z.Add(FromBigInteger(BigInteger.One));
                }

                yp = xp.Multiply(z);
            }

            return(new F2mPoint(this, xp, yp, true));
        }
Exemplo n.º 8
0
 public override ECFieldElement SquarePlusProduct(ECFieldElement x, ECFieldElement y)
 {
     BigInteger ax = this.x, xx = x.ToBigInteger(), yx = y.ToBigInteger();
     BigInteger aa = ax.Multiply(ax);
     BigInteger xy = xx.Multiply(yx);
     BigInteger sum = aa.Add(xy);
     if (r != null && r.SignValue < 0 && sum.BitLength > (q.BitLength << 1))
     {
         sum = sum.Subtract(q.ShiftLeft(q.BitLength));
     }
     return new FpFieldElement(q, r, ModReduce(sum));
 }
Exemplo n.º 9
0
 public override ECFieldElement Subtract(
     ECFieldElement b)
 {
     return(new FpFieldElement(q, r, ModSubtract(x, b.ToBigInteger())));
 }
Exemplo n.º 10
0
 public override ECFieldElement Multiply(
     ECFieldElement b)
 {
     return new FpFieldElement(q, r, ModMult(x, b.ToBigInteger()));
 }
Exemplo n.º 11
0
 public override ECFieldElement Divide(
     ECFieldElement b)
 {
     return new FpFieldElement(q, r, ModMult(x, ModInverse(b.ToBigInteger())));
 }
Exemplo n.º 12
0
 public override ECFieldElement Subtract(ECFieldElement b)
 {
     return(new FPFieldElement(_q, _x.Subtract(b.ToBigInteger()).Mod(_q)));
 }
Exemplo n.º 13
0
 public override ECFieldElement Add(
     ECFieldElement b)
 {
     return new FpFieldElement(q, r, ModAdd(x, b.ToBigInteger()));
 }
Exemplo n.º 14
0
		public override ECFieldElement Divide(
			ECFieldElement b)
		{
			return new FpFieldElement(q, x.Multiply(b.ToBigInteger().ModInverse(q)).Mod(q));
		}
        public bool Equals(
			ECFieldElement other)
        {
            return ToBigInteger().Equals(other.ToBigInteger());
        }
Exemplo n.º 16
0
        public override ECPoint Twice()
        {
            if (base.IsInfinity)
            {
                return(this);
            }
            ECCurve        curve     = this.Curve;
            ECFieldElement rawYCoord = base.RawYCoord;

            if (rawYCoord.IsZero)
            {
                return(curve.Infinity);
            }
            int            coordinateSystem = curve.CoordinateSystem;
            ECFieldElement rawXCoord        = base.RawXCoord;

            switch (coordinateSystem)
            {
            case 0:
            {
                ECFieldElement x = rawXCoord.Square();
                ECFieldElement eCFieldElement  = this.Three(x).Add(this.Curve.A).Divide(this.Two(rawYCoord));
                ECFieldElement eCFieldElement2 = eCFieldElement.Square().Subtract(this.Two(rawXCoord));
                ECFieldElement y = eCFieldElement.Multiply(rawXCoord.Subtract(eCFieldElement2)).Subtract(rawYCoord);
                return(new FpPoint(this.Curve, eCFieldElement2, y, base.IsCompressed));
            }

            case 1:
            {
                ECFieldElement eCFieldElement3 = base.RawZCoords[0];
                bool           isOne           = eCFieldElement3.IsOne;
                ECFieldElement eCFieldElement4 = curve.A;
                if (!eCFieldElement4.IsZero && !isOne)
                {
                    eCFieldElement4 = eCFieldElement4.Multiply(eCFieldElement3.Square());
                }
                eCFieldElement4 = eCFieldElement4.Add(this.Three(rawXCoord.Square()));
                ECFieldElement eCFieldElement5 = isOne ? rawYCoord : rawYCoord.Multiply(eCFieldElement3);
                ECFieldElement eCFieldElement6 = isOne ? rawYCoord.Square() : eCFieldElement5.Multiply(rawYCoord);
                ECFieldElement x2 = rawXCoord.Multiply(eCFieldElement6);
                ECFieldElement eCFieldElement7 = this.Four(x2);
                ECFieldElement eCFieldElement8 = eCFieldElement4.Square().Subtract(this.Two(eCFieldElement7));
                ECFieldElement eCFieldElement9 = this.Two(eCFieldElement5);
                ECFieldElement x3 = eCFieldElement8.Multiply(eCFieldElement9);
                ECFieldElement eCFieldElement10 = this.Two(eCFieldElement6);
                ECFieldElement y2 = eCFieldElement7.Subtract(eCFieldElement8).Multiply(eCFieldElement4).Subtract(this.Two(eCFieldElement10.Square()));
                ECFieldElement x4 = isOne ? this.Two(eCFieldElement10) : eCFieldElement9.Square();
                ECFieldElement eCFieldElement11 = this.Two(x4).Multiply(eCFieldElement5);
                return(new FpPoint(curve, x3, y2, new ECFieldElement[]
                    {
                        eCFieldElement11
                    }, base.IsCompressed));
            }

            case 2:
            {
                ECFieldElement eCFieldElement12 = base.RawZCoords[0];
                bool           isOne2           = eCFieldElement12.IsOne;
                ECFieldElement eCFieldElement13 = rawYCoord.Square();
                ECFieldElement x5 = eCFieldElement13.Square();
                ECFieldElement a  = curve.A;
                ECFieldElement eCFieldElement14 = a.Negate();
                ECFieldElement eCFieldElement15;
                ECFieldElement eCFieldElement16;
                if (eCFieldElement14.ToBigInteger().Equals(BigInteger.ValueOf(3L)))
                {
                    ECFieldElement b = isOne2 ? eCFieldElement12 : eCFieldElement12.Square();
                    eCFieldElement15 = this.Three(rawXCoord.Add(b).Multiply(rawXCoord.Subtract(b)));
                    eCFieldElement16 = this.Four(eCFieldElement13.Multiply(rawXCoord));
                }
                else
                {
                    ECFieldElement x6 = rawXCoord.Square();
                    eCFieldElement15 = this.Three(x6);
                    if (isOne2)
                    {
                        eCFieldElement15 = eCFieldElement15.Add(a);
                    }
                    else if (!a.IsZero)
                    {
                        ECFieldElement eCFieldElement17 = isOne2 ? eCFieldElement12 : eCFieldElement12.Square();
                        ECFieldElement eCFieldElement18 = eCFieldElement17.Square();
                        if (eCFieldElement14.BitLength < a.BitLength)
                        {
                            eCFieldElement15 = eCFieldElement15.Subtract(eCFieldElement18.Multiply(eCFieldElement14));
                        }
                        else
                        {
                            eCFieldElement15 = eCFieldElement15.Add(eCFieldElement18.Multiply(a));
                        }
                    }
                    eCFieldElement16 = this.Four(rawXCoord.Multiply(eCFieldElement13));
                }
                ECFieldElement eCFieldElement19 = eCFieldElement15.Square().Subtract(this.Two(eCFieldElement16));
                ECFieldElement y3 = eCFieldElement16.Subtract(eCFieldElement19).Multiply(eCFieldElement15).Subtract(this.Eight(x5));
                ECFieldElement eCFieldElement20 = this.Two(rawYCoord);
                if (!isOne2)
                {
                    eCFieldElement20 = eCFieldElement20.Multiply(eCFieldElement12);
                }
                return(new FpPoint(curve, eCFieldElement19, y3, new ECFieldElement[]
                    {
                        eCFieldElement20
                    }, base.IsCompressed));
            }

            case 4:
                return(this.TwiceJacobianModified(true));
            }
            throw new InvalidOperationException("unsupported coordinate system");
        }
Exemplo n.º 17
0
        public override ECPoint Twice()
        {
            ECFieldElement element20;
            bool           isOne;
            ECFieldElement element22;
            ECFieldElement element25;
            ECFieldElement element26;

            if (base.IsInfinity)
            {
                return(this);
            }
            ECCurve        curve     = this.Curve;
            ECFieldElement rawYCoord = base.RawYCoord;

            if (rawYCoord.IsZero)
            {
                return(curve.Infinity);
            }
            int            coordinateSystem = curve.CoordinateSystem;
            ECFieldElement rawXCoord        = base.RawXCoord;

            switch (coordinateSystem)
            {
            case 0:
            {
                ECFieldElement x        = rawXCoord.Square();
                ECFieldElement element4 = this.Three(x).Add(this.Curve.A).Divide(this.Two(rawYCoord));
                ECFieldElement element5 = element4.Square().Subtract(this.Two(rawXCoord));
                return(new FpPoint(this.Curve, element5, element4.Multiply(rawXCoord.Subtract(element5)).Subtract(rawYCoord), base.IsCompressed));
            }

            case 1:
            {
                ECFieldElement element7 = base.RawZCoords[0];
                bool           isOne    = element7.IsOne;
                ECFieldElement a        = curve.A;
                if (!a.IsZero && !isOne)
                {
                    a = a.Multiply(element7.Square());
                }
                a = a.Add(this.Three(rawXCoord.Square()));
                ECFieldElement x = !isOne?rawYCoord.Multiply(element7) : rawYCoord;

                ECFieldElement element10 = !isOne?x.Multiply(rawYCoord) : rawYCoord.Square();

                ECFieldElement element11 = rawXCoord.Multiply(element10);
                ECFieldElement element12 = this.Four(element11);
                ECFieldElement element13 = a.Square().Subtract(this.Two(element12));
                ECFieldElement element14 = this.Two(x);
                ECFieldElement element15 = element13.Multiply(element14);
                ECFieldElement element16 = this.Two(element10);
                ECFieldElement element17 = element12.Subtract(element13).Multiply(a).Subtract(this.Two(element16.Square()));
                ECFieldElement element18 = !isOne?element14.Square() : this.Two(element16);

                ECFieldElement element19 = this.Two(element18).Multiply(x);
                return(new FpPoint(curve, element15, element17, new ECFieldElement[] { element19 }, base.IsCompressed));
            }

            case 2:
            {
                element20 = base.RawZCoords[0];
                isOne     = element20.IsOne;
                ECFieldElement element21 = rawYCoord.Square();
                element22 = element21.Square();
                ECFieldElement a         = curve.A;
                ECFieldElement element24 = a.Negate();
                if (!element24.ToBigInteger().Equals(BigInteger.ValueOf(3L)))
                {
                    ECFieldElement x = rawXCoord.Square();
                    element25 = this.Three(x);
                    if (isOne)
                    {
                        element25 = element25.Add(a);
                    }
                    else if (!a.IsZero)
                    {
                        ECFieldElement element30 = (!isOne ? element20.Square() : element20).Square();
                        if (element24.BitLength < a.BitLength)
                        {
                            element25 = element25.Subtract(element30.Multiply(element24));
                        }
                        else
                        {
                            element25 = element25.Add(element30.Multiply(a));
                        }
                    }
                    element26 = this.Four(rawXCoord.Multiply(element21));
                    break;
                }
                ECFieldElement element27 = !isOne?element20.Square() : element20;

                element25 = this.Three(rawXCoord.Add(element27).Multiply(rawXCoord.Subtract(element27)));
                element26 = this.Four(element21.Multiply(rawXCoord));
                break;
            }

            case 4:
                return(this.TwiceJacobianModified(true));

            default:
                throw new InvalidOperationException("unsupported coordinate system");
            }
            ECFieldElement b         = element25.Square().Subtract(this.Two(element26));
            ECFieldElement y         = element26.Subtract(b).Multiply(element25).Subtract(this.Eight(element22));
            ECFieldElement element33 = this.Two(rawYCoord);

            if (!isOne)
            {
                element33 = element33.Multiply(element20);
            }
            return(new FpPoint(curve, b, y, new ECFieldElement[] { element33 }, base.IsCompressed));
        }
 public override ECFieldElement Add(ECFieldElement b)
 {
     return new FPFieldElement(_q, _x.Add(b.ToBigInteger()).Mod(_q));
 }
Exemplo n.º 19
0
 public override ECFieldElement Divide(ECFieldElement b) =>
 new FpFieldElement(this.q, this.r, this.ModMult(this.x, this.ModInverse(b.ToBigInteger())));
Exemplo n.º 20
0
 public override ECFieldElement Subtract(ECFieldElement b) =>
 new FpFieldElement(this.q, this.r, this.ModSubtract(this.x, b.ToBigInteger()));
Exemplo n.º 21
0
        public override ECFieldElement MultiplyMinusProduct(ECFieldElement b, ECFieldElement x, ECFieldElement y)
        {
            BigInteger ax = this.x, bx = b.ToBigInteger(), xx = x.ToBigInteger(), yx = y.ToBigInteger();
            BigInteger ab = ax.Multiply(bx);
            BigInteger xy = xx.Multiply(yx);

            return(new FpFieldElement(q, r, ModReduce(ab.Subtract(xy))));
        }
Exemplo n.º 22
0
		public override ECFieldElement Add(
			ECFieldElement b)
		{
			return new FpFieldElement(q, x.Add(b.ToBigInteger()).Mod(q));
		}
Exemplo n.º 23
0
 public virtual bool Equals(ECFieldElement other)
 {
     return(this == other || (other != null && this.ToBigInteger().Equals(other.ToBigInteger())));
 }
Exemplo n.º 24
0
 public override ECFieldElement Add(ECFieldElement b) =>
 new FpFieldElement(this.q, this.r, this.ModAdd(this.x, b.ToBigInteger()));
Exemplo n.º 25
0
		protected virtual bool Equals(
			ECFieldElement other)
		{
			return ToBigInteger().Equals(other.ToBigInteger());
		}
Exemplo n.º 26
0
 public override ECFieldElement Add(
     ECFieldElement b)
 {
     return(new FpFieldElement(q, x.Add(b.ToBigInteger()).Mod(q)));
 }
Exemplo n.º 27
0
 public override ECFieldElement Add(ECFieldElement b)
 {
     return(new FPFieldElement(_q, _x.Add(b.ToBigInteger()).Mod(_q)));
 }
Exemplo n.º 28
0
 public override ECFieldElement Multiply(
     ECFieldElement b)
 {
     return(new FpFieldElement(q, x.Multiply(b.ToBigInteger()).Mod(q)));
 }
Exemplo n.º 29
0
 public override ECFieldElement Divide(ECFieldElement b)
 {
     return(new FPFieldElement(_q, _x.Multiply(b.ToBigInteger().ModInverse(_q)).Mod(_q)));
 }
Exemplo n.º 30
0
 protected bool Equals(
     ECFieldElement other)
 {
     return(ToBigInteger().Equals(other.ToBigInteger()));
 }
Exemplo n.º 31
0
 public override ECFieldElement Subtract(
     ECFieldElement b)
 {
     return new FpFieldElement(q, r, ModSubtract(x, b.ToBigInteger()));
 }
Exemplo n.º 32
0
		/**
         * Solves a quadratic equation <code>z<sup>2</sup> + z = beta</code>(X9.62
         * D.1.6) The other solution is <code>z + 1</code>.
         *
         * @param beta
         *            The value to solve the qradratic equation for.
         * @return the solution for <code>z<sup>2</sup> + z = beta</code> or
         *         <code>null</code> if no solution exists.
         */
        private ECFieldElement solveQuadradicEquation(ECFieldElement beta)
        {
            if (beta.ToBigInteger().SignValue == 0)
            {
                return FromBigInteger(BigInteger.Zero);
            }

			ECFieldElement z = null;
            ECFieldElement gamma = FromBigInteger(BigInteger.Zero);

			while (gamma.ToBigInteger().SignValue == 0)
            {
                ECFieldElement t = FromBigInteger(new BigInteger(m, new Random()));
				z = FromBigInteger(BigInteger.Zero);

				ECFieldElement w = beta;
                for (int i = 1; i <= m - 1; i++)
                {
					ECFieldElement w2 = w.Square();
                    z = z.Square().Add(w2.Multiply(t));
                    w = w2.Add(beta);
                }
                if (w.ToBigInteger().SignValue != 0)
                {
                    return null;
                }
                gamma = z.Square().Add(z);
            }
            return z;
        }
Exemplo n.º 33
0
 public override ECFieldElement MultiplyMinusProduct(ECFieldElement b, ECFieldElement x, ECFieldElement y)
 {
     BigInteger ax = this.x, bx = b.ToBigInteger(), xx = x.ToBigInteger(), yx = y.ToBigInteger();
     BigInteger ab = ax.Multiply(bx);
     BigInteger xy = xx.Multiply(yx);
     return new FpFieldElement(q, r, ModReduce(ab.Subtract(xy)));
 }
Exemplo n.º 34
0
        public override ECPoint Twice()
        {
            //IL_0386: Unknown result type (might be due to invalid IL or missing references)
            if (base.IsInfinity)
            {
                return(this);
            }
            ECCurve        curve     = Curve;
            ECFieldElement rawYCoord = base.RawYCoord;

            if (rawYCoord.IsZero)
            {
                return(curve.Infinity);
            }
            int            coordinateSystem = curve.CoordinateSystem;
            ECFieldElement rawXCoord        = base.RawXCoord;

            switch (coordinateSystem)
            {
            case 0:
            {
                ECFieldElement x3 = rawXCoord.Square();
                ECFieldElement eCFieldElement10 = Three(x3).Add(Curve.A).Divide(Two(rawYCoord));
                ECFieldElement eCFieldElement11 = eCFieldElement10.Square().Subtract(Two(rawXCoord));
                ECFieldElement y2 = eCFieldElement10.Multiply(rawXCoord.Subtract(eCFieldElement11)).Subtract(rawYCoord);
                return(new FpPoint(Curve, eCFieldElement11, y2, base.IsCompressed));
            }

            case 1:
            {
                ECFieldElement eCFieldElement12 = base.RawZCoords[0];
                bool           isOne2           = eCFieldElement12.IsOne;
                ECFieldElement eCFieldElement13 = curve.A;
                if (!eCFieldElement13.IsZero && !isOne2)
                {
                    eCFieldElement13 = eCFieldElement13.Multiply(eCFieldElement12.Square());
                }
                eCFieldElement13 = eCFieldElement13.Add(Three(rawXCoord.Square()));
                ECFieldElement eCFieldElement14 = (isOne2 ? rawYCoord : rawYCoord.Multiply(eCFieldElement12));
                ECFieldElement eCFieldElement15 = (isOne2 ? rawYCoord.Square() : eCFieldElement14.Multiply(rawYCoord));
                ECFieldElement x4 = rawXCoord.Multiply(eCFieldElement15);
                ECFieldElement eCFieldElement16 = Four(x4);
                ECFieldElement eCFieldElement17 = eCFieldElement13.Square().Subtract(Two(eCFieldElement16));
                ECFieldElement eCFieldElement18 = Two(eCFieldElement14);
                ECFieldElement x5 = eCFieldElement17.Multiply(eCFieldElement18);
                ECFieldElement eCFieldElement19 = Two(eCFieldElement15);
                ECFieldElement y3 = eCFieldElement16.Subtract(eCFieldElement17).Multiply(eCFieldElement13).Subtract(Two(eCFieldElement19.Square()));
                ECFieldElement x6 = (isOne2 ? Two(eCFieldElement19) : eCFieldElement18.Square());
                ECFieldElement eCFieldElement20 = Two(x6).Multiply(eCFieldElement14);
                return(new FpPoint(curve, x5, y3, new ECFieldElement[1] {
                        eCFieldElement20
                    }, base.IsCompressed));
            }

            case 2:
            {
                ECFieldElement eCFieldElement  = base.RawZCoords[0];
                bool           isOne           = eCFieldElement.IsOne;
                ECFieldElement eCFieldElement2 = rawYCoord.Square();
                ECFieldElement x = eCFieldElement2.Square();
                ECFieldElement a = curve.A;
                ECFieldElement eCFieldElement3 = a.Negate();
                ECFieldElement eCFieldElement4;
                ECFieldElement eCFieldElement5;
                if (eCFieldElement3.ToBigInteger().Equals(BigInteger.ValueOf(3L)))
                {
                    ECFieldElement b = (isOne ? eCFieldElement : eCFieldElement.Square());
                    eCFieldElement4 = Three(rawXCoord.Add(b).Multiply(rawXCoord.Subtract(b)));
                    eCFieldElement5 = Four(eCFieldElement2.Multiply(rawXCoord));
                }
                else
                {
                    ECFieldElement x2 = rawXCoord.Square();
                    eCFieldElement4 = Three(x2);
                    if (isOne)
                    {
                        eCFieldElement4 = eCFieldElement4.Add(a);
                    }
                    else if (!a.IsZero)
                    {
                        ECFieldElement eCFieldElement6 = (isOne ? eCFieldElement : eCFieldElement.Square());
                        ECFieldElement eCFieldElement7 = eCFieldElement6.Square();
                        eCFieldElement4 = ((eCFieldElement3.BitLength >= a.BitLength) ? eCFieldElement4.Add(eCFieldElement7.Multiply(a)) : eCFieldElement4.Subtract(eCFieldElement7.Multiply(eCFieldElement3)));
                    }
                    eCFieldElement5 = Four(rawXCoord.Multiply(eCFieldElement2));
                }
                ECFieldElement eCFieldElement8 = eCFieldElement4.Square().Subtract(Two(eCFieldElement5));
                ECFieldElement y = eCFieldElement5.Subtract(eCFieldElement8).Multiply(eCFieldElement4).Subtract(Eight(x));
                ECFieldElement eCFieldElement9 = Two(rawYCoord);
                if (!isOne)
                {
                    eCFieldElement9 = eCFieldElement9.Multiply(eCFieldElement);
                }
                return(new FpPoint(curve, eCFieldElement8, y, new ECFieldElement[1] {
                        eCFieldElement9
                    }, base.IsCompressed));
            }

            case 4:
                return(TwiceJacobianModified(calculateW: true));

            default:
                throw new InvalidOperationException("unsupported coordinate system");
            }
        }
Exemplo n.º 35
0
 public override ECFieldElement SquareMinusProduct(ECFieldElement x, ECFieldElement y)
 {
     BigInteger ax = this.x, xx = x.ToBigInteger(), yx = y.ToBigInteger();
     BigInteger aa = ax.Multiply(ax);
     BigInteger xy = xx.Multiply(yx);
     return new FpFieldElement(q, r, ModReduce(aa.Subtract(xy)));
 }
 public override ECFieldElement Subtract(ECFieldElement b)
 {
     return new FPFieldElement(_q, _x.Subtract(b.ToBigInteger()).Mod(_q));
 }
Exemplo n.º 37
0
 public override ECFieldElement Add(
     ECFieldElement b)
 {
     return(new FpFieldElement(q, r, ModAdd(x, b.ToBigInteger())));
 }
 public override ECFieldElement Multiply(ECFieldElement b)
 {
     return new FPFieldElement(_q, _x.Multiply(b.ToBigInteger()).Mod(_q));
 }
Exemplo n.º 39
0
 public override ECFieldElement Multiply(
     ECFieldElement b)
 {
     return(new FpFieldElement(q, r, ModMult(x, b.ToBigInteger())));
 }
Exemplo n.º 40
0
		public override ECFieldElement Subtract(
			ECFieldElement b)
		{
			return new FpFieldElement(q, x.Subtract(b.ToBigInteger()).Mod(q));
		}
Exemplo n.º 41
0
 public override ECFieldElement Divide(
     ECFieldElement b)
 {
     return(new FpFieldElement(q, r, ModMult(x, ModInverse(b.ToBigInteger()))));
 }
Exemplo n.º 42
0
 public override ECFieldElement Multiply(ECFieldElement b) =>
 new FpFieldElement(this.q, this.r, this.ModMult(this.x, b.ToBigInteger()));