Example #1
0
        public virtual ECPoint ValidatePoint(BigInteger x, BigInteger y, bool withCompression)
        {
            ECPoint p = CreatePoint(x, y, withCompression);

            if (!p.IsValid())
            {
                throw new ArgumentException("Invalid point coordinates");
            }
            return(p);
        }
Example #2
0
        public virtual ECPoint ValidatePoint(BigInteger x, BigInteger y)
        {
            ECPoint point = this.CreatePoint(x, y);

            if (!point.IsValid())
            {
                throw new ArgumentException("Invalid point coordinates");
            }
            return(point);
        }
Example #3
0
        public virtual ECPoint ValidatePoint(BigInteger x, BigInteger y, bool withCompression)
        {
            //IL_0017: Unknown result type (might be due to invalid IL or missing references)
            ECPoint eCPoint = CreatePoint(x, y, withCompression);

            if (!eCPoint.IsValid())
            {
                throw new ArgumentException("Invalid point coordinates");
            }
            return(eCPoint);
        }
Example #4
0
        /// <summary>
        /// Hashes a seed t into a point T on the curve. Returns null if t is unsuitable.
        /// </summary>
        /// <param name="curve">The elliptic curve in Weierstrass form</param>
        /// <param name="t">The seed</param>
        /// <returns>A random point T uniquely determined by seed t, otherwise null</returns>
        public static ECPoint?HashToWeierstrassCurve(ECCurve curve, byte[] t)
        {
            ECFieldElement x, ax, x3, y, y2;

            BigInteger P      = curve.Field.Characteristic;
            SHA256?    sha256 = SHA256.Create();
            BigInteger hash   = new BigInteger(sha256.ComputeHash(t));

            // Check that the hash is within valid range
            if (hash.CompareTo(BigInteger.One) < 0 || hash.CompareTo(P) >= 0)
            {
                return(null);
            }

            // A valid point (x,y) must satisfy: y^2 = x^3 + Ax + B mod P
            // Convert hash from BigInt to FieldElement x modulo P
            x  = curve.FromBigInteger(hash);        // x
            ax = x.Multiply(curve.A);               // Ax
            x3 = x.Square().Multiply(x);            // x^3 = x^2 * x
            y2 = x3.Add(ax).Add(curve.B);           // y^2 = x^3 + Ax + B
            y  = y2.Sqrt();                         // y = sqrt(x^3 + Ax + B)

            // y == null if square root mod P does not exist
            if (y == null)
            {
                return(null);
            }

            ECPoint T = curve.CreatePoint(x.ToBigInteger(), y.ToBigInteger());

            // Use the built-in point validator, which also checks for membership
            // in weak subgroups
            if (!T.IsValid())
            {
                return(null);
            }

            return(T);
        }
Example #5
0
        public static ECPoint ValidatePoint(ECPoint p)
        {
            if (!p.IsValid())
                throw new ArgumentException("Invalid point", "p");

            return p;
        }