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