package org.bouncycastle.crypto.agreement;

/* JADX INFO: loaded from: E:\ios\vf_dex\classes4.dex */
public class ECDHBasicAgreement implements org.bouncycastle.crypto.BasicAgreement {
    private org.bouncycastle.crypto.params.ECPrivateKeyParameters a;

    @Override // org.bouncycastle.crypto.BasicAgreement
    public java.math.BigInteger a(org.bouncycastle.crypto.CipherParameters cipherParameters) {
        org.bouncycastle.crypto.params.ECPublicKeyParameters eCPublicKeyParameters = (org.bouncycastle.crypto.params.ECPublicKeyParameters) cipherParameters;
        org.bouncycastle.crypto.params.ECDomainParameters eCDomainParametersG = this.a.g();
        if (!eCDomainParametersG.equals(eCPublicKeyParameters.g())) {
            throw new java.lang.IllegalStateException("ECDH public key has wrong domain parameters");
        }
        java.math.BigInteger bigIntegerH = this.a.h();
        org.bouncycastle.math.ec.ECPoint eCPointA = org.bouncycastle.math.ec.ECAlgorithms.a(eCDomainParametersG.a(), eCPublicKeyParameters.h());
        if (eCPointA.u()) {
            throw new java.lang.IllegalStateException("Infinity is not a valid public key for ECDH");
        }
        java.math.BigInteger bigIntegerC = eCDomainParametersG.c();
        if (!bigIntegerC.equals(org.bouncycastle.math.ec.ECConstants.b)) {
            bigIntegerH = eCDomainParametersG.d().multiply(bigIntegerH).mod(eCDomainParametersG.e());
            eCPointA = org.bouncycastle.math.ec.ECAlgorithms.q(eCPointA, bigIntegerC);
        }
        org.bouncycastle.math.ec.ECPoint eCPointA2 = eCPointA.y(bigIntegerH).A();
        if (eCPointA2.u()) {
            throw new java.lang.IllegalStateException("Infinity is not a valid agreement value for ECDH");
        }
        return eCPointA2.f().v();
    }

    @Override // org.bouncycastle.crypto.BasicAgreement
    public int getFieldSize() {
        return this.a.g().a().v();
    }

    @Override // org.bouncycastle.crypto.BasicAgreement
    public void init(org.bouncycastle.crypto.CipherParameters cipherParameters) {
        org.bouncycastle.crypto.params.ECPrivateKeyParameters eCPrivateKeyParameters = (org.bouncycastle.crypto.params.ECPrivateKeyParameters) cipherParameters;
        this.a = eCPrivateKeyParameters;
        org.bouncycastle.crypto.CryptoServicesRegistrar.a(org.bouncycastle.crypto.agreement.Utils.b("ECDH", eCPrivateKeyParameters));
    }
}
