package org.bouncycastle.crypto.agreement;

/* JADX INFO: loaded from: E:\ios\vf_dex\classes4.dex */
public class ECVKOAgreement {
    private final org.bouncycastle.crypto.Digest a;
    private org.bouncycastle.crypto.params.ECPrivateKeyParameters b;
    private java.math.BigInteger c;

    public ECVKOAgreement(org.bouncycastle.crypto.Digest digest) {
        this.a = digest;
    }

    public byte[] 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.b.g();
        if (!eCDomainParametersG.equals(eCPublicKeyParameters.g())) {
            throw new java.lang.IllegalStateException("ECVKO public key has wrong domain parameters");
        }
        java.math.BigInteger bigIntegerMod = eCDomainParametersG.c().multiply(this.c).multiply(this.b.h()).mod(eCDomainParametersG.e());
        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 ECVKO");
        }
        org.bouncycastle.math.ec.ECPoint eCPointA2 = eCPointA.y(bigIntegerMod).A();
        if (eCPointA2.u()) {
            throw new java.lang.IllegalStateException("Infinity is not a valid agreement value for ECVKO");
        }
        byte[] bArrL = eCPointA2.l(false);
        int length = bArrL.length;
        int i = length / 2;
        int i2 = i * 2;
        int i3 = length - i2;
        org.bouncycastle.util.Arrays.g0(bArrL, i3, i);
        org.bouncycastle.util.Arrays.g0(bArrL, length - i, i);
        byte[] bArr = new byte[this.a.getDigestSize()];
        this.a.update(bArrL, i3, i2);
        this.a.doFinal(bArr, 0);
        return bArr;
    }

    public void b(org.bouncycastle.crypto.CipherParameters cipherParameters) {
        org.bouncycastle.crypto.params.ParametersWithUKM parametersWithUKM = (org.bouncycastle.crypto.params.ParametersWithUKM) cipherParameters;
        this.b = (org.bouncycastle.crypto.params.ECPrivateKeyParameters) parametersWithUKM.a();
        this.c = new java.math.BigInteger(1, org.bouncycastle.util.Arrays.f0(parametersWithUKM.b()));
        org.bouncycastle.crypto.CryptoServicesRegistrar.a(org.bouncycastle.crypto.agreement.Utils.b("ECVKO", this.b));
    }
}
