what-the-bank/sources/org/bouncycastle/crypto/agreement/ECDHBasicAgreement.java

37 lines
1.5 KiB
Java

package org.bouncycastle.crypto.agreement;
import java.math.BigInteger;
import org.bouncycastle.crypto.BasicAgreement;
import org.bouncycastle.crypto.CipherParameters;
import org.bouncycastle.crypto.params.ECPrivateKeyParameters;
import org.bouncycastle.crypto.params.ECPublicKeyParameters;
import org.bouncycastle.math.ec.ECPoint;
/* loaded from: classes6.dex */
public class ECDHBasicAgreement implements BasicAgreement {
private ECPrivateKeyParameters key;
@Override // org.bouncycastle.crypto.BasicAgreement
public void init(CipherParameters cipherParameters) {
this.key = (ECPrivateKeyParameters) cipherParameters;
}
@Override // org.bouncycastle.crypto.BasicAgreement
public int getFieldSize() {
return (this.key.getParameters().getCurve().getFieldSize() + 7) / 8;
}
@Override // org.bouncycastle.crypto.BasicAgreement
public BigInteger calculateAgreement(CipherParameters cipherParameters) {
ECPublicKeyParameters eCPublicKeyParameters = (ECPublicKeyParameters) cipherParameters;
if (!eCPublicKeyParameters.getParameters().equals(this.key.getParameters())) {
throw new IllegalStateException("ECDH public key has wrong domain parameters");
}
ECPoint normalize = eCPublicKeyParameters.getQ().multiply(this.key.getD()).normalize();
if (normalize.isInfinity()) {
throw new IllegalStateException("Infinity is not a valid agreement value for ECDH");
}
return normalize.getAffineXCoord().toBigInteger();
}
}