public static boolean areOnSameCurve(ECDomainParameters a, ECDomainParameters b) { return a != null && a.equals(b); }
public MQVPublicParameters( ECPublicKeyParameters staticPublicKey, ECPublicKeyParameters ephemeralPublicKey) { if (staticPublicKey == null) { throw new NullPointerException("staticPublicKey cannot be null"); } if (ephemeralPublicKey == null) { throw new NullPointerException("ephemeralPublicKey cannot be null"); } if (!staticPublicKey.getParameters().equals(ephemeralPublicKey.getParameters())) { throw new IllegalArgumentException("Static and ephemeral public keys have different domain parameters"); } this.staticPublicKey = staticPublicKey; this.ephemeralPublicKey = ephemeralPublicKey; }
public SM2KeyExchangePublicParameters( ECPublicKeyParameters staticPublicKey, ECPublicKeyParameters ephemeralPublicKey) { if (staticPublicKey == null) { throw new NullPointerException("staticPublicKey cannot be null"); } if (ephemeralPublicKey == null) { throw new NullPointerException("ephemeralPublicKey cannot be null"); } if (!staticPublicKey.getParameters().equals(ephemeralPublicKey.getParameters())) { throw new IllegalArgumentException("Static and ephemeral public keys have different domain parameters"); } this.staticPublicKey = staticPublicKey; this.ephemeralPublicKey = ephemeralPublicKey; }
public byte[] calculateAgreement( CipherParameters pubKey) { ECPublicKeyParameters pub = (ECPublicKeyParameters)pubKey; ECDomainParameters params = pub.getParameters(); if (!params.equals(key.getParameters())) { throw new IllegalStateException("ECVKO public key has wrong domain parameters"); } BigInteger hd = params.getH().multiply(ukm).multiply(key.getD()).mod(params.getN()); ECPoint P = pub.getQ().multiply(hd).normalize(); if (P.isInfinity()) { throw new IllegalStateException("Infinity is not a valid agreement value for ECVKO"); } return fromPoint(P.normalize()); }
public BigInteger calculateAgreement( CipherParameters pubKey) { ECPublicKeyParameters pub = (ECPublicKeyParameters)pubKey; ECDomainParameters params = pub.getParameters(); if (!params.equals(key.getParameters())) { throw new IllegalStateException("ECDHC public key has wrong domain parameters"); } BigInteger hd = params.getH().multiply(key.getD()).mod(params.getN()); ECPoint P = pub.getQ().multiply(hd).normalize(); if (P.isInfinity()) { throw new IllegalStateException("Infinity is not a valid agreement value for ECDHC"); } return P.getAffineXCoord().toBigInteger(); } }
public BigInteger calculateAgreement( CipherParameters pubKey) { ECPublicKeyParameters pub = (ECPublicKeyParameters)pubKey; if (!pub.getParameters().equals(key.getParameters())) { throw new IllegalStateException("ECDH public key has wrong domain parameters"); } ECPoint P = pub.getQ().multiply(key.getD()).normalize(); if (P.isInfinity()) { throw new IllegalStateException("Infinity is not a valid agreement value for ECDH"); } return P.getAffineXCoord().toBigInteger(); } }
public SM2KeyExchangePrivateParameters( boolean initiator, ECPrivateKeyParameters staticPrivateKey, ECPrivateKeyParameters ephemeralPrivateKey) { if (staticPrivateKey == null) { throw new NullPointerException("staticPrivateKey cannot be null"); } if (ephemeralPrivateKey == null) { throw new NullPointerException("ephemeralPrivateKey cannot be null"); } ECDomainParameters parameters = staticPrivateKey.getParameters(); if (!parameters.equals(ephemeralPrivateKey.getParameters())) { throw new IllegalArgumentException("Static and ephemeral private keys have different domain parameters"); } this.initiator = initiator; this.staticPrivateKey = staticPrivateKey; this.staticPublicPoint = parameters.getG().multiply(staticPrivateKey.getD()).normalize(); this.ephemeralPrivateKey = ephemeralPrivateKey; this.ephemeralPublicPoint = parameters.getG().multiply(ephemeralPrivateKey.getD()).normalize(); }
public BigInteger calculateAgreement(CipherParameters pubKey) { if (Properties.isOverrideSet("org.spongycastle.ec.disable_mqv")) { throw new IllegalStateException("ECMQV explicitly disabled"); } MQVPublicParameters pubParams = (MQVPublicParameters)pubKey; ECPrivateKeyParameters staticPrivateKey = privParams.getStaticPrivateKey(); ECDomainParameters parameters = staticPrivateKey.getParameters(); if (!parameters.equals(pubParams.getStaticPublicKey().getParameters())) { throw new IllegalStateException("ECMQV public key components have wrong domain parameters"); } ECPoint agreement = calculateMqvAgreement(parameters, staticPrivateKey, privParams.getEphemeralPrivateKey(), privParams.getEphemeralPublicKey(), pubParams.getStaticPublicKey(), pubParams.getEphemeralPublicKey()).normalize(); if (agreement.isInfinity()) { throw new IllegalStateException("Infinity is not a valid agreement value for MQV"); } return agreement.getAffineXCoord().toBigInteger(); }