package p421.p433.p434.p435;

import java.util.Random;
import net.lingala.zip4j.exception.ZipException;
import p138.p176.p177.p242.p246.p251.C4303;
import p421.p433.p434.p435.p436.C6776;
import p421.p433.p434.p435.p436.C6777;
import p421.p433.p434.p435.p436.C6778;
import p421.p433.p434.p435.p437.C6781;
import p421.p433.p434.p442.p443.EnumC6831;

/* JADX INFO: renamed from: ޏ.ؠ.֏.ؠ.ؠ, reason: contains not printable characters */
/* JADX INFO: loaded from: classes.dex */
public class C6773 implements InterfaceC6775 {

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public char[] f19580;

    /* JADX INFO: renamed from: ؠ, reason: contains not printable characters */
    public EnumC6831 f19581;

    /* JADX INFO: renamed from: ހ, reason: contains not printable characters */
    public C6781 f19582;

    /* JADX INFO: renamed from: ށ, reason: contains not printable characters */
    public C6776 f19583;

    /* JADX INFO: renamed from: ނ, reason: contains not printable characters */
    public boolean f19584;

    /* JADX INFO: renamed from: ރ, reason: contains not printable characters */
    public int f19585 = 1;

    /* JADX INFO: renamed from: ބ, reason: contains not printable characters */
    public int f19586 = 0;

    /* JADX INFO: renamed from: ޅ, reason: contains not printable characters */
    public byte[] f19587;

    /* JADX INFO: renamed from: ކ, reason: contains not printable characters */
    public byte[] f19588;

    /* JADX INFO: renamed from: އ, reason: contains not printable characters */
    public byte[] f19589;

    /* JADX INFO: renamed from: ވ, reason: contains not printable characters */
    public byte[] f19590;

    public C6773(char[] cArr, EnumC6831 enumC6831) throws ZipException {
        if (cArr == null || cArr.length == 0) {
            throw new ZipException("input password is empty or null");
        }
        if (enumC6831 != EnumC6831.KEY_STRENGTH_128 && enumC6831 != EnumC6831.KEY_STRENGTH_256) {
            throw new ZipException("Invalid AES key strength");
        }
        this.f19580 = cArr;
        this.f19581 = enumC6831;
        this.f19584 = false;
        this.f19588 = new byte[16];
        this.f19587 = new byte[16];
        int i = enumC6831.f19818;
        int i2 = enumC6831.f19817;
        int i3 = enumC6831.f19816;
        if (i3 != 8 && i3 != 16) {
            throw new ZipException("invalid salt size, cannot generate salt");
        }
        int i4 = i3 == 16 ? 4 : i3 == 8 ? 2 : 0;
        byte[] bArr = new byte[i3];
        for (int i5 = 0; i5 < i4; i5++) {
            int iNextInt = new Random().nextInt();
            int i6 = i5 * 4;
            bArr[i6 + 0] = (byte) (iNextInt >> 24);
            bArr[i6 + 1] = (byte) (iNextInt >> 16);
            bArr[i6 + 2] = (byte) (iNextInt >> 8);
            bArr[i6 + 3] = (byte) iNextInt;
        }
        this.f19590 = bArr;
        try {
            int i7 = i + i2;
            int i8 = i7 + 2;
            byte[] bArrM9935 = new C6777(new C6778("HmacSHA1", "ISO-8859-1", bArr, 1000)).m9935(this.f19580, i8);
            if (bArrM9935.length != i8) {
                throw new ZipException("invalid key generated, cannot decrypt file");
            }
            byte[] bArr2 = new byte[i];
            byte[] bArr3 = new byte[i2];
            this.f19589 = new byte[2];
            System.arraycopy(bArrM9935, 0, bArr2, 0, i);
            System.arraycopy(bArrM9935, i, bArr3, 0, i2);
            System.arraycopy(bArrM9935, i7, this.f19589, 0, 2);
            this.f19582 = new C6781(bArr2);
            C6776 c6776 = new C6776("HmacSHA1");
            this.f19583 = c6776;
            c6776.m9934(bArr3);
        } catch (Exception e) {
            throw new ZipException(e);
        }
    }

    @Override // p421.p433.p434.p435.InterfaceC6775
    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public int mo9933(byte[] bArr, int i, int i2) throws ZipException {
        int i3;
        if (this.f19584) {
            throw new ZipException("AES Encrypter is in finished state (A non 16 byte block has already been passed to encrypter)");
        }
        if (i2 % 16 != 0) {
            this.f19584 = true;
        }
        int i4 = i;
        while (true) {
            int i5 = i + i2;
            if (i4 >= i5) {
                return i2;
            }
            int i6 = i4 + 16;
            this.f19586 = i6 <= i5 ? 16 : i5 - i4;
            C4303.m7166(this.f19587, this.f19585);
            this.f19582.m9938(this.f19587, this.f19588);
            int i7 = 0;
            while (true) {
                i3 = this.f19586;
                if (i7 >= i3) {
                    break;
                }
                int i8 = i4 + i7;
                bArr[i8] = (byte) (bArr[i8] ^ this.f19588[i7]);
                i7++;
            }
            C6776 c6776 = this.f19583;
            if (c6776 == null) {
                throw null;
            }
            try {
                c6776.f19591.update(bArr, i4, i3);
                this.f19585++;
                i4 = i6;
            } catch (IllegalStateException e) {
                throw new RuntimeException(e);
            }
        }
    }
}
