package p138.p176.p278.p279.p290;

import java.security.GeneralSecurityException;
import java.security.InvalidKeyException;
import java.util.Arrays;
import java.util.Collection;
import javax.crypto.AEADBadTagException;
import javax.crypto.Cipher;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;
import p138.p139.p143.p144.C2803;
import p138.p176.p177.p242.p246.p251.C4303;
import p138.p176.p278.p279.InterfaceC5179;

/* JADX INFO: renamed from: ދ.ހ.ހ.֏.ޞ.ބ, reason: contains not printable characters */
/* JADX INFO: loaded from: classes.dex */
public final class C5505 implements InterfaceC5179 {

    /* JADX INFO: renamed from: ހ, reason: contains not printable characters */
    public static final Collection<Integer> f15868 = Arrays.asList(64);

    /* JADX INFO: renamed from: ށ, reason: contains not printable characters */
    public static final byte[] f15869 = new byte[16];

    /* JADX INFO: renamed from: ނ, reason: contains not printable characters */
    public static final byte[] f15870 = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1};

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public final C5499 f15871;

    /* JADX INFO: renamed from: ؠ, reason: contains not printable characters */
    public final byte[] f15872;

    public C5505(byte[] bArr) throws InvalidKeyException {
        if (!f15868.contains(Integer.valueOf(bArr.length))) {
            throw new InvalidKeyException(C2803.m4882(C2803.m4889("invalid key size: "), bArr.length, " bytes; key must have 64 bytes"));
        }
        byte[] bArrCopyOfRange = Arrays.copyOfRange(bArr, 0, bArr.length / 2);
        this.f15872 = Arrays.copyOfRange(bArr, bArr.length / 2, bArr.length);
        this.f15871 = new C5499(bArrCopyOfRange, 16);
    }

    @Override // p138.p176.p278.p279.InterfaceC5179
    /* JADX INFO: renamed from: ֏ */
    public byte[] mo8651(byte[] bArr, byte[] bArr2) throws GeneralSecurityException {
        if (bArr.length > 2147483631) {
            throw new GeneralSecurityException("plaintext too long");
        }
        Cipher cipherM8904 = C5534.f15933.m8904("AES/CTR/NoPadding");
        byte[] bArrM8873 = m8873(bArr2, bArr);
        byte[] bArr3 = (byte[]) bArrM8873.clone();
        bArr3[8] = (byte) (bArr3[8] & 127);
        bArr3[12] = (byte) (bArr3[12] & 127);
        cipherM8904.init(1, new SecretKeySpec(this.f15872, "AES"), new IvParameterSpec(bArr3));
        return C4303.m7144(bArrM8873, cipherM8904.doFinal(bArr));
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public final byte[] m8873(byte[]... bArr) {
        byte[] bArrM7187;
        if (bArr.length == 0) {
            return this.f15871.mo8680(f15870);
        }
        byte[] bArrMo8680 = this.f15871.mo8680(f15869);
        for (int i = 0; i < bArr.length - 1; i++) {
            bArrMo8680 = C4303.m7187(C4303.m7173(bArrMo8680), this.f15871.mo8680(bArr[i]));
        }
        byte[] bArr2 = bArr[bArr.length - 1];
        if (bArr2.length < 16) {
            bArrM7187 = C4303.m7187(C4303.m7141(bArr2), C4303.m7173(bArrMo8680));
        } else {
            if (bArr2.length < bArrMo8680.length) {
                throw new IllegalArgumentException("xorEnd requires a.length >= b.length");
            }
            int length = bArr2.length - bArrMo8680.length;
            bArrM7187 = Arrays.copyOf(bArr2, bArr2.length);
            for (int i2 = 0; i2 < bArrMo8680.length; i2++) {
                int i3 = length + i2;
                bArrM7187[i3] = (byte) (bArrM7187[i3] ^ bArrMo8680[i2]);
            }
        }
        return this.f15871.mo8680(bArrM7187);
    }

    @Override // p138.p176.p278.p279.InterfaceC5179
    /* JADX INFO: renamed from: ؠ */
    public byte[] mo8652(byte[] bArr, byte[] bArr2) throws GeneralSecurityException {
        if (bArr.length < 16) {
            throw new GeneralSecurityException("Ciphertext too short.");
        }
        Cipher cipherM8904 = C5534.f15933.m8904("AES/CTR/NoPadding");
        byte[] bArrCopyOfRange = Arrays.copyOfRange(bArr, 0, 16);
        byte[] bArr3 = (byte[]) bArrCopyOfRange.clone();
        bArr3[8] = (byte) (bArr3[8] & 127);
        bArr3[12] = (byte) (bArr3[12] & 127);
        cipherM8904.init(2, new SecretKeySpec(this.f15872, "AES"), new IvParameterSpec(bArr3));
        byte[] bArrCopyOfRange2 = Arrays.copyOfRange(bArr, 16, bArr.length);
        byte[] bArrDoFinal = cipherM8904.doFinal(bArrCopyOfRange2);
        if (bArrCopyOfRange2.length == 0 && bArrDoFinal == null && C4303.m7167()) {
            bArrDoFinal = new byte[0];
        }
        if (C4303.m7172(bArrCopyOfRange, m8873(bArr2, bArrDoFinal))) {
            return bArrDoFinal;
        }
        throw new AEADBadTagException("Integrity check failed.");
    }
}
