package org.bouncycastle.crypto.digests;

/* JADX INFO: loaded from: E:\ios\vf_dex\classes4.dex */
public class TupleHash implements org.bouncycastle.crypto.Xof, org.bouncycastle.crypto.Digest {
    private static final byte[] e = org.bouncycastle.util.Strings.f("TupleHash");
    private final org.bouncycastle.crypto.digests.CSHAKEDigest a;
    private final int b;
    private final int c;
    private boolean d;

    public TupleHash(int i, byte[] bArr, int i2) {
        this.a = new org.bouncycastle.crypto.digests.CSHAKEDigest(i, e, bArr);
        this.b = i;
        this.c = (i2 + 7) / 8;
        reset();
    }

    private void a(int i) {
        byte[] bArrD = org.bouncycastle.crypto.digests.XofUtils.d(((long) i) * 8);
        this.a.update(bArrD, 0, bArrD.length);
        this.d = false;
    }

    @Override // org.bouncycastle.crypto.Xof
    public int b(byte[] bArr, int i, int i2) {
        if (this.d) {
            a(getDigestSize());
        }
        int iB = this.a.b(bArr, i, i2);
        reset();
        return iB;
    }

    @Override // org.bouncycastle.crypto.Xof
    public int c(byte[] bArr, int i, int i2) {
        if (this.d) {
            a(0);
        }
        return this.a.c(bArr, i, i2);
    }

    @Override // org.bouncycastle.crypto.Digest
    public int doFinal(byte[] bArr, int i) {
        if (this.d) {
            a(getDigestSize());
        }
        int iB = this.a.b(bArr, i, getDigestSize());
        reset();
        return iB;
    }

    @Override // org.bouncycastle.crypto.Digest
    public java.lang.String getAlgorithmName() {
        return "TupleHash" + this.a.getAlgorithmName().substring(6);
    }

    @Override // org.bouncycastle.crypto.ExtendedDigest
    public int getByteLength() {
        return this.a.getByteLength();
    }

    @Override // org.bouncycastle.crypto.Digest
    public int getDigestSize() {
        return this.c;
    }

    @Override // org.bouncycastle.crypto.Digest
    public void reset() {
        this.a.reset();
        this.d = true;
    }

    @Override // org.bouncycastle.crypto.Digest
    public void update(byte b) {
        byte[] bArrA = org.bouncycastle.crypto.digests.XofUtils.a(b);
        this.a.update(bArrA, 0, bArrA.length);
    }

    public TupleHash(org.bouncycastle.crypto.digests.TupleHash tupleHash) {
        org.bouncycastle.crypto.digests.CSHAKEDigest cSHAKEDigest = new org.bouncycastle.crypto.digests.CSHAKEDigest(tupleHash.a);
        this.a = cSHAKEDigest;
        int i = cSHAKEDigest.f;
        this.b = i;
        this.c = (i * 2) / 8;
        this.d = tupleHash.d;
    }

    @Override // org.bouncycastle.crypto.Digest
    public void update(byte[] bArr, int i, int i2) {
        byte[] bArrB = org.bouncycastle.crypto.digests.XofUtils.b(bArr, i, i2);
        this.a.update(bArrB, 0, bArrB.length);
    }
}
