package org.bouncycastle.crypto.engines;

/* JADX INFO: loaded from: E:\ios\vf_dex\classes4.dex */
abstract class AEADBaseEngine implements org.bouncycastle.crypto.modes.AEADCipher {
    protected boolean a;
    protected java.lang.String b;
    protected int c;
    protected int d;
    protected int e;
    protected byte[] f;
    protected byte[] g;

    protected abstract void a(byte[] bArr, byte[] bArr2);

    @Override // org.bouncycastle.crypto.modes.AEADCipher
    public byte[] b() {
        return this.g;
    }

    protected void e(boolean z) {
        if (z) {
            this.g = null;
        }
    }

    @Override // org.bouncycastle.crypto.modes.AEADCipher
    public java.lang.String getAlgorithmName() {
        return this.b;
    }

    @Override // org.bouncycastle.crypto.modes.AEADCipher
    public void init(boolean z, org.bouncycastle.crypto.CipherParameters cipherParameters) {
        org.bouncycastle.crypto.params.KeyParameter keyParameterB;
        byte[] bArrA;
        this.a = z;
        if (cipherParameters instanceof org.bouncycastle.crypto.params.AEADParameters) {
            org.bouncycastle.crypto.params.AEADParameters aEADParameters = (org.bouncycastle.crypto.params.AEADParameters) cipherParameters;
            keyParameterB = aEADParameters.b();
            bArrA = aEADParameters.d();
            this.f = aEADParameters.a();
            int iC = aEADParameters.c();
            if (iC != this.e * 8) {
                throw new java.lang.IllegalArgumentException("Invalid value for MAC size: " + iC);
            }
        } else {
            if (!(cipherParameters instanceof org.bouncycastle.crypto.params.ParametersWithIV)) {
                throw new java.lang.IllegalArgumentException("invalid parameters passed to " + this.b);
            }
            org.bouncycastle.crypto.params.ParametersWithIV parametersWithIV = (org.bouncycastle.crypto.params.ParametersWithIV) cipherParameters;
            keyParameterB = (org.bouncycastle.crypto.params.KeyParameter) parametersWithIV.b();
            bArrA = parametersWithIV.a();
            this.f = null;
        }
        if (keyParameterB == null) {
            throw new java.lang.IllegalArgumentException(this.b + " Init parameters must include a key");
        }
        if (bArrA == null || bArrA.length != this.d) {
            throw new java.lang.IllegalArgumentException(this.b + " requires exactly " + this.d + " bytes of IV");
        }
        byte[] bArrB = keyParameterB.b();
        if (bArrB.length != this.c) {
            throw new java.lang.IllegalArgumentException(this.b + " key must be " + this.c + " bytes long");
        }
        org.bouncycastle.crypto.CryptoServicesRegistrar.a(new org.bouncycastle.crypto.constraints.DefaultServiceProperties(getAlgorithmName(), 128, cipherParameters, org.bouncycastle.crypto.engines.Utils.a(z)));
        a(bArrB, bArrA);
        byte[] bArr = this.f;
        if (bArr != null) {
            c(bArr, 0, bArr.length);
        }
    }

    @Override // org.bouncycastle.crypto.modes.AEADCipher
    public int processByte(byte b, byte[] bArr, int i) {
        return processBytes(new byte[]{b}, 0, 1, bArr, i);
    }

    @Override // org.bouncycastle.crypto.modes.AEADCipher
    public void reset() {
        e(true);
    }
}
