package org.bouncycastle.crypto.engines;

/* JADX INFO: loaded from: E:\ios\vf_dex\classes4.dex */
public class ElephantEngine extends org.bouncycastle.crypto.engines.AEADBaseEngine {
    private org.bouncycastle.crypto.engines.ElephantEngine.State A;
    private final java.io.ByteArrayOutputStream B;
    private int C;
    private byte[] D;
    private int E;
    private final byte[] F;
    private final byte[] G;
    private final int[] H;
    private final org.bouncycastle.crypto.engines.ElephantEngine.ElephantParameters h;
    private final int i;
    private int j;
    private int k;
    private final int l;
    private byte m;
    private byte[] n;
    private byte[] o;
    private boolean p;
    private int q;
    private byte[] r;
    private int s;
    private int t;
    private final byte[] u;
    private byte[] v;
    private byte[] w;
    private byte[] x;
    private final byte[] y;
    private final byte[] z;

    /* JADX INFO: renamed from: org.bouncycastle.crypto.engines.ElephantEngine$1, reason: invalid class name */
    static /* synthetic */ class AnonymousClass1 {
        static final /* synthetic */ int[] a;
        static final /* synthetic */ int[] b;

        static {
            int[] iArr = new int[org.bouncycastle.crypto.engines.ElephantEngine.State.values().length];
            b = iArr;
            try {
                iArr[org.bouncycastle.crypto.engines.ElephantEngine.State.Uninitialized.ordinal()] = 1;
            } catch (java.lang.NoSuchFieldError unused) {
            }
            try {
                b[org.bouncycastle.crypto.engines.ElephantEngine.State.DecFinal.ordinal()] = 2;
            } catch (java.lang.NoSuchFieldError unused2) {
            }
            try {
                b[org.bouncycastle.crypto.engines.ElephantEngine.State.EncFinal.ordinal()] = 3;
            } catch (java.lang.NoSuchFieldError unused3) {
            }
            try {
                b[org.bouncycastle.crypto.engines.ElephantEngine.State.EncAad.ordinal()] = 4;
            } catch (java.lang.NoSuchFieldError unused4) {
            }
            try {
                b[org.bouncycastle.crypto.engines.ElephantEngine.State.EncData.ordinal()] = 5;
            } catch (java.lang.NoSuchFieldError unused5) {
            }
            try {
                b[org.bouncycastle.crypto.engines.ElephantEngine.State.EncInit.ordinal()] = 6;
            } catch (java.lang.NoSuchFieldError unused6) {
            }
            try {
                b[org.bouncycastle.crypto.engines.ElephantEngine.State.DecAad.ordinal()] = 7;
            } catch (java.lang.NoSuchFieldError unused7) {
            }
            try {
                b[org.bouncycastle.crypto.engines.ElephantEngine.State.DecData.ordinal()] = 8;
            } catch (java.lang.NoSuchFieldError unused8) {
            }
            try {
                b[org.bouncycastle.crypto.engines.ElephantEngine.State.DecInit.ordinal()] = 9;
            } catch (java.lang.NoSuchFieldError unused9) {
            }
            int[] iArr2 = new int[org.bouncycastle.crypto.engines.ElephantEngine.ElephantParameters.values().length];
            a = iArr2;
            try {
                iArr2[org.bouncycastle.crypto.engines.ElephantEngine.ElephantParameters.elephant160.ordinal()] = 1;
            } catch (java.lang.NoSuchFieldError unused10) {
            }
            try {
                a[org.bouncycastle.crypto.engines.ElephantEngine.ElephantParameters.elephant176.ordinal()] = 2;
            } catch (java.lang.NoSuchFieldError unused11) {
            }
            try {
                a[org.bouncycastle.crypto.engines.ElephantEngine.ElephantParameters.elephant200.ordinal()] = 3;
            } catch (java.lang.NoSuchFieldError unused12) {
            }
        }
    }

    public enum ElephantParameters {
        elephant160,
        elephant176,
        elephant200
    }

    private enum State {
        Uninitialized,
        EncInit,
        EncAad,
        EncData,
        EncFinal,
        DecInit,
        DecAad,
        DecData,
        DecFinal
    }

    private void f(byte[] bArr, int i) {
        byte[] bArr2 = new byte[25];
        for (int i2 = 0; i2 < 5; i2++) {
            for (int i3 = 0; i3 < 5; i3++) {
                bArr2[i2] = (byte) (bArr2[i2] ^ bArr[i(i2, i3)]);
            }
        }
        int i4 = 0;
        while (i4 < 5) {
            int i5 = i4 + 1;
            bArr2[i4 + 5] = (byte) (bArr2[(i4 + 4) % 5] ^ g(bArr2[i5 % 5], 1));
            i4 = i5;
        }
        for (int i6 = 0; i6 < 5; i6++) {
            for (int i7 = 0; i7 < 5; i7++) {
                int i8 = i(i6, i7);
                bArr[i8] = (byte) (bArr[i8] ^ bArr2[i6 + 5]);
            }
        }
        for (int i9 = 0; i9 < 5; i9++) {
            for (int i10 = 0; i10 < 5; i10++) {
                bArr2[i(i9, i10)] = g(bArr[i(i9, i10)], this.H[i(i9, i10)]);
            }
        }
        for (int i11 = 0; i11 < 5; i11++) {
            for (int i12 = 0; i12 < 5; i12++) {
                bArr[i(i12, ((i11 * 2) + (i12 * 3)) % 5)] = bArr2[i(i11, i12)];
            }
        }
        for (int i13 = 0; i13 < 5; i13++) {
            int i14 = 0;
            while (i14 < 5) {
                int i15 = i14 + 1;
                bArr2[i14] = (byte) (bArr[i(i14, i13)] ^ ((~bArr[i(i15 % 5, i13)]) & bArr[i((i14 + 2) % 5, i13)]));
                i14 = i15;
            }
            for (int i16 = 0; i16 < 5; i16++) {
                bArr[i(i16, i13)] = bArr2[i16];
            }
        }
        bArr[0] = (byte) (this.G[i] ^ bArr[0]);
    }

    private byte g(byte b, int i) {
        int i2 = b;
        if (i != 0) {
            int i3 = b & 255;
            i2 = (i3 << i) ^ (i3 >>> (8 - i));
        }
        return (byte) i2;
    }

    private void h() {
        int i = org.bouncycastle.crypto.engines.ElephantEngine.AnonymousClass1.b[this.A.ordinal()];
        if (i == 3) {
            throw new java.lang.IllegalArgumentException(this.b + " cannot be reused for encryption");
        }
        if (i == 5) {
            throw new java.lang.IllegalArgumentException(this.b + " cannot process AAD when the length of the ciphertext to be processed exceeds the a block size");
        }
        if (i != 8) {
            return;
        }
        throw new java.lang.IllegalArgumentException(this.b + " cannot process AAD when the length of the plaintext to be processed exceeds the a block size");
    }

    private int i(int i, int i2) {
        return i + (i2 * 5);
    }

    private void j(byte[] bArr, byte[] bArr2) {
        int i = org.bouncycastle.crypto.engines.ElephantEngine.AnonymousClass1.a[this.h.ordinal()];
        if (i == 1) {
            int i2 = this.i - 1;
            byte b = bArr2[0];
            int i3 = (bArr2[3] & 255) << 7;
            int i4 = (bArr2[13] & 255) >>> 7;
            bArr[i2] = (byte) (i4 ^ (i3 ^ (((b & 255) >>> 5) | ((b & 255) << 3))));
        } else if (i == 2) {
            bArr[this.i - 1] = (byte) ((o(bArr2[0]) ^ ((bArr2[3] & 255) << 7)) ^ ((bArr2[19] & 255) >>> 7));
        } else if (i == 3) {
            bArr[this.i - 1] = (byte) ((bArr2[13] << 1) ^ (o(bArr2[0]) ^ o(bArr2[2])));
        }
        java.lang.System.arraycopy(bArr2, 1, bArr, 0, this.i - 1);
    }

    private void k(byte[] bArr) {
        int i;
        int i2 = org.bouncycastle.crypto.engines.ElephantEngine.AnonymousClass1.a[this.h.ordinal()];
        if (i2 != 1 && i2 != 2) {
            if (i2 != 3) {
                return;
            }
            for (int i3 = 0; i3 < this.l; i3++) {
                f(bArr, i3);
            }
            return;
        }
        byte b = this.m;
        byte[] bArr2 = new byte[this.k];
        for (int i4 = 0; i4 < this.l; i4++) {
            bArr[0] = (byte) (bArr[0] ^ b);
            int i5 = this.k - 1;
            int i6 = b & 32;
            int i7 = b & 64;
            bArr[i5] = (byte) (bArr[i5] ^ ((byte) (((((((((b & 1) << 7) | ((b & 2) << 5)) | ((b & 4) << 3)) | ((b & 8) << 1)) | ((b & 16) >>> 1)) | (i6 >>> 3)) | (i7 >>> 5)) | ((b & 128) >>> 7))));
            b = (byte) (((b << 1) | ((i7 >>> 6) ^ (i6 >>> 5))) & 127);
            for (int i8 = 0; i8 < this.k; i8++) {
                bArr[i8] = this.F[bArr[i8] & 255];
            }
            java.util.Arrays.fill(bArr2, (byte) 0);
            int i9 = 0;
            while (true) {
                i = this.k;
                if (i9 < i) {
                    for (int i10 = 0; i10 < 8; i10++) {
                        int i11 = (i9 << 3) + i10;
                        int i12 = this.j;
                        if (i11 != i12 - 1) {
                            i11 = ((i11 * i12) >> 2) % (i12 - 1);
                        }
                        int i13 = i11 >>> 3;
                        bArr2[i13] = (byte) (((((bArr[i9] & 255) >>> i10) & 1) << (i11 & 7)) ^ bArr2[i13]);
                    }
                    i9++;
                }
            }
            java.lang.System.arraycopy(bArr2, 0, bArr, 0, i);
        }
    }

    private int l() {
        byte[] byteArray = this.B.toByteArray();
        int i = org.bouncycastle.crypto.engines.ElephantEngine.AnonymousClass1.b[this.A.ordinal()];
        if (i == 6 || i == 9) {
            m(this.u);
        }
        return byteArray.length;
    }

    /* JADX WARN: Can't fix incorrect switch cases order, some code will duplicate */
    /* JADX WARN: Code duplicated, block: B:22:0x00a1  */
    /* JADX WARN: Code duplicated, block: B:24:0x00ac A[DONT_INVERT] */
    /* JADX WARN: Code duplicated, block: B:25:0x00ae  */
    /* JADX WARN: Code duplicated, block: B:28:0x00ca  */
    /* JADX WARN: Code duplicated, block: B:30:0x00cd A[RETURN] */
    /* JADX WARN: Code duplicated, block: B:31:0x00ce  */
    /* JADX WARN: Code duplicated, block: B:33:0x00d3  */
    private void m(byte[] bArr) {
        int i;
        org.bouncycastle.crypto.engines.ElephantEngine.State state;
        int i2;
        int i3;
        int i4;
        int i5;
        h();
        if (this.s == -1) {
            this.t = this.B.size();
            this.r = this.B.toByteArray();
            this.s = 0;
        }
        int[] iArr = org.bouncycastle.crypto.engines.ElephantEngine.AnonymousClass1.b;
        switch (iArr[this.A.ordinal()]) {
            case 3:
                throw new java.lang.IllegalArgumentException(this.b + " cannot be reused for encryption");
            case 4:
            case 7:
                if (this.s == this.t) {
                    java.util.Arrays.fill(bArr, 0, this.i, (byte) 0);
                    bArr[0] = 1;
                    return;
                }
                i = 0;
                i2 = this.i - i;
                int i6 = this.t;
                i3 = this.s;
                i4 = i6 - i3;
                if (i2 <= i4) {
                    java.lang.System.arraycopy(this.r, i3, bArr, i, i2);
                    this.s += i2;
                    return;
                }
                if (i4 > 0) {
                    java.lang.System.arraycopy(this.r, i3, bArr, i, i4);
                    this.s += i4;
                }
                int i7 = i4 + i;
                java.util.Arrays.fill(bArr, i7, i + i2, (byte) 0);
                bArr[i7] = 1;
                i5 = iArr[this.A.ordinal()];
                if (i5 != 4) {
                    this.A = org.bouncycastle.crypto.engines.ElephantEngine.State.EncData;
                    return;
                } else {
                    if (i5 != 7) {
                        return;
                    }
                    this.A = org.bouncycastle.crypto.engines.ElephantEngine.State.DecData;
                    return;
                }
            case 5:
                throw new java.lang.IllegalArgumentException(this.b + " cannot process AAD when the length of the ciphertext to be processed exceeds the a block size");
            case 6:
                java.lang.System.arraycopy(this.o, 0, this.w, 0, this.i);
                java.lang.System.arraycopy(this.n, 0, bArr, 0, this.d);
                i = this.d;
                state = org.bouncycastle.crypto.engines.ElephantEngine.State.EncAad;
                this.A = state;
                i2 = this.i - i;
                int i8 = this.t;
                i3 = this.s;
                i4 = i8 - i3;
                if (i2 <= i4) {
                    java.lang.System.arraycopy(this.r, i3, bArr, i, i2);
                    this.s += i2;
                    return;
                }
                if (i4 > 0) {
                    java.lang.System.arraycopy(this.r, i3, bArr, i, i4);
                    this.s += i4;
                }
                int i9 = i4 + i;
                java.util.Arrays.fill(bArr, i9, i + i2, (byte) 0);
                bArr[i9] = 1;
                i5 = iArr[this.A.ordinal()];
                if (i5 != 4) {
                    this.A = org.bouncycastle.crypto.engines.ElephantEngine.State.EncData;
                    return;
                } else {
                    if (i5 != 7) {
                        return;
                    }
                    this.A = org.bouncycastle.crypto.engines.ElephantEngine.State.DecData;
                    return;
                }
            case 8:
                throw new java.lang.IllegalArgumentException(this.b + " cannot process AAD when the length of the plaintext to be processed exceeds the a block size");
            case 9:
                java.lang.System.arraycopy(this.o, 0, this.w, 0, this.i);
                java.lang.System.arraycopy(this.n, 0, bArr, 0, this.d);
                i = this.d;
                state = org.bouncycastle.crypto.engines.ElephantEngine.State.DecAad;
                this.A = state;
                i2 = this.i - i;
                int i10 = this.t;
                i3 = this.s;
                i4 = i10 - i3;
                if (i2 <= i4) {
                    java.lang.System.arraycopy(this.r, i3, bArr, i, i2);
                    this.s += i2;
                    return;
                }
                if (i4 > 0) {
                    java.lang.System.arraycopy(this.r, i3, bArr, i, i4);
                    this.s += i4;
                }
                int i11 = i4 + i;
                java.util.Arrays.fill(bArr, i11, i + i2, (byte) 0);
                bArr[i11] = 1;
                i5 = iArr[this.A.ordinal()];
                if (i5 != 4) {
                    this.A = org.bouncycastle.crypto.engines.ElephantEngine.State.EncData;
                    return;
                } else {
                    if (i5 != 7) {
                        return;
                    }
                    this.A = org.bouncycastle.crypto.engines.ElephantEngine.State.DecData;
                    return;
                }
            default:
                i = 0;
                i2 = this.i - i;
                int i12 = this.t;
                i3 = this.s;
                i4 = i12 - i3;
                if (i2 <= i4) {
                    java.lang.System.arraycopy(this.r, i3, bArr, i, i2);
                    this.s += i2;
                    return;
                }
                if (i4 > 0) {
                    java.lang.System.arraycopy(this.r, i3, bArr, i, i4);
                    this.s += i4;
                }
                int i13 = i4 + i;
                java.util.Arrays.fill(bArr, i13, i + i2, (byte) 0);
                bArr[i13] = 1;
                i5 = iArr[this.A.ordinal()];
                if (i5 != 4) {
                    this.A = org.bouncycastle.crypto.engines.ElephantEngine.State.EncData;
                    return;
                } else {
                    if (i5 != 7) {
                        return;
                    }
                    this.A = org.bouncycastle.crypto.engines.ElephantEngine.State.DecData;
                    return;
                }
        }
    }

    private int n(byte[] bArr, byte[] bArr2, int i, int i2, int i3, int i4, int i5, int i6, boolean z) {
        byte[] bArr3 = new byte[this.i];
        int i7 = this.q;
        int i8 = 0;
        int i9 = i;
        while (i7 < i2) {
            int i10 = i7 == i3 + (-1) ? i5 - (this.i * i7) : this.i;
            if (!z) {
                int i11 = this.i;
                if (i5 <= i7 * i11 || i10 % i11 != 0) {
                    break;
                }
            }
            j(this.x, this.w);
            if (i7 < i3) {
                java.lang.System.arraycopy(this.n, 0, this.y, 0, this.d);
                java.util.Arrays.fill(this.y, this.d, this.i, (byte) 0);
                p(this.y, this.w, 0, this.i);
                p(this.y, this.x, 0, this.i);
                k(this.y);
                p(this.y, this.w, 0, this.i);
                p(this.y, this.x, 0, this.i);
                p(this.y, bArr, i8, i10);
                java.lang.System.arraycopy(this.y, 0, bArr2, i9, i10);
                if (this.a) {
                    java.lang.System.arraycopy(this.y, 0, bArr3, 0, i10);
                } else {
                    java.lang.System.arraycopy(bArr, i8, bArr3, 0, i10);
                }
                i9 += i10;
                i8 += i10;
            }
            if (i7 > 0 && i7 <= i4) {
                int i12 = this.i;
                int i13 = (i7 - 1) * i12;
                if (i13 == i5) {
                    java.util.Arrays.fill(this.y, 0, i12, (byte) 0);
                    this.y[0] = 1;
                } else {
                    int i14 = i5 - i13;
                    if (i12 <= i14) {
                        java.lang.System.arraycopy(this.z, 0, this.y, 0, i12);
                    } else if (i14 > 0) {
                        java.lang.System.arraycopy(this.z, 0, this.y, 0, i14);
                        java.util.Arrays.fill(this.y, i14, this.i, (byte) 0);
                        this.y[i14] = 1;
                    }
                }
                p(this.y, this.v, 0, this.i);
                p(this.y, this.x, 0, this.i);
                k(this.y);
                p(this.y, this.v, 0, this.i);
                p(this.y, this.x, 0, this.i);
                p(this.u, this.y, 0, this.i);
            }
            i7++;
            if (i7 < i6) {
                m(this.y);
                p(this.y, this.x, 0, this.i);
                k(this.y);
                p(this.y, this.x, 0, this.i);
                p(this.u, this.y, 0, this.i);
            }
            byte[] bArr4 = this.v;
            this.v = this.w;
            this.w = this.x;
            this.x = bArr4;
            java.lang.System.arraycopy(bArr3, 0, this.z, 0, this.i);
        }
        this.q = i7;
        return i8;
    }

    private byte o(byte b) {
        int i = b & 255;
        return (byte) ((i >>> 7) | (i << 1));
    }

    private void p(byte[] bArr, byte[] bArr2, int i, int i2) {
        for (int i3 = 0; i3 < i2; i3++) {
            bArr[i3] = (byte) (bArr[i3] ^ bArr2[i3 + i]);
        }
    }

    @Override // org.bouncycastle.crypto.engines.AEADBaseEngine
    protected void a(byte[] bArr, byte[] bArr2) {
        this.n = bArr2;
        byte[] bArr3 = new byte[this.i];
        this.o = bArr3;
        java.lang.System.arraycopy(bArr, 0, bArr3, 0, this.c);
        k(this.o);
        this.p = true;
        boolean z = this.a;
        this.A = z ? org.bouncycastle.crypto.engines.ElephantEngine.State.EncInit : org.bouncycastle.crypto.engines.ElephantEngine.State.DecInit;
        this.D = new byte[(this.i * 2) + (z ? 0 : this.e)];
        e(false);
    }

    @Override // org.bouncycastle.crypto.engines.AEADBaseEngine, org.bouncycastle.crypto.modes.AEADCipher
    public /* bridge */ /* synthetic */ byte[] b() {
        return super.b();
    }

    @Override // org.bouncycastle.crypto.modes.AEADCipher
    public void c(byte[] bArr, int i, int i2) {
        if (i + i2 > bArr.length) {
            throw new org.bouncycastle.crypto.DataLengthException("input buffer too short");
        }
        this.B.write(bArr, i, i2);
    }

    @Override // org.bouncycastle.crypto.modes.AEADCipher
    public int doFinal(byte[] bArr, int i) {
        if (!this.p) {
            throw new java.lang.IllegalArgumentException(this.b + " needs call init function before doFinal");
        }
        int i2 = this.C;
        boolean z = this.a;
        if ((z && i2 + i + this.e > bArr.length) || (!z && (i2 + i) - this.e > bArr.length)) {
            throw new org.bouncycastle.crypto.OutputLengthException("output buffer is too short");
        }
        int i3 = this.E;
        int i4 = (i2 + i3) - (z ? 0 : this.e);
        int i5 = i4 - i3;
        int iL = l();
        int i6 = this.i;
        int i7 = i4 / i6;
        int i8 = i7 + 1;
        int i9 = i4 % i6 != 0 ? i8 : i7;
        int i10 = (this.d + iL) / i6;
        int iN = n(this.D, bArr, i, java.lang.Math.max(i7 + 2, i10), i9, i8, i4, i10 + 1, true) + i;
        this.g = new byte[this.e];
        p(this.u, this.o, 0, this.i);
        k(this.u);
        p(this.u, this.o, 0, this.i);
        if (this.a) {
            java.lang.System.arraycopy(this.u, 0, this.g, 0, this.e);
            byte[] bArr2 = this.g;
            java.lang.System.arraycopy(bArr2, 0, bArr, iN, bArr2.length);
            i5 += this.e;
        } else {
            this.C -= this.e;
            for (int i11 = 0; i11 < this.e; i11++) {
                if (this.u[i11] != this.D[this.C + i11]) {
                    throw new java.lang.IllegalArgumentException("Mac does not match");
                }
            }
        }
        e(false);
        return i5;
    }

    @Override // org.bouncycastle.crypto.engines.AEADBaseEngine
    protected void e(boolean z) {
        this.B.reset();
        java.util.Arrays.fill(this.u, (byte) 0);
        java.util.Arrays.fill(this.z, (byte) 0);
        this.C = 0;
        this.q = 0;
        this.s = -1;
        this.E = 0;
        super.e(z);
    }

    @Override // org.bouncycastle.crypto.engines.AEADBaseEngine, org.bouncycastle.crypto.modes.AEADCipher
    public /* bridge */ /* synthetic */ java.lang.String getAlgorithmName() {
        return super.getAlgorithmName();
    }

    @Override // org.bouncycastle.crypto.modes.AEADCipher
    public int getOutputSize(int i) {
        switch (org.bouncycastle.crypto.engines.ElephantEngine.AnonymousClass1.b[this.A.ordinal()]) {
            case 1:
                throw new java.lang.IllegalArgumentException(this.b + " needs call init function before getUpdateOutputSize");
            case 2:
            case 3:
                return 0;
            case 4:
            case 5:
            case 6:
                return i + this.C + this.e;
            default:
                return java.lang.Math.max(0, (i + this.C) - this.e);
        }
    }

    @Override // org.bouncycastle.crypto.modes.AEADCipher
    public int getUpdateOutputSize(int i) {
        switch (org.bouncycastle.crypto.engines.ElephantEngine.AnonymousClass1.b[this.A.ordinal()]) {
            case 1:
                throw new java.lang.IllegalArgumentException(this.b + " needs call init function before getUpdateOutputSize");
            case 2:
            case 3:
                return 0;
            case 4:
            case 5:
            case 6:
                int i2 = this.C + i;
                return i2 - (i2 % this.i);
            case 7:
            case 8:
            case 9:
                int iMax = java.lang.Math.max(0, (this.C + i) - this.e);
                return iMax - (iMax % this.i);
            default:
                return java.lang.Math.max(0, (i + this.C) - this.e);
        }
    }

    @Override // org.bouncycastle.crypto.engines.AEADBaseEngine, org.bouncycastle.crypto.modes.AEADCipher
    public /* bridge */ /* synthetic */ void init(boolean z, org.bouncycastle.crypto.CipherParameters cipherParameters) {
        super.init(z, cipherParameters);
    }

    @Override // org.bouncycastle.crypto.engines.AEADBaseEngine, org.bouncycastle.crypto.modes.AEADCipher
    public /* bridge */ /* synthetic */ int processByte(byte b, byte[] bArr, int i) {
        return super.processByte(b, bArr, i);
    }

    @Override // org.bouncycastle.crypto.modes.AEADCipher
    public int processBytes(byte[] bArr, int i, int i2, byte[] bArr2, int i3) {
        if (i + i2 > bArr.length) {
            throw new org.bouncycastle.crypto.DataLengthException("input buffer too short");
        }
        int i4 = this.C;
        int i5 = i4 + i2;
        boolean z = this.a;
        if (i5 - (z ? 0 : this.e) < this.i) {
            java.lang.System.arraycopy(bArr, i, this.D, i4, i2);
            this.C += i2;
            return 0;
        }
        int i6 = ((i4 + this.E) + i2) - (z ? 0 : this.e);
        int iL = l();
        int i7 = this.i;
        int i8 = i6 / i7;
        int i9 = i8 + 1;
        int i10 = i6 % i7 != 0 ? i9 : i8;
        int i11 = (this.d + iL) / i7;
        int i12 = i11 + 1;
        int iMax = java.lang.Math.max(i8 + 2, i11);
        int iMax2 = java.lang.Math.max(i9, 1) * this.i;
        byte[] bArr3 = new byte[iMax2];
        java.lang.System.arraycopy(this.D, 0, bArr3, 0, this.C);
        int i13 = this.C;
        java.lang.System.arraycopy(bArr, i, bArr3, i13, java.lang.Math.min(i2, iMax2 - i13));
        int iN = n(bArr3, bArr2, i3, iMax, i10, i9, i6, i12, false);
        int i14 = this.C;
        int i15 = iN - i14;
        if (i15 >= 0) {
            int i16 = (i14 + i2) - iN;
            this.C = i16;
            java.lang.System.arraycopy(bArr, i15 + i, this.D, 0, i16);
        } else {
            byte[] bArr4 = this.D;
            int i17 = -i15;
            java.lang.System.arraycopy(bArr4, i14 + i15, bArr4, 0, i17);
            java.lang.System.arraycopy(bArr, i, this.D, i17, i2);
            this.C = i2 - i15;
        }
        this.E += iN;
        return iN;
    }
}
