package org.bouncycastle.crypto.digests;

/* JADX INFO: loaded from: E:\ios\vf_dex\classes4.dex */
abstract class AsconBaseDigest implements org.bouncycastle.crypto.ExtendedDigest {
    protected long a;
    protected long b;
    protected long c;
    protected long d;
    protected long e;
    protected int f;
    protected final byte[] g;
    protected int h;

    private void i(long j) {
        long j2 = this.a;
        long j3 = this.b;
        long j4 = this.c;
        long j5 = this.d;
        long j6 = this.e;
        long j7 = ((((j2 ^ j3) ^ j4) ^ j5) ^ j) ^ ((((j2 ^ j4) ^ j6) ^ j) & j3);
        long j8 = ((((j2 ^ j4) ^ j5) ^ j6) ^ j) ^ (((j3 ^ j4) ^ j) & (j3 ^ j5));
        long j9 = (((j3 ^ j4) ^ j6) ^ j) ^ (j5 & j6);
        long j10 = ((j4 ^ (j2 ^ j3)) ^ j) ^ ((~j2) & (j5 ^ j6));
        long j11 = ((j2 ^ j6) & j3) ^ ((j3 ^ j5) ^ j6);
        this.a = org.bouncycastle.util.Longs.c(j7, 28) ^ (org.bouncycastle.util.Longs.c(j7, 19) ^ j7);
        this.b = (org.bouncycastle.util.Longs.c(j8, 39) ^ j8) ^ org.bouncycastle.util.Longs.c(j8, 61);
        this.c = ~(org.bouncycastle.util.Longs.c(j9, 6) ^ (org.bouncycastle.util.Longs.c(j9, 1) ^ j9));
        this.d = (org.bouncycastle.util.Longs.c(j10, 10) ^ j10) ^ org.bouncycastle.util.Longs.c(j10, 17);
        this.e = org.bouncycastle.util.Longs.c(j11, 41) ^ (org.bouncycastle.util.Longs.c(j11, 7) ^ j11);
    }

    protected int a(byte[] bArr, int i, int i2) {
        if (i + 32 > bArr.length) {
            throw new org.bouncycastle.crypto.OutputLengthException("output buffer is too short");
        }
        h();
        l(bArr, i, i2);
        return i2;
    }

    protected abstract long d(byte[] bArr, int i);

    @Override // org.bouncycastle.crypto.Digest
    public int doFinal(byte[] bArr, int i) {
        return a(bArr, i, 32);
    }

    protected abstract long e(byte[] bArr, int i, int i2);

    protected void f(int i) {
        if (i == 12) {
            i(240L);
            i(225L);
            i(210L);
            i(195L);
        }
        if (i >= 8) {
            i(180L);
            i(165L);
        }
        i(150L);
        i(135L);
        i(120L);
        i(105L);
        i(90L);
        i(75L);
    }

    protected abstract long g(int i);

    @Override // org.bouncycastle.crypto.ExtendedDigest
    public int getByteLength() {
        return 8;
    }

    @Override // org.bouncycastle.crypto.Digest
    public int getDigestSize() {
        return 32;
    }

    protected void h() {
        long jE = this.a ^ e(this.g, 0, this.h);
        this.a = jE;
        this.a = jE ^ g(this.h);
        f(12);
    }

    protected abstract void j(long j, byte[] bArr, int i);

    protected abstract void k(long j, byte[] bArr, int i, int i2);

    protected void l(byte[] bArr, int i, int i2) {
        int i3 = i;
        int i4 = i2;
        while (i4 > 8) {
            j(this.a, bArr, i3);
            f(this.f);
            i3 += 8;
            i4 -= 8;
        }
        k(this.a, bArr, i3, i4);
        reset();
    }

    @Override // org.bouncycastle.crypto.Digest
    public void reset() {
        org.bouncycastle.util.Arrays.i(this.g);
        this.h = 0;
    }

    @Override // org.bouncycastle.crypto.Digest
    public void update(byte b) {
        byte[] bArr = this.g;
        int i = this.h;
        bArr[i] = b;
        int i2 = i + 1;
        this.h = i2;
        if (i2 == 8) {
            this.a ^= d(bArr, 0);
            f(this.f);
            this.h = 0;
        }
    }

    @Override // org.bouncycastle.crypto.Digest
    public void update(byte[] bArr, int i, int i2) {
        if (i + i2 > bArr.length) {
            throw new org.bouncycastle.crypto.DataLengthException("input buffer too short");
        }
        int i3 = this.h;
        int i4 = 8 - i3;
        if (i2 < i4) {
            java.lang.System.arraycopy(bArr, i, this.g, i3, i2);
            this.h += i2;
            return;
        }
        if (i3 > 0) {
            java.lang.System.arraycopy(bArr, i, this.g, i3, i4);
            this.a ^= d(this.g, 0);
            f(this.f);
        } else {
            i4 = 0;
        }
        while (true) {
            int i5 = i2 - i4;
            if (i5 < 8) {
                java.lang.System.arraycopy(bArr, i + i4, this.g, 0, i5);
                this.h = i5;
                return;
            } else {
                this.a ^= d(bArr, i + i4);
                f(this.f);
                i4 += 8;
            }
        }
    }
}
