Пример #1
0
        public virtual bool Equals(ECPoint other)
        {
            if (this == other)
            {
                return(true);
            }
            if (null == other)
            {
                return(false);
            }

            ECCurve c1 = this.Curve, c2 = other.Curve;
            bool    n1 = (null == c1), n2 = (null == c2);
            bool    i1 = IsInfinity, i2 = other.IsInfinity;

            if (i1 || i2)
            {
                return((i1 && i2) && (n1 || n2 || c1.Equals(c2)));
            }

            ECPoint p1 = this, p2 = other;

            if (n1 && n2)
            {
                // Points with null curve are in affine form, so already normalized
            }
            else if (n1)
            {
                p2 = p2.Normalize();
            }
            else if (n2)
            {
                p1 = p1.Normalize();
            }
            else if (!c1.Equals(c2))
            {
                return(false);
            }
            else
            {
                // TODO Consider just requiring already normalized, to avoid silent performance degradation

                ECPoint[] points = new ECPoint[] { this, c1.ImportPoint(p2) };

                // TODO This is a little strong, really only requires coZNormalizeAll to get Zs equal
                c1.NormalizeAll(points);

                p1 = points[0];
                p2 = points[1];
            }

            return(p1.XCoord.Equals(p2.XCoord) && p1.YCoord.Equals(p2.YCoord));
        }
Пример #2
0
		protected bool Equals(
			ECDomainParameters other)
		{
            return curve.Equals(other.curve)
                && g.Equals(other.g)
                && n.Equals(other.n)
                && h.Equals(other.h)
                && true; // TODO: FIXME Arrays.AreEqual(seed, other.seed);
		}
Пример #3
0
        public static ECPoint ImportPoint(ECCurve c, ECPoint p)
        {
            ECCurve cp = p.Curve;

            if (!c.Equals(cp))
            {
                throw new ArgumentException("Point must be on the same curve");
            }

            return(c.ImportPoint(p));
        }
Пример #4
0
        public static ECPoint SumOfTwoMultiplies(ECPoint P, BigInteger a,
                                                 ECPoint Q, BigInteger b)
        {
            ECCurve c = P.Curve;

            if (!c.Equals(Q.Curve))
            {
                throw new ArgumentException("P and Q must be on same curve");
            }

/*
 *          // Point multiplication for Koblitz curves (using WTNAF) beats Shamir's trick
 *                      if (c is F2mCurve)
 *                      {
 *                              F2mCurve f2mCurve = (F2mCurve) c;
 *                              if (f2mCurve.IsKoblitz)
 *                              {
 *                                      return P.Multiply(a).Add(Q.Multiply(b));
 *                              }
 *                      }
 */
            return(ImplShamirsTrick(P, a, Q, b));
        }