package org.bouncycastle.crypto.macs;

/* JADX INFO: loaded from: E:\ios\vf_dex\classes4.dex */
public class BlockCipherMac implements org.bouncycastle.crypto.Mac {
    private byte[] a;
    private byte[] b;
    private int c;
    private org.bouncycastle.crypto.BlockCipher d;
    private int e;

    @Override // org.bouncycastle.crypto.Mac
    public int doFinal(byte[] bArr, int i) {
        int iB = this.d.b();
        while (true) {
            int i2 = this.c;
            if (i2 >= iB) {
                this.d.c(this.b, 0, this.a, 0);
                java.lang.System.arraycopy(this.a, 0, bArr, i, this.e);
                reset();
                return this.e;
            }
            this.b[i2] = 0;
            this.c = i2 + 1;
        }
    }

    @Override // org.bouncycastle.crypto.Mac
    public java.lang.String getAlgorithmName() {
        return this.d.getAlgorithmName();
    }

    @Override // org.bouncycastle.crypto.Mac
    public int getMacSize() {
        return this.e;
    }

    @Override // org.bouncycastle.crypto.Mac
    public void init(org.bouncycastle.crypto.CipherParameters cipherParameters) {
        reset();
        this.d.init(true, cipherParameters);
    }

    @Override // org.bouncycastle.crypto.Mac
    public void reset() {
        int i = 0;
        while (true) {
            byte[] bArr = this.b;
            if (i >= bArr.length) {
                this.c = 0;
                this.d.reset();
                return;
            } else {
                bArr[i] = 0;
                i++;
            }
        }
    }

    @Override // org.bouncycastle.crypto.Mac
    public void update(byte b) {
        int i = this.c;
        byte[] bArr = this.b;
        if (i == bArr.length) {
            this.d.c(bArr, 0, this.a, 0);
            this.c = 0;
        }
        byte[] bArr2 = this.b;
        int i2 = this.c;
        this.c = i2 + 1;
        bArr2[i2] = b;
    }

    @Override // org.bouncycastle.crypto.Mac
    public void update(byte[] bArr, int i, int i2) {
        if (i2 < 0) {
            throw new java.lang.IllegalArgumentException("Can't have a negative input length!");
        }
        int iB = this.d.b();
        int i3 = this.c;
        int i4 = iB - i3;
        if (i2 > i4) {
            java.lang.System.arraycopy(bArr, i, this.b, i3, i4);
            this.d.c(this.b, 0, this.a, 0);
            this.c = 0;
            i2 -= i4;
            i += i4;
            while (i2 > iB) {
                this.d.c(bArr, i, this.a, 0);
                i2 -= iB;
                i += iB;
            }
        }
        java.lang.System.arraycopy(bArr, i, this.b, this.c, i2);
        this.c += i2;
    }
}
