package org.bouncycastle.crypto.digests;

/* JADX INFO: loaded from: E:\ios\vf_dex\classes4.dex */
public class Prehash implements org.bouncycastle.crypto.Digest {
    private final java.lang.String a;
    private final org.bouncycastle.util.io.LimitedBuffer b;

    @Override // org.bouncycastle.crypto.Digest
    public int doFinal(byte[] bArr, int i) {
        try {
            if (getDigestSize() != this.b.e()) {
                throw new java.lang.IllegalStateException("Incorrect prehash size");
            }
            int iA = this.b.a(bArr, i);
            reset();
            return iA;
        } catch (java.lang.Throwable th) {
            reset();
            throw th;
        }
    }

    @Override // org.bouncycastle.crypto.Digest
    public java.lang.String getAlgorithmName() {
        return this.a;
    }

    @Override // org.bouncycastle.crypto.Digest
    public int getDigestSize() {
        return this.b.d();
    }

    @Override // org.bouncycastle.crypto.Digest
    public void reset() {
        this.b.reset();
    }

    @Override // org.bouncycastle.crypto.Digest
    public void update(byte b) {
        this.b.write(b);
    }

    @Override // org.bouncycastle.crypto.Digest
    public void update(byte[] bArr, int i, int i2) {
        this.b.write(bArr, i, i2);
    }
}
