package org.bouncycastle.crypto.digests;

/* JADX INFO: loaded from: E:\ios\vf_dex\classes4.dex */
public class MD5Digest extends org.bouncycastle.crypto.digests.GeneralDigest implements org.bouncycastle.crypto.digests.EncodableDigest {
    private int e;
    private int f;
    private int g;
    private int h;
    private int[] i;
    private int j;

    public MD5Digest() {
        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 (i & i3) | ((~i3) & i2);
    }

    private int l(int i, int i2, int i3) {
        return (i ^ i2) ^ i3;
    }

    private int m(int i, int i2, int i3) {
        return ((~i3) | i) ^ i2;
    }

    private void n(org.bouncycastle.crypto.digests.MD5Digest mD5Digest) {
        super.e(mD5Digest);
        this.e = mD5Digest.e;
        this.f = mD5Digest.f;
        this.g = mD5Digest.g;
        this.h = mD5Digest.h;
        int[] iArr = mD5Digest.i;
        java.lang.System.arraycopy(iArr, 0, this.i, 0, iArr.length);
        this.j = mD5Digest.j;
    }

    private int o(int i, int i2) {
        return (i << i2) | (i >>> (32 - i2));
    }

    public org.bouncycastle.util.Memoable a() {
        return new org.bouncycastle.crypto.digests.MD5Digest(this);
    }

    public void d(org.bouncycastle.util.Memoable memoable) {
        n((org.bouncycastle.crypto.digests.MD5Digest) 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 iO = o(((i + j(i2, i3, i4)) + this.i[0]) - 680876936, 7) + i2;
        int iO2 = o(((i4 + j(iO, i2, i3)) + this.i[1]) - 389564586, 12) + iO;
        int iO3 = o(i3 + j(iO2, iO, i2) + this.i[2] + 606105819, 17) + iO2;
        int iO4 = o(((i2 + j(iO3, iO2, iO)) + this.i[3]) - 1044525330, 22) + iO3;
        int iO5 = o(((iO + j(iO4, iO3, iO2)) + this.i[4]) - 176418897, 7) + iO4;
        int iO6 = o(iO2 + j(iO5, iO4, iO3) + this.i[5] + 1200080426, 12) + iO5;
        int iO7 = o(((iO3 + j(iO6, iO5, iO4)) + this.i[6]) - 1473231341, 17) + iO6;
        int iO8 = o(((iO4 + j(iO7, iO6, iO5)) + this.i[7]) - 45705983, 22) + iO7;
        int iO9 = o(iO5 + j(iO8, iO7, iO6) + this.i[8] + 1770035416, 7) + iO8;
        int iO10 = o(((iO6 + j(iO9, iO8, iO7)) + this.i[9]) - 1958414417, 12) + iO9;
        int iO11 = o(((iO7 + j(iO10, iO9, iO8)) + this.i[10]) - 42063, 17) + iO10;
        int iO12 = o(((iO8 + j(iO11, iO10, iO9)) + this.i[11]) - 1990404162, 22) + iO11;
        int iO13 = o(iO9 + j(iO12, iO11, iO10) + this.i[12] + 1804603682, 7) + iO12;
        int iO14 = o(((iO10 + j(iO13, iO12, iO11)) + this.i[13]) - 40341101, 12) + iO13;
        int iO15 = o(((iO11 + j(iO14, iO13, iO12)) + this.i[14]) - 1502002290, 17) + iO14;
        int iO16 = o(iO12 + j(iO15, iO14, iO13) + this.i[15] + 1236535329, 22) + iO15;
        int iO17 = o(((iO13 + k(iO16, iO15, iO14)) + this.i[1]) - 165796510, 5) + iO16;
        int iO18 = o(((iO14 + k(iO17, iO16, iO15)) + this.i[6]) - 1069501632, 9) + iO17;
        int iO19 = o(iO15 + k(iO18, iO17, iO16) + this.i[11] + 643717713, 14) + iO18;
        int iO20 = o(((iO16 + k(iO19, iO18, iO17)) + this.i[0]) - 373897302, 20) + iO19;
        int iO21 = o(((iO17 + k(iO20, iO19, iO18)) + this.i[5]) - 701558691, 5) + iO20;
        int iO22 = o(iO18 + k(iO21, iO20, iO19) + this.i[10] + 38016083, 9) + iO21;
        int iO23 = o(((iO19 + k(iO22, iO21, iO20)) + this.i[15]) - 660478335, 14) + iO22;
        int iO24 = o(((iO20 + k(iO23, iO22, iO21)) + this.i[4]) - 405537848, 20) + iO23;
        int iO25 = o(iO21 + k(iO24, iO23, iO22) + this.i[9] + 568446438, 5) + iO24;
        int iO26 = o(((iO22 + k(iO25, iO24, iO23)) + this.i[14]) - 1019803690, 9) + iO25;
        int iO27 = o(((iO23 + k(iO26, iO25, iO24)) + this.i[3]) - 187363961, 14) + iO26;
        int iO28 = o(iO24 + k(iO27, iO26, iO25) + this.i[8] + 1163531501, 20) + iO27;
        int iO29 = o(((iO25 + k(iO28, iO27, iO26)) + this.i[13]) - 1444681467, 5) + iO28;
        int iO30 = o(((iO26 + k(iO29, iO28, iO27)) + this.i[2]) - 51403784, 9) + iO29;
        int iO31 = o(iO27 + k(iO30, iO29, iO28) + this.i[7] + 1735328473, 14) + iO30;
        int iO32 = o(((iO28 + k(iO31, iO30, iO29)) + this.i[12]) - 1926607734, 20) + iO31;
        int iO33 = o(((iO29 + l(iO32, iO31, iO30)) + this.i[5]) - 378558, 4) + iO32;
        int iO34 = o(((iO30 + l(iO33, iO32, iO31)) + this.i[8]) - 2022574463, 11) + iO33;
        int iO35 = o(iO31 + l(iO34, iO33, iO32) + this.i[11] + 1839030562, 16) + iO34;
        int iO36 = o(((iO32 + l(iO35, iO34, iO33)) + this.i[14]) - 35309556, 23) + iO35;
        int iO37 = o(((iO33 + l(iO36, iO35, iO34)) + this.i[1]) - 1530992060, 4) + iO36;
        int iO38 = o(iO34 + l(iO37, iO36, iO35) + this.i[4] + 1272893353, 11) + iO37;
        int iO39 = o(((iO35 + l(iO38, iO37, iO36)) + this.i[7]) - 155497632, 16) + iO38;
        int iO40 = o(((iO36 + l(iO39, iO38, iO37)) + this.i[10]) - 1094730640, 23) + iO39;
        int iO41 = o(iO37 + l(iO40, iO39, iO38) + this.i[13] + 681279174, 4) + iO40;
        int iO42 = o(((iO38 + l(iO41, iO40, iO39)) + this.i[0]) - 358537222, 11) + iO41;
        int iO43 = o(((iO39 + l(iO42, iO41, iO40)) + this.i[3]) - 722521979, 16) + iO42;
        int iO44 = o(iO40 + l(iO43, iO42, iO41) + this.i[6] + 76029189, 23) + iO43;
        int iO45 = o(((iO41 + l(iO44, iO43, iO42)) + this.i[9]) - 640364487, 4) + iO44;
        int iO46 = o(((iO42 + l(iO45, iO44, iO43)) + this.i[12]) - 421815835, 11) + iO45;
        int iO47 = o(iO43 + l(iO46, iO45, iO44) + this.i[15] + 530742520, 16) + iO46;
        int iO48 = o(((iO44 + l(iO47, iO46, iO45)) + this.i[2]) - 995338651, 23) + iO47;
        int iO49 = o(((iO45 + m(iO48, iO47, iO46)) + this.i[0]) - 198630844, 6) + iO48;
        int iO50 = o(iO46 + m(iO49, iO48, iO47) + this.i[7] + 1126891415, 10) + iO49;
        int iO51 = o(((iO47 + m(iO50, iO49, iO48)) + this.i[14]) - 1416354905, 15) + iO50;
        int iO52 = o(((iO48 + m(iO51, iO50, iO49)) + this.i[5]) - 57434055, 21) + iO51;
        int iO53 = o(iO49 + m(iO52, iO51, iO50) + this.i[12] + 1700485571, 6) + iO52;
        int iO54 = o(((iO50 + m(iO53, iO52, iO51)) + this.i[3]) - 1894986606, 10) + iO53;
        int iO55 = o(((iO51 + m(iO54, iO53, iO52)) + this.i[10]) - 1051523, 15) + iO54;
        int iO56 = o(((iO52 + m(iO55, iO54, iO53)) + this.i[1]) - 2054922799, 21) + iO55;
        int iO57 = o(iO53 + m(iO56, iO55, iO54) + this.i[8] + 1873313359, 6) + iO56;
        int iO58 = o(((iO54 + m(iO57, iO56, iO55)) + this.i[15]) - 30611744, 10) + iO57;
        int iO59 = o(((iO55 + m(iO58, iO57, iO56)) + this.i[6]) - 1560198380, 15) + iO58;
        int iO60 = o(iO56 + m(iO59, iO58, iO57) + this.i[13] + 1309151649, 21) + iO59;
        int iO61 = o(((iO57 + m(iO60, iO59, iO58)) + this.i[4]) - 145523070, 6) + iO60;
        int iO62 = o(((iO58 + m(iO61, iO60, iO59)) + this.i[11]) - 1120210379, 10) + iO61;
        int iO63 = o(iO59 + m(iO62, iO61, iO60) + this.i[2] + 718787259, 15) + iO62;
        int iO64 = o(((iO60 + m(iO63, iO62, iO61)) + this.i[9]) - 343485551, 21) + iO63;
        this.e += iO61;
        this.f += iO64;
        this.g += iO63;
        this.h += iO62;
        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 "MD5";
    }

    @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 MD5Digest(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 MD5Digest(org.bouncycastle.crypto.digests.MD5Digest mD5Digest) {
        super(mD5Digest);
        this.i = new int[16];
        n(mD5Digest);
    }
}
