package org.bouncycastle.crypto.digests;

/* JADX INFO: loaded from: E:\ios\vf_dex\classes4.dex */
public class RIPEMD128Digest 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 RIPEMD128Digest() {
        this(org.bouncycastle.crypto.CryptoServicePurpose.ANY);
    }

    private int j(int i, int i2, int i3, int i4, int i5, int i6) {
        return r(i + t(i2, i3, i4) + i5, i6);
    }

    private int k(int i, int i2, int i3, int i4, int i5, int i6) {
        return r(i + u(i2, i3, i4) + i5 + 1518500249, i6);
    }

    private int l(int i, int i2, int i3, int i4, int i5, int i6) {
        return r(i + v(i2, i3, i4) + i5 + 1859775393, i6);
    }

    private int m(int i, int i2, int i3, int i4, int i5, int i6) {
        return r(((i + w(i2, i3, i4)) + i5) - 1894007588, i6);
    }

    private int n(int i, int i2, int i3, int i4, int i5, int i6) {
        return r(i + t(i2, i3, i4) + i5, i6);
    }

    private int o(int i, int i2, int i3, int i4, int i5, int i6) {
        return r(i + u(i2, i3, i4) + i5 + 1836072691, i6);
    }

    private int p(int i, int i2, int i3, int i4, int i5, int i6) {
        return r(i + v(i2, i3, i4) + i5 + 1548603684, i6);
    }

    private int q(int i, int i2, int i3, int i4, int i5, int i6) {
        return r(i + w(i2, i3, i4) + i5 + 1352829926, i6);
    }

    private int r(int i, int i2) {
        return (i << i2) | (i >>> (32 - i2));
    }

    private void s(org.bouncycastle.crypto.digests.RIPEMD128Digest rIPEMD128Digest) {
        super.e(rIPEMD128Digest);
        this.e = rIPEMD128Digest.e;
        this.f = rIPEMD128Digest.f;
        this.g = rIPEMD128Digest.g;
        this.h = rIPEMD128Digest.h;
        int[] iArr = rIPEMD128Digest.i;
        java.lang.System.arraycopy(iArr, 0, this.i, 0, iArr.length);
        this.j = rIPEMD128Digest.j;
    }

    private int t(int i, int i2, int i3) {
        return (i ^ i2) ^ i3;
    }

    private int u(int i, int i2, int i3) {
        return (i & i2) | ((~i) & i3);
    }

    private int v(int i, int i2, int i3) {
        return ((~i2) | i) ^ i3;
    }

    private int w(int i, int i2, int i3) {
        return (i & i3) | ((~i3) & i2);
    }

    public org.bouncycastle.util.Memoable a() {
        return new org.bouncycastle.crypto.digests.RIPEMD128Digest(this);
    }

    public void d(org.bouncycastle.util.Memoable memoable) {
        s((org.bouncycastle.crypto.digests.RIPEMD128Digest) 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 iJ = j(i, i2, i3, i4, this.i[0], 11);
        int iJ2 = j(i4, iJ, i2, i3, this.i[1], 14);
        int iJ3 = j(i3, iJ2, iJ, i2, this.i[2], 15);
        int iJ4 = j(i2, iJ3, iJ2, iJ, this.i[3], 12);
        int iJ5 = j(iJ, iJ4, iJ3, iJ2, this.i[4], 5);
        int iJ6 = j(iJ2, iJ5, iJ4, iJ3, this.i[5], 8);
        int iJ7 = j(iJ3, iJ6, iJ5, iJ4, this.i[6], 7);
        int iJ8 = j(iJ4, iJ7, iJ6, iJ5, this.i[7], 9);
        int iJ9 = j(iJ5, iJ8, iJ7, iJ6, this.i[8], 11);
        int iJ10 = j(iJ6, iJ9, iJ8, iJ7, this.i[9], 13);
        int iJ11 = j(iJ7, iJ10, iJ9, iJ8, this.i[10], 14);
        int iJ12 = j(iJ8, iJ11, iJ10, iJ9, this.i[11], 15);
        int iJ13 = j(iJ9, iJ12, iJ11, iJ10, this.i[12], 6);
        int iJ14 = j(iJ10, iJ13, iJ12, iJ11, this.i[13], 7);
        int iJ15 = j(iJ11, iJ14, iJ13, iJ12, this.i[14], 9);
        int iJ16 = j(iJ12, iJ15, iJ14, iJ13, this.i[15], 8);
        int iK = k(iJ13, iJ16, iJ15, iJ14, this.i[7], 7);
        int iK2 = k(iJ14, iK, iJ16, iJ15, this.i[4], 6);
        int iK3 = k(iJ15, iK2, iK, iJ16, this.i[13], 8);
        int iK4 = k(iJ16, iK3, iK2, iK, this.i[1], 13);
        int iK5 = k(iK, iK4, iK3, iK2, this.i[10], 11);
        int iK6 = k(iK2, iK5, iK4, iK3, this.i[6], 9);
        int iK7 = k(iK3, iK6, iK5, iK4, this.i[15], 7);
        int iK8 = k(iK4, iK7, iK6, iK5, this.i[3], 15);
        int iK9 = k(iK5, iK8, iK7, iK6, this.i[12], 7);
        int iK10 = k(iK6, iK9, iK8, iK7, this.i[0], 12);
        int iK11 = k(iK7, iK10, iK9, iK8, this.i[9], 15);
        int iK12 = k(iK8, iK11, iK10, iK9, this.i[5], 9);
        int iK13 = k(iK9, iK12, iK11, iK10, this.i[2], 11);
        int iK14 = k(iK10, iK13, iK12, iK11, this.i[14], 7);
        int iK15 = k(iK11, iK14, iK13, iK12, this.i[11], 13);
        int iK16 = k(iK12, iK15, iK14, iK13, this.i[8], 12);
        int iL = l(iK13, iK16, iK15, iK14, this.i[3], 11);
        int iL2 = l(iK14, iL, iK16, iK15, this.i[10], 13);
        int iL3 = l(iK15, iL2, iL, iK16, this.i[14], 6);
        int iL4 = l(iK16, iL3, iL2, iL, this.i[4], 7);
        int iL5 = l(iL, iL4, iL3, iL2, this.i[9], 14);
        int iL6 = l(iL2, iL5, iL4, iL3, this.i[15], 9);
        int iL7 = l(iL3, iL6, iL5, iL4, this.i[8], 13);
        int iL8 = l(iL4, iL7, iL6, iL5, this.i[1], 15);
        int iL9 = l(iL5, iL8, iL7, iL6, this.i[2], 14);
        int iL10 = l(iL6, iL9, iL8, iL7, this.i[7], 8);
        int iL11 = l(iL7, iL10, iL9, iL8, this.i[0], 13);
        int iL12 = l(iL8, iL11, iL10, iL9, this.i[6], 6);
        int iL13 = l(iL9, iL12, iL11, iL10, this.i[13], 5);
        int iL14 = l(iL10, iL13, iL12, iL11, this.i[11], 12);
        int iL15 = l(iL11, iL14, iL13, iL12, this.i[5], 7);
        int iL16 = l(iL12, iL15, iL14, iL13, this.i[12], 5);
        int iM = m(iL13, iL16, iL15, iL14, this.i[1], 11);
        int iM2 = m(iL14, iM, iL16, iL15, this.i[9], 12);
        int iM3 = m(iL15, iM2, iM, iL16, this.i[11], 14);
        int iM4 = m(iL16, iM3, iM2, iM, this.i[10], 15);
        int iM5 = m(iM, iM4, iM3, iM2, this.i[0], 14);
        int iM6 = m(iM2, iM5, iM4, iM3, this.i[8], 15);
        int iM7 = m(iM3, iM6, iM5, iM4, this.i[12], 9);
        int iM8 = m(iM4, iM7, iM6, iM5, this.i[4], 8);
        int iM9 = m(iM5, iM8, iM7, iM6, this.i[13], 9);
        int iM10 = m(iM6, iM9, iM8, iM7, this.i[3], 14);
        int iM11 = m(iM7, iM10, iM9, iM8, this.i[7], 5);
        int iM12 = m(iM8, iM11, iM10, iM9, this.i[15], 6);
        int iM13 = m(iM9, iM12, iM11, iM10, this.i[14], 8);
        int iM14 = m(iM10, iM13, iM12, iM11, this.i[5], 6);
        int iM15 = m(iM11, iM14, iM13, iM12, this.i[6], 5);
        int iM16 = m(iM12, iM15, iM14, iM13, this.i[2], 12);
        int iQ = q(i, i2, i3, i4, this.i[5], 8);
        int iQ2 = q(i4, iQ, i2, i3, this.i[14], 9);
        int iQ3 = q(i3, iQ2, iQ, i2, this.i[7], 9);
        int iQ4 = q(i2, iQ3, iQ2, iQ, this.i[0], 11);
        int iQ5 = q(iQ, iQ4, iQ3, iQ2, this.i[9], 13);
        int iQ6 = q(iQ2, iQ5, iQ4, iQ3, this.i[2], 15);
        int iQ7 = q(iQ3, iQ6, iQ5, iQ4, this.i[11], 15);
        int iQ8 = q(iQ4, iQ7, iQ6, iQ5, this.i[4], 5);
        int iQ9 = q(iQ5, iQ8, iQ7, iQ6, this.i[13], 7);
        int iQ10 = q(iQ6, iQ9, iQ8, iQ7, this.i[6], 7);
        int iQ11 = q(iQ7, iQ10, iQ9, iQ8, this.i[15], 8);
        int iQ12 = q(iQ8, iQ11, iQ10, iQ9, this.i[8], 11);
        int iQ13 = q(iQ9, iQ12, iQ11, iQ10, this.i[1], 14);
        int iQ14 = q(iQ10, iQ13, iQ12, iQ11, this.i[10], 14);
        int iQ15 = q(iQ11, iQ14, iQ13, iQ12, this.i[3], 12);
        int iQ16 = q(iQ12, iQ15, iQ14, iQ13, this.i[12], 6);
        int iP = p(iQ13, iQ16, iQ15, iQ14, this.i[6], 9);
        int iP2 = p(iQ14, iP, iQ16, iQ15, this.i[11], 13);
        int iP3 = p(iQ15, iP2, iP, iQ16, this.i[3], 15);
        int iP4 = p(iQ16, iP3, iP2, iP, this.i[7], 7);
        int iP5 = p(iP, iP4, iP3, iP2, this.i[0], 12);
        int iP6 = p(iP2, iP5, iP4, iP3, this.i[13], 8);
        int iP7 = p(iP3, iP6, iP5, iP4, this.i[5], 9);
        int iP8 = p(iP4, iP7, iP6, iP5, this.i[10], 11);
        int iP9 = p(iP5, iP8, iP7, iP6, this.i[14], 7);
        int iP10 = p(iP6, iP9, iP8, iP7, this.i[15], 7);
        int iP11 = p(iP7, iP10, iP9, iP8, this.i[8], 12);
        int iP12 = p(iP8, iP11, iP10, iP9, this.i[12], 7);
        int iP13 = p(iP9, iP12, iP11, iP10, this.i[4], 6);
        int iP14 = p(iP10, iP13, iP12, iP11, this.i[9], 15);
        int iP15 = p(iP11, iP14, iP13, iP12, this.i[1], 13);
        int iP16 = p(iP12, iP15, iP14, iP13, this.i[2], 11);
        int iO = o(iP13, iP16, iP15, iP14, this.i[15], 9);
        int iO2 = o(iP14, iO, iP16, iP15, this.i[5], 7);
        int iO3 = o(iP15, iO2, iO, iP16, this.i[1], 15);
        int iO4 = o(iP16, iO3, iO2, iO, this.i[3], 11);
        int iO5 = o(iO, iO4, iO3, iO2, this.i[7], 8);
        int iO6 = o(iO2, iO5, iO4, iO3, this.i[14], 6);
        int iO7 = o(iO3, iO6, iO5, iO4, this.i[6], 6);
        int iO8 = o(iO4, iO7, iO6, iO5, this.i[9], 14);
        int iO9 = o(iO5, iO8, iO7, iO6, this.i[11], 12);
        int iO10 = o(iO6, iO9, iO8, iO7, this.i[8], 13);
        int iO11 = o(iO7, iO10, iO9, iO8, this.i[12], 5);
        int iO12 = o(iO8, iO11, iO10, iO9, this.i[2], 14);
        int iO13 = o(iO9, iO12, iO11, iO10, this.i[10], 13);
        int iO14 = o(iO10, iO13, iO12, iO11, this.i[0], 13);
        int iO15 = o(iO11, iO14, iO13, iO12, this.i[4], 7);
        int iO16 = o(iO12, iO15, iO14, iO13, this.i[13], 5);
        int iN = n(iO13, iO16, iO15, iO14, this.i[8], 15);
        int iN2 = n(iO14, iN, iO16, iO15, this.i[6], 5);
        int iN3 = n(iO15, iN2, iN, iO16, this.i[4], 8);
        int iN4 = n(iO16, iN3, iN2, iN, this.i[1], 11);
        int iN5 = n(iN, iN4, iN3, iN2, this.i[3], 14);
        int iN6 = n(iN2, iN5, iN4, iN3, this.i[11], 14);
        int iN7 = n(iN3, iN6, iN5, iN4, this.i[15], 6);
        int iN8 = n(iN4, iN7, iN6, iN5, this.i[0], 14);
        int iN9 = n(iN5, iN8, iN7, iN6, this.i[5], 6);
        int iN10 = n(iN6, iN9, iN8, iN7, this.i[12], 9);
        int iN11 = n(iN7, iN10, iN9, iN8, this.i[2], 12);
        int iN12 = n(iN8, iN11, iN10, iN9, this.i[13], 9);
        int iN13 = n(iN9, iN12, iN11, iN10, this.i[9], 12);
        int iN14 = n(iN10, iN13, iN12, iN11, this.i[7], 5);
        int iN15 = n(iN11, iN14, iN13, iN12, this.i[10], 15);
        int iN16 = n(iN12, iN15, iN14, iN13, this.i[14], 8);
        int i5 = iN14 + iM15 + this.f;
        this.f = this.g + iM14 + iN13;
        this.g = this.h + iM13 + iN16;
        this.h = this.e + iM16 + iN15;
        this.e = i5;
        this.j = 0;
        int i6 = 0;
        while (true) {
            int[] iArr = this.i;
            if (i6 == iArr.length) {
                return;
            }
            iArr[i6] = 0;
            i6++;
        }
    }

    @Override // org.bouncycastle.crypto.Digest
    public java.lang.String getAlgorithmName() {
        return "RIPEMD128";
    }

    @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 RIPEMD128Digest(org.bouncycastle.crypto.CryptoServicePurpose cryptoServicePurpose) {
        super(cryptoServicePurpose);
        this.i = new int[16];
        org.bouncycastle.crypto.CryptoServicesRegistrar.a(org.bouncycastle.crypto.digests.Utils.a(this, 128, cryptoServicePurpose));
        reset();
    }

    public RIPEMD128Digest(org.bouncycastle.crypto.digests.RIPEMD128Digest rIPEMD128Digest) {
        super(rIPEMD128Digest.a);
        this.i = new int[16];
        org.bouncycastle.crypto.CryptoServicesRegistrar.a(org.bouncycastle.crypto.digests.Utils.a(this, 128, this.a));
        s(rIPEMD128Digest);
    }
}
