package defpackage;

import com.hierynomus.security.SecurityException;
import java.security.InvalidKeyException;
import javax.crypto.BadPaddingException;
import javax.crypto.Cipher;
import javax.crypto.IllegalBlockSizeException;
import javax.crypto.ShortBufferException;
import javax.crypto.spec.SecretKeySpec;
import org.bouncycastle.crypto.DataLengthException;
import org.bouncycastle.crypto.InvalidCipherTextException;
import org.bouncycastle.crypto.OutputLengthException;

/* JADX INFO: renamed from: ˈʣᵰ, reason: contains not printable characters */
/* JADX INFO: loaded from: classes3.dex */
public final class C1022 {

    /* JADX INFO: renamed from: ʽˈˋ, reason: contains not printable characters */
    public Object f4448;

    /* JADX INFO: renamed from: ᵲᵶᵳˈ, reason: contains not printable characters */
    public final /* synthetic */ int f4449;

    public /* synthetic */ C1022(int i) {
        this.f4449 = i;
    }

    /* JADX INFO: renamed from: ʽˈˋ, reason: contains not printable characters */
    public final void m3382(byte[] bArr) throws SecurityException {
        switch (this.f4449) {
            case 0:
                C1886 c1886 = (C1886) this.f4448;
                int length = bArr.length;
                byte[] bArr2 = new byte[length];
                System.arraycopy(bArr, 0, bArr2, 0, length);
                if (ᵸˊʾᵜ.ˌᴵ(0, bArr)) {
                    ᵕᵩʽᵲ.ᵮᵣᵗˈ("attempt to create weak DES key");
                    return;
                }
                int length2 = bArr.length;
                for (int i = 0; i < length2; i += 8) {
                    if (ᵸˊʾᵜ.ˌᴵ(i, bArr)) {
                        ᵕᵩʽᵲ.ᵮᵣᵗˈ("attempt to create weak DESede key");
                        return;
                    }
                }
                c1886.m5121();
                ᵟˑʽ r14 = (ᵟˑʽ) c1886.f7484;
                if (length > 8) {
                    ᵕᵩʽᵲ.ᵮᵣᵗˈ("DES key too long - should be 8 bytes");
                    return;
                }
                int[] iArr = ᵟˑʽ.ᵨᵼⁱ;
                byte[] bArr3 = ᵟˑʽ.ᵶˇᵱ;
                int[] iArr2 = new int[32];
                boolean[] zArr = new boolean[56];
                boolean[] zArr2 = new boolean[56];
                for (int i2 = 0; i2 < 56; i2++) {
                    byte b = ᵟˑʽ.ᵯᵷʽ[i2];
                    zArr[i2] = (ᵟˑʽ.ᵔᵖᵹᵫ[b & 7] & bArr2[b >>> 3]) != 0;
                }
                for (int i3 = 0; i3 < 16; i3++) {
                    int i4 = i3 << 1;
                    int i5 = i4 + 1;
                    iArr2[i5] = 0;
                    iArr2[i4] = 0;
                    int i6 = 0;
                    while (true) {
                        if (i6 < 28) {
                            int i7 = bArr3[i3] + i6;
                            if (i7 < 28) {
                                zArr2[i6] = zArr[i7];
                            } else {
                                zArr2[i6] = zArr[i7 - 28];
                            }
                            i6++;
                        } else {
                            for (int i8 = 28; i8 < 56; i8++) {
                                int i9 = bArr3[i3] + i8;
                                if (i9 < 56) {
                                    zArr2[i8] = zArr[i9];
                                } else {
                                    zArr2[i8] = zArr[i9 - 28];
                                }
                            }
                            for (int i10 = 0; i10 < 24; i10++) {
                                byte[] bArr4 = ᵟˑʽ.ˈᵲᵢ;
                                if (zArr2[bArr4[i10]]) {
                                    iArr2[i4] = iArr2[i4] | iArr[i10];
                                }
                                if (zArr2[bArr4[i10 + 24]]) {
                                    iArr2[i5] = iArr2[i5] | iArr[i10];
                                }
                            }
                        }
                    }
                }
                for (int i11 = 0; i11 != 32; i11 += 2) {
                    int i12 = iArr2[i11];
                    int i13 = i11 + 1;
                    int i14 = iArr2[i13];
                    iArr2[i11] = ((16515072 & i14) >>> 10) | ((i12 & 16515072) << 6) | ((i12 & 4032) << 10) | ((i14 & 4032) >>> 6);
                    iArr2[i13] = ((i12 & 63) << 16) | ((i12 & 258048) << 12) | ((258048 & i14) >>> 4) | (i14 & 63);
                }
                r14.ˌᴵ = iArr2;
                return;
            case 1:
                C4177 c4177 = (C4177) this.f4448;
                int length3 = bArr.length;
                byte[] bArr5 = new byte[length3];
                System.arraycopy(bArr, 0, bArr5, 0, length3);
                c4177.f15935 = bArr5;
                c4177.m9115(bArr5);
                return;
            default:
                Cipher cipher = (Cipher) this.f4448;
                try {
                    cipher.init(1, new SecretKeySpec(bArr, cipher.getAlgorithm().split("/")[0]));
                    return;
                } catch (InvalidKeyException e) {
                    throw new SecurityException(e);
                }
        }
    }

    /* JADX INFO: renamed from: ːˏᵟᵯ, reason: contains not printable characters */
    public final int m3383(int i, byte[] bArr, byte[] bArr2) throws SecurityException {
        int i2;
        int i3;
        switch (this.f4449) {
            case 0:
                C1886 c1886 = (C1886) this.f4448;
                ᵟˑʽ r9 = (ᵟˑʽ) c1886.f7484;
                byte[] bArr3 = (byte[]) c1886.f7482;
                if (i < 0) {
                    ᵕᵩʽᵲ.ᵮᵣᵗˈ("Can't have a negative input length!");
                    return 0;
                }
                int i4 = c1886.f7481;
                int i5 = i + i4;
                int length = i5 - (i5 % bArr3.length);
                if (length > 0 && length > bArr2.length) {
                    throw new OutputLengthException("output buffer too short");
                }
                int length2 = bArr3.length - i4;
                if (i > length2) {
                    System.arraycopy(bArr, 0, bArr3, i4, length2);
                    r9.ˋˈ(0, 0, bArr3, bArr2);
                    c1886.f7481 = 0;
                    i2 = i - length2;
                    i3 = 8;
                    while (i2 > bArr3.length) {
                        r9.ˋˈ(length2, i3, bArr, bArr2);
                        i3 += 8;
                        i2 -= 8;
                        length2 += 8;
                    }
                } else {
                    length2 = 0;
                    i2 = i;
                    i3 = 0;
                }
                System.arraycopy(bArr, length2, bArr3, c1886.f7481, i2);
                int i6 = c1886.f7481 + i2;
                c1886.f7481 = i6;
                if (i6 == bArr3.length) {
                    r9.ˋˈ(0, i3, bArr3, bArr2);
                    i3 += 8;
                    c1886.f7481 = 0;
                }
                return i3;
            case 1:
                C4177 c4177 = (C4177) this.f4448;
                if (i > bArr.length) {
                    throw new DataLengthException("input buffer too short");
                }
                if (i > bArr2.length) {
                    throw new OutputLengthException("output buffer too short");
                }
                for (int i7 = 0; i7 < i; i7++) {
                    int i8 = (c4177.f15932 + 1) & 255;
                    c4177.f15932 = i8;
                    byte[] bArr4 = c4177.f15934;
                    byte b = bArr4[i8];
                    int i9 = (c4177.f15933 + b) & 255;
                    c4177.f15933 = i9;
                    bArr4[i8] = bArr4[i9];
                    bArr4[i9] = b;
                    bArr2[i7] = (byte) (bArr4[(bArr4[i8] + b) & 255] ^ bArr[i7]);
                }
                return i;
            default:
                try {
                    return ((Cipher) this.f4448).update(bArr, 0, i, bArr2, 0);
                } catch (ShortBufferException e) {
                    throw new SecurityException(e);
                }
        }
    }

    /* JADX INFO: renamed from: ᵲᵶᵳˈ, reason: contains not printable characters */
    public final int m3384(int i, byte[] bArr) throws SecurityException {
        switch (this.f4449) {
            case 0:
                try {
                    return ((C1886) this.f4448).m5120(i, bArr);
                } catch (InvalidCipherTextException e) {
                    throw new SecurityException(e);
                }
            case 1:
                C4177 c4177 = (C4177) this.f4448;
                c4177.m9115(c4177.f15935);
                return 0;
            default:
                try {
                    try {
                        return ((Cipher) this.f4448).doFinal(bArr, i);
                    } catch (BadPaddingException | IllegalBlockSizeException | ShortBufferException e2) {
                        e = e2;
                        throw new SecurityException(e);
                    }
                } catch (IllegalBlockSizeException e3) {
                    e = e3;
                    throw new SecurityException(e);
                } catch (ShortBufferException e4) {
                    e = e4;
                    throw new SecurityException(e);
                }
        }
    }
}
