package org.bouncycastle.crypto.digests;

/* JADX INFO: loaded from: E:\ios\vf_dex\classes4.dex */
public class ISAPDigest implements org.bouncycastle.crypto.Digest {
    private long a;
    private long b;
    private long c;
    private long d;
    private long e;
    private long f;
    private long g;
    private long h;
    private long i;
    private long j;
    private java.io.ByteArrayOutputStream k;

    private void a() {
        e(240L);
        e(225L);
        e(210L);
        e(195L);
        e(180L);
        e(165L);
        e(150L);
        e(135L);
        e(120L);
        e(105L);
        e(90L);
        e(75L);
    }

    private long d(long j, long j2) {
        return (j << ((int) (64 - j2))) | (j >>> ((int) j2));
    }

    private void e(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);
        this.f = j7;
        this.g = ((((j2 ^ j4) ^ j5) ^ j6) ^ j) ^ (((j3 ^ j4) ^ j) & (j3 ^ j5));
        this.h = (((j3 ^ j4) ^ j6) ^ j) ^ (j5 & j6);
        this.i = ((j4 ^ (j2 ^ j3)) ^ j) ^ ((~j2) & (j5 ^ j6));
        this.j = ((j2 ^ j6) & j3) ^ ((j3 ^ j5) ^ j6);
        this.a = (d(j7, 19L) ^ j7) ^ d(this.f, 28L);
        long j8 = this.g;
        this.b = (j8 ^ d(j8, 39L)) ^ d(this.g, 61L);
        long j9 = this.h;
        this.c = ~((j9 ^ d(j9, 1L)) ^ d(this.h, 6L));
        long j10 = this.i;
        this.d = (j10 ^ d(j10, 10L)) ^ d(this.i, 17L);
        long j11 = this.j;
        this.e = (j11 ^ d(j11, 7L)) ^ d(this.j, 41L);
    }

    @Override // org.bouncycastle.crypto.Digest
    public int doFinal(byte[] bArr, int i) {
        if (i + 32 > bArr.length) {
            throw new org.bouncycastle.crypto.OutputLengthException("output buffer is too short");
        }
        this.j = 0L;
        this.i = 0L;
        this.h = 0L;
        this.g = 0L;
        this.f = 0L;
        this.a = -1255492011513352131L;
        this.b = -8380609354527731710L;
        this.c = -5437372128236807582L;
        this.d = 4834782570098516968L;
        this.e = 3787428097924915520L;
        byte[] byteArray = this.k.toByteArray();
        int length = byteArray.length;
        int i2 = length >> 3;
        long[] jArr = new long[i2];
        int i3 = 0;
        org.bouncycastle.util.Pack.y(byteArray, 0, jArr, 0, i2);
        int i4 = 0;
        while (length >= 8) {
            this.a ^= f(jArr[i4]);
            a();
            length -= 8;
            i4++;
        }
        long j = this.a;
        int i5 = (7 - length) << 3;
        long j2 = 128;
        while (true) {
            this.a = j ^ (j2 << i5);
            if (length <= 0) {
                break;
            }
            j = this.a;
            length--;
            j2 = ((long) byteArray[(i4 << 3) + length]) & 255;
            i5 = (7 - length) << 3;
        }
        a();
        long[] jArr2 = new long[4];
        while (true) {
            long jF = f(this.a);
            if (i3 >= 3) {
                jArr2[i3] = jF;
                org.bouncycastle.util.Pack.K(jArr2, bArr, i);
                this.k.reset();
                return 32;
            }
            jArr2[i3] = jF;
            a();
            i3++;
        }
    }

    protected long f(long j) {
        return (d(j, 56L) & 1095216660735L) | (d(j, 8L) & (-72057589759737856L)) | (d(j, 24L) & 71776119077928960L) | (d(j, 40L) & 280375465148160L);
    }

    @Override // org.bouncycastle.crypto.Digest
    public java.lang.String getAlgorithmName() {
        return "ISAP Hash";
    }

    @Override // org.bouncycastle.crypto.Digest
    public int getDigestSize() {
        return 32;
    }

    @Override // org.bouncycastle.crypto.Digest
    public void reset() {
        this.k.reset();
    }

    @Override // org.bouncycastle.crypto.Digest
    public void update(byte b) {
        this.k.write(b);
    }

    @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");
        }
        this.k.write(bArr, i, i2);
    }
}
