本文整理了Java中java.security.spec.ECPoint.equals()
方法的一些代码示例,展示了ECPoint.equals()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ECPoint.equals()
方法的具体详情如下:
包路径:java.security.spec.ECPoint
类名称:ECPoint
方法名:equals
[英]Returns whether the specified object and this elliptic curve point are equal.
[中]
代码示例来源:origin: robovm/robovm
/**
* Creates a new {@code ECPublicKey} with the specified public elliptic
* curve point and parameter specification.
*
* @param w
* the public elliptic curve point {@code W}.
* @param params
* the domain parameter specification.
* @throws IllegalArgumentException
* if the specified point {@code W} is at infinity.
*/
public ECPublicKeySpec(ECPoint w, ECParameterSpec params) {
this.w = w;
this.params = params;
// throw NullPointerException if w or params is null
if (this.w == null) {
throw new NullPointerException("w == null");
}
if (this.params == null) {
throw new NullPointerException("params == null");
}
// throw IllegalArgumentException if w is point at infinity
if (this.w.equals(ECPoint.POINT_INFINITY)) {
throw new IllegalArgumentException("the w parameter is point at infinity");
}
}
代码示例来源:origin: i2p/i2p.i2p
private static ECPoint doublePoint(ECPoint r, EllipticCurve curve) {
if (r.equals(ECPoint.POINT_INFINITY))
return r;
BigInteger slope = (r.getAffineX().pow(2)).multiply(THREE);
slope = slope.add(curve.getA());
BigInteger prime = ((ECFieldFp) curve.getField()).getP();
// use NBI modInverse();
BigInteger tmp = r.getAffineY().multiply(TWO);
tmp = new NativeBigInteger(tmp);
slope = slope.multiply(tmp.modInverse(prime));
BigInteger xOut = slope.pow(2).subtract(r.getAffineX().multiply(TWO)).mod(prime);
BigInteger yOut = (r.getAffineY().negate()).add(slope.multiply(r.getAffineX().subtract(xOut))).mod(prime);
ECPoint out = new ECPoint(xOut, yOut);
return out;
}
代码示例来源:origin: i2p/i2p.i2p
private static ECPoint addPoint(ECPoint r, ECPoint s, EllipticCurve curve) {
if (r.equals(s))
return doublePoint(r, curve);
else if (r.equals(ECPoint.POINT_INFINITY))
return s;
else if (s.equals(ECPoint.POINT_INFINITY))
return r;
BigInteger prime = ((ECFieldFp) curve.getField()).getP();
// use NBI modInverse();
BigInteger tmp = r.getAffineX().subtract(s.getAffineX());
tmp = new NativeBigInteger(tmp);
BigInteger slope = (r.getAffineY().subtract(s.getAffineY())).multiply(tmp.modInverse(prime)).mod(prime);
slope = new NativeBigInteger(slope);
BigInteger xOut = (slope.modPow(TWO, prime).subtract(r.getAffineX())).subtract(s.getAffineX()).mod(prime);
BigInteger yOut = s.getAffineY().negate().mod(prime);
yOut = yOut.add(slope.multiply(s.getAffineX().subtract(xOut))).mod(prime);
ECPoint out = new ECPoint(xOut, yOut);
return out;
}
代码示例来源:origin: com.mobidevelop.robovm/robovm-rt
/**
* Creates a new {@code ECPublicKey} with the specified public elliptic
* curve point and parameter specification.
*
* @param w
* the public elliptic curve point {@code W}.
* @param params
* the domain parameter specification.
* @throws IllegalArgumentException
* if the specified point {@code W} is at infinity.
*/
public ECPublicKeySpec(ECPoint w, ECParameterSpec params) {
this.w = w;
this.params = params;
// throw NullPointerException if w or params is null
if (this.w == null) {
throw new NullPointerException("w == null");
}
if (this.params == null) {
throw new NullPointerException("params == null");
}
// throw IllegalArgumentException if w is point at infinity
if (this.w.equals(ECPoint.POINT_INFINITY)) {
throw new IllegalArgumentException("the w parameter is point at infinity");
}
}
代码示例来源:origin: ibinti/bugvm
/**
* Creates a new {@code ECPublicKey} with the specified public elliptic
* curve point and parameter specification.
*
* @param w
* the public elliptic curve point {@code W}.
* @param params
* the domain parameter specification.
* @throws IllegalArgumentException
* if the specified point {@code W} is at infinity.
*/
public ECPublicKeySpec(ECPoint w, ECParameterSpec params) {
this.w = w;
this.params = params;
// throw NullPointerException if w or params is null
if (this.w == null) {
throw new NullPointerException("w == null");
}
if (this.params == null) {
throw new NullPointerException("params == null");
}
// throw IllegalArgumentException if w is point at infinity
if (this.w.equals(ECPoint.POINT_INFINITY)) {
throw new IllegalArgumentException("the w parameter is point at infinity");
}
}
代码示例来源:origin: MobiVM/robovm
/**
* Creates a new {@code ECPublicKey} with the specified public elliptic
* curve point and parameter specification.
*
* @param w
* the public elliptic curve point {@code W}.
* @param params
* the domain parameter specification.
* @throws IllegalArgumentException
* if the specified point {@code W} is at infinity.
*/
public ECPublicKeySpec(ECPoint w, ECParameterSpec params) {
this.w = w;
this.params = params;
// throw NullPointerException if w or params is null
if (this.w == null) {
throw new NullPointerException("w == null");
}
if (this.params == null) {
throw new NullPointerException("params == null");
}
// throw IllegalArgumentException if w is point at infinity
if (this.w.equals(ECPoint.POINT_INFINITY)) {
throw new IllegalArgumentException("the w parameter is point at infinity");
}
}
代码示例来源:origin: com.bugvm/bugvm-rt
/**
* Creates a new {@code ECPublicKey} with the specified public elliptic
* curve point and parameter specification.
*
* @param w
* the public elliptic curve point {@code W}.
* @param params
* the domain parameter specification.
* @throws IllegalArgumentException
* if the specified point {@code W} is at infinity.
*/
public ECPublicKeySpec(ECPoint w, ECParameterSpec params) {
this.w = w;
this.params = params;
// throw NullPointerException if w or params is null
if (this.w == null) {
throw new NullPointerException("w == null");
}
if (this.params == null) {
throw new NullPointerException("params == null");
}
// throw IllegalArgumentException if w is point at infinity
if (this.w.equals(ECPoint.POINT_INFINITY)) {
throw new IllegalArgumentException("the w parameter is point at infinity");
}
}
代码示例来源:origin: com.gluonhq/robovm-rt
/**
* Creates a new {@code ECPublicKey} with the specified public elliptic
* curve point and parameter specification.
*
* @param w
* the public elliptic curve point {@code W}.
* @param params
* the domain parameter specification.
* @throws IllegalArgumentException
* if the specified point {@code W} is at infinity.
*/
public ECPublicKeySpec(ECPoint w, ECParameterSpec params) {
this.w = w;
this.params = params;
// throw NullPointerException if w or params is null
if (this.w == null) {
throw new NullPointerException("w == null");
}
if (this.params == null) {
throw new NullPointerException("params == null");
}
// throw IllegalArgumentException if w is point at infinity
if (this.w.equals(ECPoint.POINT_INFINITY)) {
throw new IllegalArgumentException("the w parameter is point at infinity");
}
}
代码示例来源:origin: org.xbib/jsch-core
public boolean validate(byte[] r, byte[] s) throws Exception {
BigInteger x = new BigInteger(1, r);
BigInteger y = new BigInteger(1, s);
ECPoint w = new ECPoint(x, y);
if (w.equals(ECPoint.POINT_INFINITY)) {
return false;
}
ECParameterSpec params = publicKey.getParams();
EllipticCurve curve = params.getCurve();
BigInteger p = ((ECFieldFp) curve.getField()).getP();
BigInteger p_sub1 = p.subtract(BigInteger.ONE);
if (!(x.compareTo(p_sub1) <= 0 && y.compareTo(p_sub1) <= 0)) {
return false;
}
BigInteger tmp = x.multiply(curve.getA()).
add(curve.getB()).
add(x.modPow(three, p)).
mod(p);
BigInteger y_2 = y.modPow(two, p);
return y_2.equals(tmp);
}
代码示例来源:origin: com.google.crypto.tink/tink
/** Checks that the public key's params spec is the same as the private key's params spec. */
static void validatePublicKeySpec(ECPublicKey publicKey, ECPrivateKey privateKey)
throws GeneralSecurityException {
try {
ECParameterSpec publicKeySpec = publicKey.getParams();
ECParameterSpec privateKeySpec = privateKey.getParams();
if (!publicKeySpec.getCurve().equals(privateKeySpec.getCurve())
|| !publicKeySpec.getGenerator().equals(privateKeySpec.getGenerator())
|| !publicKeySpec.getOrder().equals(privateKeySpec.getOrder())
|| publicKeySpec.getCofactor() != privateKeySpec.getCofactor()) {
throw new GeneralSecurityException("invalid public key spec");
}
} catch (IllegalArgumentException | NullPointerException ex) {
// The Java security providers on Android K and Android L might throw these unchecked
// exceptions, converting them to a checked one to not crash the JVM.
throw new GeneralSecurityException(ex.toString());
}
}
代码示例来源:origin: ibinti/bugvm
@Override
public boolean equals(Object o) {
if (o == this) {
return true;
}
if (o instanceof OpenSSLECPrivateKey) {
OpenSSLECPrivateKey other = (OpenSSLECPrivateKey) o;
return key.equals(other.key);
}
if (!(o instanceof ECPublicKey)) {
return false;
}
final ECPublicKey other = (ECPublicKey) o;
if (!getPublicKey().equals(other.getW())) {
return false;
}
final ECParameterSpec spec = getParams();
final ECParameterSpec otherSpec = other.getParams();
return spec.getCurve().equals(otherSpec.getCurve())
&& spec.getGenerator().equals(otherSpec.getGenerator())
&& spec.getOrder().equals(otherSpec.getOrder())
&& spec.getCofactor() == otherSpec.getCofactor();
}
代码示例来源:origin: org.conscrypt/conscrypt-openjdk-uber
@Override
public boolean equals(Object o) {
if (o == this) {
return true;
}
if (o instanceof OpenSSLECPublicKey) {
OpenSSLECPublicKey other = (OpenSSLECPublicKey) o;
return key.equals(other.key);
}
if (!(o instanceof ECPublicKey)) {
return false;
}
final ECPublicKey other = (ECPublicKey) o;
if (!getPublicKey().equals(other.getW())) {
return false;
}
final ECParameterSpec spec = getParams();
final ECParameterSpec otherSpec = other.getParams();
return spec.getCurve().equals(otherSpec.getCurve())
&& spec.getGenerator().equals(otherSpec.getGenerator())
&& spec.getOrder().equals(otherSpec.getOrder())
&& spec.getCofactor() == otherSpec.getCofactor();
}
代码示例来源:origin: com.bugvm/bugvm-rt
@Override
public boolean equals(Object o) {
if (o == this) {
return true;
}
if (o instanceof OpenSSLECPrivateKey) {
OpenSSLECPrivateKey other = (OpenSSLECPrivateKey) o;
return key.equals(other.key);
}
if (!(o instanceof ECPublicKey)) {
return false;
}
final ECPublicKey other = (ECPublicKey) o;
if (!getPublicKey().equals(other.getW())) {
return false;
}
final ECParameterSpec spec = getParams();
final ECParameterSpec otherSpec = other.getParams();
return spec.getCurve().equals(otherSpec.getCurve())
&& spec.getGenerator().equals(otherSpec.getGenerator())
&& spec.getOrder().equals(otherSpec.getOrder())
&& spec.getCofactor() == otherSpec.getCofactor();
}
代码示例来源:origin: org.conscrypt/conscrypt-openjdk
@Override
public boolean equals(Object o) {
if (o == this) {
return true;
}
if (o instanceof OpenSSLECPublicKey) {
OpenSSLECPublicKey other = (OpenSSLECPublicKey) o;
return key.equals(other.key);
}
if (!(o instanceof ECPublicKey)) {
return false;
}
final ECPublicKey other = (ECPublicKey) o;
if (!getPublicKey().equals(other.getW())) {
return false;
}
final ECParameterSpec spec = getParams();
final ECParameterSpec otherSpec = other.getParams();
return spec.getCurve().equals(otherSpec.getCurve())
&& spec.getGenerator().equals(otherSpec.getGenerator())
&& spec.getOrder().equals(otherSpec.getOrder())
&& spec.getCofactor() == otherSpec.getCofactor();
}
代码示例来源:origin: org.conscrypt/conscrypt-openjdk
@Override
public boolean equals(Object o) {
if (o == this) {
return true;
}
if (o instanceof OpenSSLECPrivateKey) {
OpenSSLECPrivateKey other = (OpenSSLECPrivateKey) o;
return key.equals(other.key);
}
if (!(o instanceof ECPrivateKey)) {
return false;
}
final ECPrivateKey other = (ECPrivateKey) o;
if (!getPrivateKey().equals(other.getS())) {
return false;
}
final ECParameterSpec spec = getParams();
final ECParameterSpec otherSpec = other.getParams();
return spec.getCurve().equals(otherSpec.getCurve())
&& spec.getGenerator().equals(otherSpec.getGenerator())
&& spec.getOrder().equals(otherSpec.getOrder())
&& spec.getCofactor() == otherSpec.getCofactor();
}
代码示例来源:origin: ibinti/bugvm
@Override
public boolean equals(Object o) {
if (o == this) {
return true;
}
if (o instanceof OpenSSLECPrivateKey) {
OpenSSLECPrivateKey other = (OpenSSLECPrivateKey) o;
return key.equals(other.key);
}
if (!(o instanceof ECPrivateKey)) {
return false;
}
final ECPrivateKey other = (ECPrivateKey) o;
if (!getPrivateKey().equals(other.getS())) {
return false;
}
final ECParameterSpec spec = getParams();
final ECParameterSpec otherSpec = other.getParams();
return spec.getCurve().equals(otherSpec.getCurve())
&& spec.getGenerator().equals(otherSpec.getGenerator())
&& spec.getOrder().equals(otherSpec.getOrder())
&& spec.getCofactor() == otherSpec.getCofactor();
}
代码示例来源:origin: org.apache.santuario/xmlsec
private static boolean matchCurve(ECParameterSpec params, Curve curve) {
int fieldSize = params.getCurve().getField().getFieldSize();
if (curve.getCurve().getField().getFieldSize() == fieldSize
&& curve.getCurve().equals(params.getCurve())
&& curve.getGenerator().equals(params.getGenerator())
&& curve.getOrder().equals(params.getOrder())
&& curve.getCofactor() == params.getCofactor()) {
return true;
} else {
return false;
}
}
代码示例来源:origin: org.conscrypt/conscrypt-openjdk-uber
@Override
public boolean equals(Object o) {
if (o == this) {
return true;
}
if (o instanceof OpenSSLECPrivateKey) {
OpenSSLECPrivateKey other = (OpenSSLECPrivateKey) o;
return key.equals(other.key);
}
if (!(o instanceof ECPrivateKey)) {
return false;
}
final ECPrivateKey other = (ECPrivateKey) o;
if (!getPrivateKey().equals(other.getS())) {
return false;
}
final ECParameterSpec spec = getParams();
final ECParameterSpec otherSpec = other.getParams();
return spec.getCurve().equals(otherSpec.getCurve())
&& spec.getGenerator().equals(otherSpec.getGenerator())
&& spec.getOrder().equals(otherSpec.getOrder())
&& spec.getCofactor() == otherSpec.getCofactor();
}
代码示例来源:origin: com.bugvm/bugvm-rt
@Override
public boolean equals(Object o) {
if (o == this) {
return true;
}
if (o instanceof OpenSSLECPrivateKey) {
OpenSSLECPrivateKey other = (OpenSSLECPrivateKey) o;
return key.equals(other.key);
}
if (!(o instanceof ECPrivateKey)) {
return false;
}
final ECPrivateKey other = (ECPrivateKey) o;
if (!getPrivateKey().equals(other.getS())) {
return false;
}
final ECParameterSpec spec = getParams();
final ECParameterSpec otherSpec = other.getParams();
return spec.getCurve().equals(otherSpec.getCurve())
&& spec.getGenerator().equals(otherSpec.getGenerator())
&& spec.getOrder().equals(otherSpec.getOrder())
&& spec.getCofactor() == otherSpec.getCofactor();
}
代码示例来源:origin: com.nimbusds/nimbus-jose-jwt
private static void validateEcCurves(ECPublicKey publicKey, ECPrivateKey privateKey) throws JOSEException {
final ECParameterSpec pubParams = publicKey.getParams();
final ECParameterSpec privParams = privateKey.getParams();
if (!pubParams.getCurve().equals(privParams.getCurve())) {
throw new JOSEException("Public/private EC key curve mismatch: " + publicKey);
}
if (pubParams.getCofactor() != privParams.getCofactor()) {
throw new JOSEException("Public/private EC key cofactor mismatch: " + publicKey);
}
if (!pubParams.getGenerator().equals(privParams.getGenerator())) {
throw new JOSEException("Public/private EC key generator mismatch: " + publicKey);
}
if (!pubParams.getOrder().equals(privParams.getOrder())) {
throw new JOSEException("Public/private EC key order mismatch: " + publicKey);
}
}
内容来源于网络,如有侵权,请联系作者删除!