@Test public void testPointOnCurve() throws Exception { for (int i = 0; i < testVectors1.length; i++) { ECPoint pubPoint = new ECPoint( new BigInteger(testVectors1[i].pubX, 16), new BigInteger(testVectors1[i].pubY, 16)); try { EllipticCurves.checkPointOnCurve(pubPoint, testVectors1[i].getCurve()); } catch (GeneralSecurityException ex) { fail("The valid public point is not on the curve: " + ex.getMessage()); } } }
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"); } 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"); } 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"); } }
EllipticCurves { 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"); } 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"); } 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"); } } }
EllipticCurves { 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"); } 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"); } 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"); } }  }
EllipticCurves { 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"); } 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"); } 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"); } }  static ECParameterSpec getNistP256Params(); static ECParameterSpec getNistP384Params(); static ECParameterSpec getNistP521Params(); static boolean isNistEcParameterSpec(ECParameterSpec spec); static boolean isSameEcParameterSpec(ECParameterSpec one, ECParameterSpec two); static void validatePublicKey(ECPublicKey publicKey, ECPrivateKey privateKey); static BigInteger getModulus(EllipticCurve curve); static int fieldSizeInBytes(EllipticCurve curve); static BigInteger getY(BigInteger x, boolean lsb, EllipticCurve curve); static byte[] ecdsaIeee2Der(byte[] ieee); static byte[] ecdsaDer2Ieee(byte[] der, int ieeeLength); static boolean isValidDerEncoding(final byte[] sig); static int encodingSizeInBytes(EllipticCurve curve, PointFormatType format); @Deprecated static ECPoint ecPointDecode(EllipticCurve curve, PointFormatType format, byte[] encoded); static ECPoint pointDecode(CurveType curveType, PointFormatType format, byte[] encoded); static ECPoint pointDecode(EllipticCurve curve, PointFormatType format, byte[] encoded); static byte[] pointEncode(CurveType curveType, PointFormatType format, ECPoint point); static byte[] pointEncode(EllipticCurve curve, PointFormatType format, ECPoint point); static ECParameterSpec getCurveSpec(CurveType curve); static ECPublicKey getEcPublicKey(final byte[] x509PublicKey); static ECPublicKey getEcPublicKey(
      CurveType curve, PointFormatType pointFormat, final byte[] publicKey); static ECPublicKey getEcPublicKey(
      ECParameterSpec spec, PointFormatType pointFormat, final byte[] publicKey); static ECPublicKey getEcPublicKey(CurveType curve, final byte[] x, final byte[] y); static ECPrivateKey getEcPrivateKey(final byte[] pkcs8PrivateKey); static ECPrivateKey getEcPrivateKey(CurveType curve, final byte[] keyValue); static KeyPair generateKeyPair(CurveType curve); static KeyPair generateKeyPair(ECParameterSpec spec); static byte[] computeSharedSecret(ECPrivateKey myPrivateKey, ECPublicKey peerPublicKey); static byte[] computeSharedSecret(ECPrivateKey myPrivateKey, ECPoint publicPoint); }
EllipticCurves { 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"); } 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"); } 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"); } }  static ECParameterSpec getNistP256Params(); static ECParameterSpec getNistP384Params(); static ECParameterSpec getNistP521Params(); static boolean isNistEcParameterSpec(ECParameterSpec spec); static boolean isSameEcParameterSpec(ECParameterSpec one, ECParameterSpec two); static void validatePublicKey(ECPublicKey publicKey, ECPrivateKey privateKey); static BigInteger getModulus(EllipticCurve curve); static int fieldSizeInBytes(EllipticCurve curve); static BigInteger getY(BigInteger x, boolean lsb, EllipticCurve curve); static byte[] ecdsaIeee2Der(byte[] ieee); static byte[] ecdsaDer2Ieee(byte[] der, int ieeeLength); static boolean isValidDerEncoding(final byte[] sig); static int encodingSizeInBytes(EllipticCurve curve, PointFormatType format); @Deprecated static ECPoint ecPointDecode(EllipticCurve curve, PointFormatType format, byte[] encoded); static ECPoint pointDecode(CurveType curveType, PointFormatType format, byte[] encoded); static ECPoint pointDecode(EllipticCurve curve, PointFormatType format, byte[] encoded); static byte[] pointEncode(CurveType curveType, PointFormatType format, ECPoint point); static byte[] pointEncode(EllipticCurve curve, PointFormatType format, ECPoint point); static ECParameterSpec getCurveSpec(CurveType curve); static ECPublicKey getEcPublicKey(final byte[] x509PublicKey); static ECPublicKey getEcPublicKey(
      CurveType curve, PointFormatType pointFormat, final byte[] publicKey); static ECPublicKey getEcPublicKey(
      ECParameterSpec spec, PointFormatType pointFormat, final byte[] publicKey); static ECPublicKey getEcPublicKey(CurveType curve, final byte[] x, final byte[] y); static ECPrivateKey getEcPrivateKey(final byte[] pkcs8PrivateKey); static ECPrivateKey getEcPrivateKey(CurveType curve, final byte[] keyValue); static KeyPair generateKeyPair(CurveType curve); static KeyPair generateKeyPair(ECParameterSpec spec); static byte[] computeSharedSecret(ECPrivateKey myPrivateKey, ECPublicKey peerPublicKey); static byte[] computeSharedSecret(ECPrivateKey myPrivateKey, ECPoint publicPoint);  }