Subtract() 공개 추상적인 메소드

public abstract Subtract ( ECPoint b ) : ECPoint
b ECPoint
리턴 ECPoint
예제 #1
0
        internal static ECPoint ImplShamirsTrickJsf(ECPoint P, BigInteger k, ECPoint Q, BigInteger l)
        {
            ECCurve curve    = P.Curve;
            ECPoint infinity = curve.Infinity;
            ECPoint eCPoint  = P.Add(Q);
            ECPoint eCPoint2 = P.Subtract(Q);

            ECPoint[] array = new ECPoint[]
            {
                Q,
                eCPoint2,
                P,
                eCPoint
            };
            curve.NormalizeAll(array);
            ECPoint[] array2 = new ECPoint[]
            {
                array[3].Negate(),
                array[2].Negate(),
                array[1].Negate(),
                array[0].Negate(),
                infinity,
                array[0],
                array[1],
                array[2],
                array[3]
            };
            byte[]  array3   = WNafUtilities.GenerateJsf(k, l);
            ECPoint eCPoint3 = infinity;
            int     num      = array3.Length;

            while (--num >= 0)
            {
                int num2 = (int)array3[num];
                int num3 = num2 << 24 >> 28;
                int num4 = num2 << 28 >> 28;
                int num5 = 4 + num3 * 3 + num4;
                eCPoint3 = eCPoint3.TwicePlus(array2[num5]);
            }
            return(eCPoint3);
        }
예제 #2
0
        // D.3.2 pg 101
        public override ECPoint Multiply(
            BigInteger b)
        {
            if (this.IsInfinity)
            {
                return(this);
            }

            if (b.SignValue == 0)
            {
                return(this.curve.Infinity);
            }

            // BigInteger e = k.mod(n); // n == order this
            BigInteger e = b;

            BigInteger h = e.Multiply(BigInteger.ValueOf(3));

            ECPoint R = this;

            for (int i = h.BitLength - 2; i > 0; i--)
            {
                R = R.Twice();

                if (h.TestBit(i) && !e.TestBit(i))
                {
                    //System.out.print("+");
                    R = R.Add(this);
                }
                else if (!h.TestBit(i) && e.TestBit(i))
                {
                    //System.out.print("-");
                    R = R.Subtract(this);
                }
                // else
                // System.out.print(".");
            }
            // System.out.println();

            return(R);
        }
예제 #3
0
        internal static ECPoint ImplShamirsTrickJsf(ECPoint P, BigInteger k, ECPoint Q, BigInteger l)
        {
            ECCurve curve    = P.Curve;
            ECPoint infinity = curve.Infinity;

            // TODO conjugate co-Z addition (ZADDC) can return both of these
            ECPoint PaddQ = P.Add(Q);
            ECPoint PsubQ = P.Subtract(Q);

            ECPoint[] points = new ECPoint[] { Q, PsubQ, P, PaddQ };
            curve.NormalizeAll(points);

            ECPoint[] table = new ECPoint[] {
                points[3].Negate(), points[2].Negate(), points[1].Negate(),
                points[0].Negate(), infinity, points[0],
                points[1], points[2], points[3]
            };

            byte[] jsf = WNafUtilities.GenerateJsf(k, l);

            ECPoint R = infinity;

            int i = jsf.Length;

            while (--i >= 0)
            {
                int jsfi = jsf[i];

                // NOTE: The shifting ensures the sign is extended correctly
                int kDigit = ((jsfi << 24) >> 28), lDigit = ((jsfi << 28) >> 28);

                int index = 4 + (kDigit * 3) + lDigit;
                R = R.TwicePlus(table[index]);
            }

            return(R);
        }
예제 #4
0
        internal static ECPoint ImplShamirsTrickJsf(ECPoint P, BigInteger k, ECPoint Q, BigInteger l)
        {
            ECCurve curve    = P.Curve;
            ECPoint infinity = curve.Infinity;
            ECPoint point2   = P.Add(Q);
            ECPoint point3   = P.Subtract(Q);

            ECPoint[] points = new ECPoint[] { Q, point3, P, point2 };
            curve.NormalizeAll(points);
            ECPoint[] pointArray2 = new ECPoint[] { points[3].Negate(), points[2].Negate(), points[1].Negate(), points[0].Negate(), infinity, points[0], points[1], points[2], points[3] };
            byte[]    buffer      = WNafUtilities.GenerateJsf(k, l);
            ECPoint   point4      = infinity;
            int       length      = buffer.Length;

            while (--length >= 0)
            {
                int num2  = buffer[length];
                int num3  = (num2 << 0x18) >> 0x1c;
                int num4  = (num2 << 0x1c) >> 0x1c;
                int index = (4 + (num3 * 3)) + num4;
                point4 = point4.TwicePlus(pointArray2[index]);
            }
            return(point4);
        }
예제 #5
0
 /**
  * Tests <code>ECPoint.add()</code> and <code>ECPoint.subtract()</code>
  * for the given point and the given point at infinity.
  *
  * @param p
  *            The point on which the tests are performed.
  * @param infinity
  *            The point at infinity on the same curve as <code>p</code>.
  */
 private void ImplTestAddSubtract(ECPoint p, ECPoint infinity)
 {
     AssertPointsEqual("Twice and Add inconsistent", p.Twice(), p.Add(p));
     AssertPointsEqual("Twice p - p is not p", p, p.Twice().Subtract(p));
     AssertPointsEqual("TwicePlus(p, -p) is not p", p, p.TwicePlus(p.Negate()));
     AssertPointsEqual("p - p is not infinity", infinity, p.Subtract(p));
     AssertPointsEqual("p plus infinity is not p", p, p.Add(infinity));
     AssertPointsEqual("infinity plus p is not p", p, infinity.Add(p));
     AssertPointsEqual("infinity plus infinity is not infinity ", infinity, infinity.Add(infinity));
     AssertPointsEqual("Twice infinity is not infinity ", infinity, infinity.Twice());
 }
예제 #6
0
        internal static ECPoint ImplShamirsTrickJsf(ECPoint P, BigInteger k, ECPoint Q, BigInteger l)
        {
            ECCurve curve = P.Curve;
            ECPoint infinity = curve.Infinity;

            // TODO conjugate co-Z addition (ZADDC) can return both of these
            ECPoint PaddQ = P.Add(Q);
            ECPoint PsubQ = P.Subtract(Q);

            ECPoint[] points = new ECPoint[] { Q, PsubQ, P, PaddQ };
            curve.NormalizeAll(points);

            ECPoint[] table = new ECPoint[] {
            points[3].Negate(), points[2].Negate(), points[1].Negate(),
            points[0].Negate(), infinity, points[0],
            points[1], points[2], points[3] };

            byte[] jsf = WNafUtilities.GenerateJsf(k, l);

            ECPoint R = infinity;

            int i = jsf.Length;
            while (--i >= 0)
            {
                int jsfi = jsf[i];

                // NOTE: The shifting ensures the sign is extended correctly
                int kDigit = ((jsfi << 24) >> 28), lDigit = ((jsfi << 28) >> 28);

                int index = 4 + (kDigit * 3) + lDigit;
                R = R.TwicePlus(table[index]);
            }

            return R;
        }
예제 #7
0
		/**
		 * Tests <code>ECPoint.add()</code> and <code>ECPoint.subtract()</code>
		 * for the given point and the given point at infinity.
		 *
		 * @param p
		 *            The point on which the tests are performed.
		 * @param infinity
		 *            The point at infinity on the same curve as <code>p</code>.
		 */
		private void implTestAddSubtract(ECPoint p, ECPoint infinity)
		{
			Assert.AreEqual(p.Twice(), p.Add(p), "Twice and Add inconsistent");
			Assert.AreEqual(p, p.Twice().Subtract(p), "Twice p - p is not p");
			Assert.AreEqual(infinity, p.Subtract(p), "p - p is not infinity");
			Assert.AreEqual(p, p.Add(infinity), "p plus infinity is not p");
			Assert.AreEqual(p, infinity.Add(p), "infinity plus p is not p");
			Assert.AreEqual(infinity, infinity.Add(infinity), "infinity plus infinity is not infinity ");
		}