package org.bouncycastle.crypto.digests;

/* JADX INFO: loaded from: E:\ios\vf_dex\classes4.dex */
public class SHA1Digest 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;
    private int k;

    public SHA1Digest() {
        this(org.bouncycastle.crypto.CryptoServicePurpose.ANY);
    }

    private void j(org.bouncycastle.crypto.digests.SHA1Digest sHA1Digest) {
        this.e = sHA1Digest.e;
        this.f = sHA1Digest.f;
        this.g = sHA1Digest.g;
        this.h = sHA1Digest.h;
        this.i = sHA1Digest.i;
        int[] iArr = sHA1Digest.j;
        java.lang.System.arraycopy(iArr, 0, this.j, 0, iArr.length);
        this.k = sHA1Digest.k;
    }

    private int l(int i, int i2, int i3) {
        return (i & i2) | ((~i) & i3);
    }

    private int m(int i, int i2, int i3) {
        return ((i2 | i3) & i) | (i2 & i3);
    }

    private int n(int i, int i2, int i3) {
        return (i ^ i2) ^ i3;
    }

    public org.bouncycastle.util.Memoable a() {
        return new org.bouncycastle.crypto.digests.SHA1Digest(this);
    }

    public void d(org.bouncycastle.util.Memoable memoable) {
        org.bouncycastle.crypto.digests.SHA1Digest sHA1Digest = (org.bouncycastle.crypto.digests.SHA1Digest) memoable;
        super.e(sHA1Digest);
        j(sHA1Digest);
    }

    @Override // org.bouncycastle.crypto.Digest
    public int doFinal(byte[] bArr, int i) {
        f();
        org.bouncycastle.util.Pack.h(this.e, bArr, i);
        org.bouncycastle.util.Pack.h(this.f, bArr, i + 4);
        org.bouncycastle.util.Pack.h(this.g, bArr, i + 8);
        org.bouncycastle.util.Pack.h(this.h, bArr, i + 12);
        org.bouncycastle.util.Pack.h(this.i, bArr, i + 16);
        reset();
        return 20;
    }

    @Override // org.bouncycastle.crypto.digests.GeneralDigest
    protected void g() {
        for (int i = 16; i < 80; i++) {
            int[] iArr = this.j;
            int i2 = ((iArr[i - 3] ^ iArr[i - 8]) ^ iArr[i - 14]) ^ iArr[i - 16];
            iArr[i] = (i2 >>> 31) | (i2 << 1);
        }
        int iN = this.e;
        int iN2 = this.f;
        int i3 = this.g;
        int i4 = this.h;
        int i5 = this.i;
        int i6 = 0;
        for (int i7 = 0; i7 < 4; i7++) {
            int iL = i5 + ((iN << 5) | (iN >>> 27)) + l(iN2, i3, i4) + this.j[i6] + 1518500249;
            int i8 = (iN2 >>> 2) | (iN2 << 30);
            int iL2 = i4 + ((iL << 5) | (iL >>> 27)) + l(iN, i8, i3) + this.j[i6 + 1] + 1518500249;
            int i9 = (iN >>> 2) | (iN << 30);
            int iL3 = i3 + ((iL2 << 5) | (iL2 >>> 27)) + l(iL, i9, i8) + this.j[i6 + 2] + 1518500249;
            i5 = (iL >>> 2) | (iL << 30);
            int i10 = i6 + 4;
            iN2 = i8 + ((iL3 << 5) | (iL3 >>> 27)) + l(iL2, i5, i9) + this.j[i6 + 3] + 1518500249;
            i4 = (iL2 >>> 2) | (iL2 << 30);
            i6 += 5;
            iN = i9 + ((iN2 << 5) | (iN2 >>> 27)) + l(iL3, i4, i5) + this.j[i10] + 1518500249;
            i3 = (iL3 >>> 2) | (iL3 << 30);
        }
        for (int i11 = 0; i11 < 4; i11++) {
            int iN3 = i5 + ((iN << 5) | (iN >>> 27)) + n(iN2, i3, i4) + this.j[i6] + 1859775393;
            int i12 = (iN2 >>> 2) | (iN2 << 30);
            int iN4 = i4 + ((iN3 << 5) | (iN3 >>> 27)) + n(iN, i12, i3) + this.j[i6 + 1] + 1859775393;
            int i13 = (iN >>> 2) | (iN << 30);
            int iN5 = i3 + ((iN4 << 5) | (iN4 >>> 27)) + n(iN3, i13, i12) + this.j[i6 + 2] + 1859775393;
            i5 = (iN3 >>> 2) | (iN3 << 30);
            int i14 = i6 + 4;
            iN2 = i12 + ((iN5 << 5) | (iN5 >>> 27)) + n(iN4, i5, i13) + this.j[i6 + 3] + 1859775393;
            i4 = (iN4 >>> 2) | (iN4 << 30);
            i6 += 5;
            iN = i13 + ((iN2 << 5) | (iN2 >>> 27)) + n(iN5, i4, i5) + this.j[i14] + 1859775393;
            i3 = (iN5 >>> 2) | (iN5 << 30);
        }
        for (int i15 = 0; i15 < 4; i15++) {
            int iM = i5 + (((((iN << 5) | (iN >>> 27)) + m(iN2, i3, i4)) + this.j[i6]) - 1894007588);
            int i16 = (iN2 >>> 2) | (iN2 << 30);
            int iM2 = i4 + (((((iM << 5) | (iM >>> 27)) + m(iN, i16, i3)) + this.j[i6 + 1]) - 1894007588);
            int i17 = (iN >>> 2) | (iN << 30);
            int iM3 = i3 + (((((iM2 << 5) | (iM2 >>> 27)) + m(iM, i17, i16)) + this.j[i6 + 2]) - 1894007588);
            i5 = (iM >>> 2) | (iM << 30);
            int i18 = i6 + 4;
            iN2 = i16 + (((((iM3 << 5) | (iM3 >>> 27)) + m(iM2, i5, i17)) + this.j[i6 + 3]) - 1894007588);
            i4 = (iM2 >>> 2) | (iM2 << 30);
            i6 += 5;
            iN = i17 + (((((iN2 << 5) | (iN2 >>> 27)) + m(iM3, i4, i5)) + this.j[i18]) - 1894007588);
            i3 = (iM3 >>> 2) | (iM3 << 30);
        }
        for (int i19 = 0; i19 <= 3; i19++) {
            int iN6 = i5 + (((((iN << 5) | (iN >>> 27)) + n(iN2, i3, i4)) + this.j[i6]) - 899497514);
            int i20 = (iN2 >>> 2) | (iN2 << 30);
            int iN7 = i4 + (((((iN6 << 5) | (iN6 >>> 27)) + n(iN, i20, i3)) + this.j[i6 + 1]) - 899497514);
            int i21 = (iN >>> 2) | (iN << 30);
            int iN8 = i3 + (((((iN7 << 5) | (iN7 >>> 27)) + n(iN6, i21, i20)) + this.j[i6 + 2]) - 899497514);
            i5 = (iN6 >>> 2) | (iN6 << 30);
            int i22 = i6 + 4;
            iN2 = i20 + (((((iN8 << 5) | (iN8 >>> 27)) + n(iN7, i5, i21)) + this.j[i6 + 3]) - 899497514);
            i4 = (iN7 >>> 2) | (iN7 << 30);
            i6 += 5;
            iN = i21 + (((((iN2 << 5) | (iN2 >>> 27)) + n(iN8, i4, i5)) + this.j[i22]) - 899497514);
            i3 = (iN8 >>> 2) | (iN8 << 30);
        }
        this.e += iN;
        this.f += iN2;
        this.g += i3;
        this.h += i4;
        this.i += i5;
        this.k = 0;
        for (int i23 = 0; i23 < 16; i23++) {
            this.j[i23] = 0;
        }
    }

    @Override // org.bouncycastle.crypto.Digest
    public java.lang.String getAlgorithmName() {
        return "SHA-1";
    }

    @Override // org.bouncycastle.crypto.Digest
    public int getDigestSize() {
        return 20;
    }

    @Override // org.bouncycastle.crypto.digests.GeneralDigest
    protected void h(long j) {
        if (this.k > 14) {
            g();
        }
        int[] iArr = this.j;
        iArr[14] = (int) (j >>> 32);
        iArr[15] = (int) j;
    }

    @Override // org.bouncycastle.crypto.digests.GeneralDigest
    protected void i(byte[] bArr, int i) {
        this.j[this.k] = org.bouncycastle.util.Pack.a(bArr, i);
        int i2 = this.k + 1;
        this.k = i2;
        if (i2 == 16) {
            g();
        }
    }

    protected org.bouncycastle.crypto.CryptoServiceProperties k() {
        return org.bouncycastle.crypto.digests.Utils.a(this, 128, this.a);
    }

    @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.i = -1009589776;
        this.k = 0;
        int i = 0;
        while (true) {
            int[] iArr = this.j;
            if (i == iArr.length) {
                return;
            }
            iArr[i] = 0;
            i++;
        }
    }

    public SHA1Digest(org.bouncycastle.crypto.CryptoServicePurpose cryptoServicePurpose) {
        super(cryptoServicePurpose);
        this.j = new int[80];
        org.bouncycastle.crypto.CryptoServicesRegistrar.a(k());
        reset();
    }

    public SHA1Digest(org.bouncycastle.crypto.digests.SHA1Digest sHA1Digest) {
        super(sHA1Digest);
        this.j = new int[80];
        org.bouncycastle.crypto.CryptoServicesRegistrar.a(k());
        j(sHA1Digest);
    }
}
