NBitcoin.BouncyCastle.Math.EC.ECCurve.NormalizeAll C# (CSharp) Method

NormalizeAll() public method

public NormalizeAll ( NBitcoin.BouncyCastle.Math.EC.ECPoint points, int off, int len, ECFieldElement iso ) : void
points NBitcoin.BouncyCastle.Math.EC.ECPoint
off int
len int
iso ECFieldElement
return void
		public virtual void NormalizeAll(ECPoint[] points, int off, int len, ECFieldElement iso)
		{
			CheckPoints(points, off, len);

			switch(this.CoordinateSystem)
			{
				case ECCurve.COORD_AFFINE:
				case ECCurve.COORD_LAMBDA_AFFINE:
					{
						if(iso != null)
							throw new ArgumentException("not valid for affine coordinates", "iso");

						return;
					}
			}

			/*
             * Figure out which of the points actually need to be normalized
             */
			ECFieldElement[] zs = new ECFieldElement[len];
			int[] indices = new int[len];
			int count = 0;
			for(int i = 0; i < len; ++i)
			{
				ECPoint p = points[off + i];
				if(null != p && (iso != null || !p.IsNormalized()))
				{
					zs[count] = p.GetZCoord(0);
					indices[count++] = off + i;
				}
			}

			if(count == 0)
			{
				return;
			}

			ECAlgorithms.MontgomeryTrick(zs, 0, count, iso);

			for(int j = 0; j < count; ++j)
			{
				int index = indices[j];
				points[index] = points[index].Normalize(zs[j]);
			}
		}

Same methods

ECCurve::NormalizeAll ( NBitcoin.BouncyCastle.Math.EC.ECPoint points ) : void

Usage Example

コード例 #1
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);

            var points = new ECPoint[] { Q, PsubQ, P, PaddQ };

            curve.NormalizeAll(points);

            var 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);
        }