当前位置: 首页>>代码示例>>C#>>正文


C# ECPoint.Add方法代码示例

本文整理汇总了C#中Org.BouncyCastle.Math.EC.ECPoint.Add方法的典型用法代码示例。如果您正苦于以下问题:C# ECPoint.Add方法的具体用法?C# ECPoint.Add怎么用?C# ECPoint.Add使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Org.BouncyCastle.Math.EC.ECPoint的用法示例。


在下文中一共展示了ECPoint.Add方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ImplShamirsTrick

        private static ECPoint ImplShamirsTrick(ECPoint p, IBigInteger k, ECPoint q, IBigInteger l)
        {
            var m = System.Math.Max(k.BitLength, l.BitLength);
            var z = p.Add(q);
            var r = p.Curve.Infinity;

            for (var i = m - 1; i >= 0; --i)
            {
                r = r.Twice();

                if (k.TestBit(i))
                {
                    r = r.Add(l.TestBit(i) ? z : p);
                }
                else
                {
                    if (l.TestBit(i))
                    {
                        r = r.Add(q);
                    }
                }
            }

            return r;
        }
开发者ID:sanyaade-iot,项目名称:Schmoose-BouncyCastle,代码行数:25,代码来源:ECAlgorithms.cs

示例2: ImplShamirsTrick

		private static ECPoint ImplShamirsTrick(ECPoint P, BigInteger k,
			ECPoint Q, BigInteger l)
		{
			int m = System.Math.Max(k.BitLength, l.BitLength);
			ECPoint Z = P.Add(Q);
			ECPoint R = P.Curve.Infinity;

			for (int i = m - 1; i >= 0; --i)
			{
				R = R.Twice();

				if (k.TestBit(i))
				{
					if (l.TestBit(i))
					{
						R = R.Add(Z);
					}
					else
					{
						R = R.Add(P);
					}
				}
				else
				{
					if (l.TestBit(i))
					{
						R = R.Add(Q);
					}
				}
			}

			return R;
		}
开发者ID:nicecai,项目名称:iTextSharp-4.1.6,代码行数:33,代码来源:ECAlgorithms.cs

示例3: ImplTestAddSubtract

 /**
  * 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());
 }
开发者ID:jesusgarza,项目名称:bc-csharp,代码行数:20,代码来源:ECPointTest.cs

示例4: ImplTestAdd

 /**
  * Tests <code>ECPoint.add()</code> against literature values.
  *
  * @param p
  *            The array of literature values.
  * @param infinity
  *            The point at infinity on the respective curve.
  */
 private void ImplTestAdd(ECPoint[] p, ECPoint infinity)
 {
     AssertPointsEqual("p0 plus p1 does not equal p2", p[2], p[0].Add(p[1]));
     AssertPointsEqual("p1 plus p0 does not equal p2", p[2], p[1].Add(p[0]));
     for (int i = 0; i < p.Length; i++)
     {
         AssertPointsEqual("Adding infinity failed", p[i], p[i].Add(infinity));
         AssertPointsEqual("Adding to infinity failed", p[i], infinity.Add(p[i]));
     }
 }
开发者ID:jesusgarza,项目名称:bc-csharp,代码行数:18,代码来源:ECPointTest.cs

示例5: ImplShamirsTrickJsf

        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;
        }
开发者ID:MBrekhof,项目名称:pleiobox-clients,代码行数:35,代码来源:ECAlgorithms.cs

示例6: implTestAddSubtract

		/**
		 * 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 ");
		}
开发者ID:randombit,项目名称:hacrypto,代码行数:18,代码来源:ECPointTest.cs

示例7: Add

        public override ECPoint Add(ECPoint b)
        {
            if (this.IsInfinity)
                return b;
            if (b.IsInfinity)
                return this;

            ECCurve curve = this.Curve;
            int coord = curve.CoordinateSystem;

            ECFieldElement X1 = this.RawXCoord;
            ECFieldElement X2 = b.RawXCoord;

            switch (coord)
            {
                case ECCurve.COORD_AFFINE:
                {
                    ECFieldElement Y1 = this.RawYCoord;
                    ECFieldElement Y2 = b.RawYCoord;

                    ECFieldElement dx = X1.Add(X2), dy = Y1.Add(Y2);
                    if (dx.IsZero)
                    {
                        if (dy.IsZero)
                        {
                            return Twice();
                        }

                        return curve.Infinity;
                    }

                    ECFieldElement L = dy.Divide(dx);

                    ECFieldElement X3 = L.Square().Add(L).Add(dx).Add(curve.A);
                    ECFieldElement Y3 = L.Multiply(X1.Add(X3)).Add(X3).Add(Y1);

                    return new F2mPoint(curve, X3, Y3, IsCompressed);
                }
                case ECCurve.COORD_HOMOGENEOUS:
                {
                    ECFieldElement Y1 = this.RawYCoord, Z1 = this.RawZCoords[0];
                    ECFieldElement Y2 = b.RawYCoord, Z2 = b.RawZCoords[0];

                    bool Z1IsOne = Z1.IsOne;
                    ECFieldElement U1 = Y2, V1 = X2;
                    if (!Z1IsOne)
                    {
                        U1 = U1.Multiply(Z1);
                        V1 = V1.Multiply(Z1);
                    }

                    bool Z2IsOne = Z2.IsOne;
                    ECFieldElement U2 = Y1, V2 = X1;
                    if (!Z2IsOne)
                    {
                        U2 = U2.Multiply(Z2);
                        V2 = V2.Multiply(Z2);
                    }

                    ECFieldElement U = U1.Add(U2);
                    ECFieldElement V = V1.Add(V2);

                    if (V.IsZero)
                    {
                        if (U.IsZero)
                        {
                            return Twice();
                        }

                        return curve.Infinity;
                    }

                    ECFieldElement VSq = V.Square();
                    ECFieldElement VCu = VSq.Multiply(V);
                    ECFieldElement W = Z1IsOne ? Z2 : Z2IsOne ? Z1 : Z1.Multiply(Z2);
                    ECFieldElement uv = U.Add(V);
                    ECFieldElement A = uv.MultiplyPlusProduct(U, VSq, curve.A).Multiply(W).Add(VCu);

                    ECFieldElement X3 = V.Multiply(A);
                    ECFieldElement VSqZ2 = Z2IsOne ? VSq : VSq.Multiply(Z2);
                    ECFieldElement Y3 = U.MultiplyPlusProduct(X1, V, Y1).MultiplyPlusProduct(VSqZ2, uv, A);
                    ECFieldElement Z3 = VCu.Multiply(W);

                    return new F2mPoint(curve, X3, Y3, new ECFieldElement[] { Z3 }, IsCompressed);
                }
                case ECCurve.COORD_LAMBDA_PROJECTIVE:
                {
                    if (X1.IsZero)
                    {
                        if (X2.IsZero)
                            return curve.Infinity;

                        return b.Add(this);
                    }

                    ECFieldElement L1 = this.RawYCoord, Z1 = this.RawZCoords[0];
                    ECFieldElement L2 = b.RawYCoord, Z2 = b.RawZCoords[0];

                    bool Z1IsOne = Z1.IsOne;
                    ECFieldElement U2 = X2, S2 = L2;
//.........这里部分代码省略.........
开发者ID:ubberkid,项目名称:PeerATT,代码行数:101,代码来源:ECPoint.cs


注:本文中的Org.BouncyCastle.Math.EC.ECPoint.Add方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。