package org.bouncycastle.crypto.digests;

/* JADX INFO: loaded from: E:\ios\vf_dex\classes4.dex */
public class MD4Digest extends org.bouncycastle.crypto.digests.GeneralDigest {
    private int e;
    private int f;
    private int g;
    private int h;
    private int[] i;
    private int j;

    public MD4Digest() {
        this(org.bouncycastle.crypto.CryptoServicePurpose.ANY);
    }

    private int j(int i, int i2, int i3) {
        return (i & i2) | ((~i) & i3);
    }

    private int k(int i, int i2, int i3) {
        return ((i2 | i3) & i) | (i2 & i3);
    }

    private int l(int i, int i2, int i3) {
        return (i ^ i2) ^ i3;
    }

    private void m(org.bouncycastle.crypto.digests.MD4Digest mD4Digest) {
        super.e(mD4Digest);
        this.e = mD4Digest.e;
        this.f = mD4Digest.f;
        this.g = mD4Digest.g;
        this.h = mD4Digest.h;
        int[] iArr = mD4Digest.i;
        java.lang.System.arraycopy(iArr, 0, this.i, 0, iArr.length);
        this.j = mD4Digest.j;
    }

    private int n(int i, int i2) {
        return (i << i2) | (i >>> (32 - i2));
    }

    public org.bouncycastle.util.Memoable a() {
        return new org.bouncycastle.crypto.digests.MD4Digest(this);
    }

    public void d(org.bouncycastle.util.Memoable memoable) {
        m((org.bouncycastle.crypto.digests.MD4Digest) memoable);
    }

    @Override // org.bouncycastle.crypto.Digest
    public int doFinal(byte[] bArr, int i) {
        f();
        org.bouncycastle.util.Pack.l(this.e, bArr, i);
        org.bouncycastle.util.Pack.l(this.f, bArr, i + 4);
        org.bouncycastle.util.Pack.l(this.g, bArr, i + 8);
        org.bouncycastle.util.Pack.l(this.h, bArr, i + 12);
        reset();
        return 16;
    }

    @Override // org.bouncycastle.crypto.digests.GeneralDigest
    protected void g() {
        int i = this.e;
        int i2 = this.f;
        int i3 = this.g;
        int i4 = this.h;
        int iN = n(i + j(i2, i3, i4) + this.i[0], 3);
        int iN2 = n(i4 + j(iN, i2, i3) + this.i[1], 7);
        int iN3 = n(i3 + j(iN2, iN, i2) + this.i[2], 11);
        int iN4 = n(i2 + j(iN3, iN2, iN) + this.i[3], 19);
        int iN5 = n(iN + j(iN4, iN3, iN2) + this.i[4], 3);
        int iN6 = n(iN2 + j(iN5, iN4, iN3) + this.i[5], 7);
        int iN7 = n(iN3 + j(iN6, iN5, iN4) + this.i[6], 11);
        int iN8 = n(iN4 + j(iN7, iN6, iN5) + this.i[7], 19);
        int iN9 = n(iN5 + j(iN8, iN7, iN6) + this.i[8], 3);
        int iN10 = n(iN6 + j(iN9, iN8, iN7) + this.i[9], 7);
        int iN11 = n(iN7 + j(iN10, iN9, iN8) + this.i[10], 11);
        int iN12 = n(iN8 + j(iN11, iN10, iN9) + this.i[11], 19);
        int iN13 = n(iN9 + j(iN12, iN11, iN10) + this.i[12], 3);
        int iN14 = n(iN10 + j(iN13, iN12, iN11) + this.i[13], 7);
        int iN15 = n(iN11 + j(iN14, iN13, iN12) + this.i[14], 11);
        int iN16 = n(iN12 + j(iN15, iN14, iN13) + this.i[15], 19);
        int iN17 = n(iN13 + k(iN16, iN15, iN14) + this.i[0] + 1518500249, 3);
        int iN18 = n(iN14 + k(iN17, iN16, iN15) + this.i[4] + 1518500249, 5);
        int iN19 = n(iN15 + k(iN18, iN17, iN16) + this.i[8] + 1518500249, 9);
        int iN20 = n(iN16 + k(iN19, iN18, iN17) + this.i[12] + 1518500249, 13);
        int iN21 = n(iN17 + k(iN20, iN19, iN18) + this.i[1] + 1518500249, 3);
        int iN22 = n(iN18 + k(iN21, iN20, iN19) + this.i[5] + 1518500249, 5);
        int iN23 = n(iN19 + k(iN22, iN21, iN20) + this.i[9] + 1518500249, 9);
        int iN24 = n(iN20 + k(iN23, iN22, iN21) + this.i[13] + 1518500249, 13);
        int iN25 = n(iN21 + k(iN24, iN23, iN22) + this.i[2] + 1518500249, 3);
        int iN26 = n(iN22 + k(iN25, iN24, iN23) + this.i[6] + 1518500249, 5);
        int iN27 = n(iN23 + k(iN26, iN25, iN24) + this.i[10] + 1518500249, 9);
        int iN28 = n(iN24 + k(iN27, iN26, iN25) + this.i[14] + 1518500249, 13);
        int iN29 = n(iN25 + k(iN28, iN27, iN26) + this.i[3] + 1518500249, 3);
        int iN30 = n(iN26 + k(iN29, iN28, iN27) + this.i[7] + 1518500249, 5);
        int iN31 = n(iN27 + k(iN30, iN29, iN28) + this.i[11] + 1518500249, 9);
        int iN32 = n(iN28 + k(iN31, iN30, iN29) + this.i[15] + 1518500249, 13);
        int iN33 = n(iN29 + l(iN32, iN31, iN30) + this.i[0] + 1859775393, 3);
        int iN34 = n(iN30 + l(iN33, iN32, iN31) + this.i[8] + 1859775393, 9);
        int iN35 = n(iN31 + l(iN34, iN33, iN32) + this.i[4] + 1859775393, 11);
        int iN36 = n(iN32 + l(iN35, iN34, iN33) + this.i[12] + 1859775393, 15);
        int iN37 = n(iN33 + l(iN36, iN35, iN34) + this.i[2] + 1859775393, 3);
        int iN38 = n(iN34 + l(iN37, iN36, iN35) + this.i[10] + 1859775393, 9);
        int iN39 = n(iN35 + l(iN38, iN37, iN36) + this.i[6] + 1859775393, 11);
        int iN40 = n(iN36 + l(iN39, iN38, iN37) + this.i[14] + 1859775393, 15);
        int iN41 = n(iN37 + l(iN40, iN39, iN38) + this.i[1] + 1859775393, 3);
        int iN42 = n(iN38 + l(iN41, iN40, iN39) + this.i[9] + 1859775393, 9);
        int iN43 = n(iN39 + l(iN42, iN41, iN40) + this.i[5] + 1859775393, 11);
        int iN44 = n(iN40 + l(iN43, iN42, iN41) + this.i[13] + 1859775393, 15);
        int iN45 = n(iN41 + l(iN44, iN43, iN42) + this.i[3] + 1859775393, 3);
        int iN46 = n(iN42 + l(iN45, iN44, iN43) + this.i[11] + 1859775393, 9);
        int iN47 = n(iN43 + l(iN46, iN45, iN44) + this.i[7] + 1859775393, 11);
        int iN48 = n(iN44 + l(iN47, iN46, iN45) + this.i[15] + 1859775393, 15);
        this.e += iN45;
        this.f += iN48;
        this.g += iN47;
        this.h += iN46;
        this.j = 0;
        int i5 = 0;
        while (true) {
            int[] iArr = this.i;
            if (i5 == iArr.length) {
                return;
            }
            iArr[i5] = 0;
            i5++;
        }
    }

    @Override // org.bouncycastle.crypto.Digest
    public java.lang.String getAlgorithmName() {
        return "MD4";
    }

    @Override // org.bouncycastle.crypto.Digest
    public int getDigestSize() {
        return 16;
    }

    @Override // org.bouncycastle.crypto.digests.GeneralDigest
    protected void h(long j) {
        if (this.j > 14) {
            g();
        }
        int[] iArr = this.i;
        iArr[14] = (int) j;
        iArr[15] = (int) (j >>> 32);
    }

    @Override // org.bouncycastle.crypto.digests.GeneralDigest
    protected void i(byte[] bArr, int i) {
        int[] iArr = this.i;
        int i2 = this.j;
        this.j = i2 + 1;
        iArr[i2] = org.bouncycastle.util.Pack.q(bArr, i);
        if (this.j == 16) {
            g();
        }
    }

    @Override // org.bouncycastle.crypto.digests.GeneralDigest, org.bouncycastle.crypto.Digest
    public void reset() {
        super.reset();
        this.e = 1732584193;
        this.f = -271733879;
        this.g = -1732584194;
        this.h = 271733878;
        this.j = 0;
        int i = 0;
        while (true) {
            int[] iArr = this.i;
            if (i == iArr.length) {
                return;
            }
            iArr[i] = 0;
            i++;
        }
    }

    public MD4Digest(org.bouncycastle.crypto.CryptoServicePurpose cryptoServicePurpose) {
        super(cryptoServicePurpose);
        this.i = new int[16];
        org.bouncycastle.crypto.CryptoServicesRegistrar.a(org.bouncycastle.crypto.digests.Utils.a(this, 64, cryptoServicePurpose));
        reset();
    }

    public MD4Digest(org.bouncycastle.crypto.digests.MD4Digest mD4Digest) {
        super(mD4Digest.a);
        this.i = new int[16];
        org.bouncycastle.crypto.CryptoServicesRegistrar.a(org.bouncycastle.crypto.digests.Utils.a(this, 64, this.a));
        m(mD4Digest);
    }
}
