public static void checkPointOnCurve(ECPoint point, EllipticCurve ec)
      throws GeneralSecurityException {
    BigInteger p = getModulus(ec);
    BigInteger x = point.getAffineX();
    BigInteger y = point.getAffineY();
    if (x == null || y == null) {
      throw new GeneralSecurityException("point is at infinity");
    }
    // Check 0 <= x < p and 0 <= y < p.
    if (x.signum() == -1 || x.compareTo(p) >= 0) {
      throw new GeneralSecurityException("x is out of range");
    }
    if (y.signum() == -1 || y.compareTo(p) >= 0) {
      throw new GeneralSecurityException("y is out of range");
    }
    // Check y^2 == x^3 + a x + b (mod p)
    BigInteger lhs = y.multiply(y).mod(p);
    BigInteger rhs = x.multiply(x).add(ec.getA()).multiply(x).add(ec.getB()).mod(p);
    if (!lhs.equals(rhs)) {
      throw new GeneralSecurityException("Point is not on curve");
    }
  }
Checks that a point is on a given elliptic curve.

<p>This method implements the partial public key validation routine from Section 5.6.2.6 of <a
href="http://nvlpubs.nist.gov/nistpubs/SpecialPublications/NIST.SP.800-56Ar2.pdf">NIST SP
800-56A</a>. A partial public key validation is sufficient for curves with cofactor 1. See
Section B.3 of http://www.nsa.gov/ia/_files/SuiteB_Implementer_G-113808.pdf.

<p>The point validations above are taken from recommendations for ECDH, because parameter
checks in ECDH are much more important than for the case of ECDSA. Performing this test for
ECDSA keys is mainly a sanity check.

@param point the point that needs verification
@param ec the elliptic curve. This must be a curve over a prime order field.
@throws GeneralSecurityException if the field is binary or if the point is not on the curve.
java_src/src/main/java/com/google/crypto/tink/internal/EllipticCurvesUtil.java