package org.bouncycastle.crypto.macs;

/* JADX INFO: loaded from: E:\ios\vf_dex\classes4.dex */
public class KGMac implements org.bouncycastle.crypto.Mac {
    private final org.bouncycastle.crypto.modes.KGCMBlockCipher a;
    private final int b;

    public KGMac(org.bouncycastle.crypto.modes.KGCMBlockCipher kGCMBlockCipher, int i) {
        this.a = kGCMBlockCipher;
        this.b = i;
    }

    @Override // org.bouncycastle.crypto.Mac
    public int doFinal(byte[] bArr, int i) {
        try {
            return this.a.doFinal(bArr, i);
        } catch (org.bouncycastle.crypto.InvalidCipherTextException e) {
            throw new java.lang.IllegalStateException(e.toString());
        }
    }

    @Override // org.bouncycastle.crypto.Mac
    public java.lang.String getAlgorithmName() {
        return this.a.getUnderlyingCipher().getAlgorithmName() + "-KGMAC";
    }

    @Override // org.bouncycastle.crypto.Mac
    public int getMacSize() {
        return this.b / 8;
    }

    @Override // org.bouncycastle.crypto.Mac
    public void init(org.bouncycastle.crypto.CipherParameters cipherParameters) throws java.io.IOException {
        if (!(cipherParameters instanceof org.bouncycastle.crypto.params.ParametersWithIV)) {
            throw new java.lang.IllegalArgumentException("KGMAC requires ParametersWithIV");
        }
        org.bouncycastle.crypto.params.ParametersWithIV parametersWithIV = (org.bouncycastle.crypto.params.ParametersWithIV) cipherParameters;
        byte[] bArrA = parametersWithIV.a();
        this.a.init(true, new org.bouncycastle.crypto.params.AEADParameters((org.bouncycastle.crypto.params.KeyParameter) parametersWithIV.b(), this.b, bArrA));
    }

    @Override // org.bouncycastle.crypto.Mac
    public void reset() throws java.io.IOException {
        this.a.reset();
    }

    @Override // org.bouncycastle.crypto.Mac
    public void update(byte b) throws java.io.IOException {
        this.a.d(b);
    }

    @Override // org.bouncycastle.crypto.Mac
    public void update(byte[] bArr, int i, int i2) throws java.io.IOException {
        this.a.c(bArr, i, i2);
    }
}
