private static void validateSharedSecret(byte[] secret, ECPrivateKey privateKey)
      throws GeneralSecurityException {
    EllipticCurve privateKeyCurve = privateKey.getParams().getCurve();
    BigInteger x = new BigInteger(1, secret);
    if (x.signum() == -1 || x.compareTo(getModulus(privateKeyCurve)) >= 0) {
      throw new GeneralSecurityException("shared secret is out of range");
    }
    // This will throw if x is not a valid coordinate.
    Object unused = getY(x, true /* lsb, doesn't matter here */, privateKeyCurve);
  }
Checks that the shared secret is on the curve of the private key, to prevent arithmetic errors
or fault attacks.
java_src/src/main/java/com/google/crypto/tink/subtle/EllipticCurves.java