package org.bouncycastle.crypto.digests;

/* JADX INFO: loaded from: E:\ios\vf_dex\classes4.dex */
public class SHA512tDigest extends org.bouncycastle.crypto.digests.LongDigest {
    private int q;
    private long r;
    private long s;
    private long t;
    private long u;
    private long v;
    private long w;
    private long x;
    private long y;

    public SHA512tDigest(int i) {
        this(i, org.bouncycastle.crypto.CryptoServicePurpose.ANY);
    }

    private static void r(int i, byte[] bArr, int i2, int i3) {
        int iMin = java.lang.Math.min(4, i3);
        while (true) {
            iMin--;
            if (iMin < 0) {
                return;
            } else {
                bArr[i2 + iMin] = (byte) (i >>> ((3 - iMin) * 8));
            }
        }
    }

    private static void s(long j, byte[] bArr, int i, int i2) {
        if (i2 > 0) {
            r((int) (j >>> 32), bArr, i, i2);
            if (i2 > 4) {
                r((int) (j & 4294967295L), bArr, i + 4, i2 - 4);
            }
        }
    }

    private void t(int i) {
        this.f = -3482333909917012819L;
        this.g = 2216346199247487646L;
        this.h = -7364697282686394994L;
        this.i = 65953792586715988L;
        this.j = -816286391624063116L;
        this.k = 4512832404995164602L;
        this.l = -5033199132376557362L;
        this.m = -124578254951840548L;
        update((byte) 83);
        update((byte) 72);
        update((byte) 65);
        update((byte) 45);
        update((byte) 53);
        update((byte) 49);
        update((byte) 50);
        update((byte) 47);
        if (i <= 100) {
            if (i > 10) {
            }
            update((byte) (i + 48));
            m();
            this.r = this.f;
            this.s = this.g;
            this.t = this.h;
            this.u = this.i;
            this.v = this.j;
            this.w = this.k;
            this.x = this.l;
            this.y = this.m;
        }
        update((byte) ((i / 100) + 48));
        i %= 100;
        update((byte) ((i / 10) + 48));
        i %= 10;
        update((byte) (i + 48));
        m();
        this.r = this.f;
        this.s = this.g;
        this.t = this.h;
        this.u = this.i;
        this.v = this.j;
        this.w = this.k;
        this.x = this.l;
        this.y = this.m;
    }

    public org.bouncycastle.util.Memoable a() {
        return new org.bouncycastle.crypto.digests.SHA512tDigest(this);
    }

    /* JADX INFO: Thrown type has an unknown type hierarchy: org.bouncycastle.util.MemoableResetException */
    public void d(org.bouncycastle.util.Memoable memoable) throws org.bouncycastle.util.MemoableResetException {
        org.bouncycastle.crypto.digests.SHA512tDigest sHA512tDigest = (org.bouncycastle.crypto.digests.SHA512tDigest) memoable;
        if (this.q != sHA512tDigest.q) {
            throw new org.bouncycastle.util.MemoableResetException("digestLength inappropriate in other");
        }
        super.l(sHA512tDigest);
        this.r = sHA512tDigest.r;
        this.s = sHA512tDigest.s;
        this.t = sHA512tDigest.t;
        this.u = sHA512tDigest.u;
        this.v = sHA512tDigest.v;
        this.w = sHA512tDigest.w;
        this.x = sHA512tDigest.x;
        this.y = sHA512tDigest.y;
    }

    @Override // org.bouncycastle.crypto.Digest
    public int doFinal(byte[] bArr, int i) {
        m();
        s(this.f, bArr, i, this.q);
        s(this.g, bArr, i + 8, this.q - 8);
        s(this.h, bArr, i + 16, this.q - 16);
        s(this.i, bArr, i + 24, this.q - 24);
        s(this.j, bArr, i + 32, this.q - 32);
        s(this.k, bArr, i + 40, this.q - 40);
        s(this.l, bArr, i + 48, this.q - 48);
        s(this.m, bArr, i + 56, this.q - 56);
        reset();
        return this.q;
    }

    @Override // org.bouncycastle.crypto.Digest
    public java.lang.String getAlgorithmName() {
        return "SHA-512/" + java.lang.Integer.toString(this.q * 8);
    }

    @Override // org.bouncycastle.crypto.Digest
    public int getDigestSize() {
        return this.q;
    }

    protected org.bouncycastle.crypto.CryptoServiceProperties q() {
        return org.bouncycastle.crypto.digests.Utils.a(this, getDigestSize() * 8, this.a);
    }

    @Override // org.bouncycastle.crypto.digests.LongDigest, org.bouncycastle.crypto.Digest
    public void reset() {
        super.reset();
        this.f = this.r;
        this.g = this.s;
        this.h = this.t;
        this.i = this.u;
        this.j = this.v;
        this.k = this.w;
        this.l = this.x;
        this.m = this.y;
    }

    public SHA512tDigest(int i, org.bouncycastle.crypto.CryptoServicePurpose cryptoServicePurpose) {
        if (i >= 512) {
            throw new java.lang.IllegalArgumentException("bitLength cannot be >= 512");
        }
        if (i % 8 != 0) {
            throw new java.lang.IllegalArgumentException("bitLength needs to be a multiple of 8");
        }
        if (i == 384) {
            throw new java.lang.IllegalArgumentException("bitLength cannot be 384 use SHA384 instead");
        }
        this.q = i / 8;
        org.bouncycastle.crypto.CryptoServicesRegistrar.a(q());
        t(this.q * 8);
        reset();
    }

    /* JADX INFO: Thrown type has an unknown type hierarchy: org.bouncycastle.util.MemoableResetException */
    public SHA512tDigest(org.bouncycastle.crypto.digests.SHA512tDigest sHA512tDigest) throws org.bouncycastle.util.MemoableResetException {
        super(sHA512tDigest);
        this.q = sHA512tDigest.q;
        org.bouncycastle.crypto.CryptoServicesRegistrar.a(q());
        d(sHA512tDigest);
    }
}
