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

39 lines
1.7 KiB
Java
Raw Permalink Normal View History

2024-07-27 18:17:47 +07:00
package org.bouncycastle.crypto.agreement;
import java.math.BigInteger;
import org.bouncycastle.crypto.BasicAgreement;
import org.bouncycastle.crypto.CipherParameters;
import org.bouncycastle.crypto.params.ECDomainParameters;
import org.bouncycastle.crypto.params.ECPrivateKeyParameters;
import org.bouncycastle.crypto.params.ECPublicKeyParameters;
import org.bouncycastle.math.ec.ECPoint;
/* loaded from: classes6.dex */
public class ECDHCBasicAgreement implements BasicAgreement {
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;
ECDomainParameters parameters = eCPublicKeyParameters.getParameters();
if (!parameters.equals(this.key.getParameters())) {
throw new IllegalStateException("ECDHC public key has wrong domain parameters");
}
ECPoint normalize = eCPublicKeyParameters.getQ().multiply(parameters.getH().multiply(this.key.getD()).mod(parameters.getN())).normalize();
if (normalize.isInfinity()) {
throw new IllegalStateException("Infinity is not a valid agreement value for ECDHC");
}
return normalize.getAffineXCoord().toBigInteger();
}
}