package org.bouncycastle.crypto.macs;

/* JADX INFO: loaded from: E:\ios\vf_dex\classes4.dex */
class MacCFBBlockCipher {
    private byte[] a;
    private byte[] b;
    private byte[] c;
    private int d;
    private org.bouncycastle.crypto.BlockCipher e;

    public MacCFBBlockCipher(org.bouncycastle.crypto.BlockCipher blockCipher, int i) {
        this.e = blockCipher;
        this.d = i / 8;
        this.a = new byte[blockCipher.b()];
        this.b = new byte[blockCipher.b()];
        this.c = new byte[blockCipher.b()];
    }

    public java.lang.String a() {
        return this.e.getAlgorithmName() + "/CFB" + (this.d * 8);
    }

    public int b() {
        return this.d;
    }

    void c(byte[] bArr) {
        this.e.c(this.b, 0, bArr, 0);
    }

    public void d(org.bouncycastle.crypto.CipherParameters cipherParameters) {
        org.bouncycastle.crypto.BlockCipher blockCipher;
        if (cipherParameters instanceof org.bouncycastle.crypto.params.ParametersWithIV) {
            org.bouncycastle.crypto.params.ParametersWithIV parametersWithIV = (org.bouncycastle.crypto.params.ParametersWithIV) cipherParameters;
            byte[] bArrA = parametersWithIV.a();
            int length = bArrA.length;
            byte[] bArr = this.a;
            if (length < bArr.length) {
                java.lang.System.arraycopy(bArrA, 0, bArr, bArr.length - bArrA.length, bArrA.length);
            } else {
                java.lang.System.arraycopy(bArrA, 0, bArr, 0, bArr.length);
            }
            f();
            blockCipher = this.e;
            cipherParameters = parametersWithIV.b();
        } else {
            f();
            blockCipher = this.e;
        }
        blockCipher.init(true, cipherParameters);
    }

    public int e(byte[] bArr, int i, byte[] bArr2, int i2) {
        int i3 = this.d;
        if (i + i3 > bArr.length) {
            throw new org.bouncycastle.crypto.DataLengthException("input buffer too short");
        }
        if (i3 + i2 > bArr2.length) {
            throw new org.bouncycastle.crypto.OutputLengthException("output buffer too short");
        }
        this.e.c(this.b, 0, this.c, 0);
        int i4 = 0;
        while (true) {
            int i5 = this.d;
            if (i4 >= i5) {
                byte[] bArr3 = this.b;
                java.lang.System.arraycopy(bArr3, i5, bArr3, 0, bArr3.length - i5);
                byte[] bArr4 = this.b;
                int length = bArr4.length;
                int i6 = this.d;
                java.lang.System.arraycopy(bArr2, i2, bArr4, length - i6, i6);
                return this.d;
            }
            bArr2[i2 + i4] = (byte) (this.c[i4] ^ bArr[i + i4]);
            i4++;
        }
    }

    public void f() {
        byte[] bArr = this.a;
        java.lang.System.arraycopy(bArr, 0, this.b, 0, bArr.length);
        this.e.reset();
    }
}
