package defpackage;

import java.security.GeneralSecurityException;
import java.util.Arrays;
import javax.crypto.AEADBadTagException;
import javax.crypto.Cipher;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;

/* JADX INFO: renamed from: ᵜˈˎʢ, reason: contains not printable characters */
/* JADX INFO: loaded from: classes3.dex */
public final class C2848 implements InterfaceC5579 {

    /* JADX INFO: renamed from: ᵨᵣ, reason: contains not printable characters */
    public static final C0140 f10929 = new C0140(1);

    /* JADX INFO: renamed from: ʽˈˋ, reason: contains not printable characters */
    public final InterfaceC2925 f10930;

    /* JADX INFO: renamed from: ːˏᵟᵯ, reason: contains not printable characters */
    public final SecretKeySpec f10931;

    /* JADX INFO: renamed from: ᵲᵶᵳˈ, reason: contains not printable characters */
    public final byte[] f10932;

    /* JADX INFO: renamed from: ᵷᵺʾᵖ, reason: contains not printable characters */
    public final int f10933;

    public C2848(int i, byte[] bArr, byte[] bArr2) throws GeneralSecurityException {
        if (!AbstractC2704.m6538(1)) {
            C1685.m4558("Can not use AES-EAX in FIPS-mode.");
            throw null;
        }
        if (i != 12 && i != 16) {
            ᵕᵩʽᵲ.ᵮᵣᵗˈ("IV size should be either 12 or 16 bytes");
            throw null;
        }
        this.f10933 = i;
        AbstractC1792.m4941(bArr.length);
        this.f10931 = new SecretKeySpec(bArr, "AES");
        this.f10930 = ˌᵨʽʙ.ᵮᵣᵗˈ(C5537.m11158(C0429.m1828(bArr.length), new ʽˎˇˌ(21, C2855.m6836(bArr))));
        this.f10932 = bArr2;
    }

    @Override // defpackage.InterfaceC5579
    /* JADX INFO: renamed from: ʽˈˋ */
    public final byte[] mo1207(byte[] bArr, byte[] bArr2) throws GeneralSecurityException {
        int length = bArr.length;
        byte[] bArr3 = this.f10932;
        int length2 = length - bArr3.length;
        int i = this.f10933;
        int i2 = (length2 - i) - 16;
        if (i2 < 0) {
            C1685.m4558("ciphertext too short");
            return null;
        }
        if (!AbstractC0184.m1341(bArr3, bArr)) {
            C1685.m4558("Decryption failed (OutputPrefix mismatch).");
            return null;
        }
        byte[] bArrM6828 = m6828(0, bArr3.length, i, bArr);
        if (bArr2 == null) {
            bArr2 = new byte[0];
        }
        byte[] bArrM68282 = m6828(1, 0, bArr2.length, bArr2);
        byte[] bArrM68283 = m6828(2, bArr3.length + i, i2, bArr);
        int length3 = bArr.length - 16;
        byte b = 0;
        for (int i3 = 0; i3 < 16; i3++) {
            b = (byte) (b | (((bArr[length3 + i3] ^ bArrM68282[i3]) ^ bArrM6828[i3]) ^ bArrM68283[i3]));
        }
        if (b != 0) {
            throw new AEADBadTagException("tag mismatch");
        }
        Cipher cipher = (Cipher) f10929.get();
        cipher.init(1, this.f10931, new IvParameterSpec(bArrM6828));
        return cipher.doFinal(bArr, bArr3.length + i, i2);
    }

    /* JADX INFO: renamed from: ːˏᵟᵯ, reason: contains not printable characters */
    public final byte[] m6828(int i, int i2, int i3, byte[] bArr) {
        byte[] bArr2 = new byte[i3 + 16];
        bArr2[15] = (byte) i;
        System.arraycopy(bArr, i2, bArr2, 16, i3);
        return this.f10930.mo4740(16, bArr2);
    }

    @Override // defpackage.InterfaceC5579
    /* JADX INFO: renamed from: ᵲᵶᵳˈ */
    public final byte[] mo1208(byte[] bArr, byte[] bArr2) throws GeneralSecurityException {
        int length = bArr.length;
        byte[] bArr3 = this.f10932;
        int length2 = Integer.MAX_VALUE - bArr3.length;
        int i = this.f10933;
        if (length > (length2 - i) - 16) {
            C1685.m4558("plaintext too long");
            return null;
        }
        byte[] bArrCopyOf = Arrays.copyOf(bArr3, bArr3.length + i + bArr.length + 16);
        byte[] bArrM5643 = AbstractC2133.m5643(i);
        System.arraycopy(bArrM5643, 0, bArrCopyOf, bArr3.length, i);
        byte[] bArrM6828 = m6828(0, 0, bArrM5643.length, bArrM5643);
        if (bArr2 == null) {
            bArr2 = new byte[0];
        }
        byte[] bArrM68282 = m6828(1, 0, bArr2.length, bArr2);
        Cipher cipher = (Cipher) f10929.get();
        cipher.init(1, this.f10931, new IvParameterSpec(bArrM6828));
        cipher.doFinal(bArr, 0, bArr.length, bArrCopyOf, bArr3.length + i);
        byte[] bArrM68283 = m6828(2, bArr3.length + i, bArr.length, bArrCopyOf);
        int length3 = bArr3.length + bArr.length + i;
        for (int i2 = 0; i2 < 16; i2++) {
            bArrCopyOf[length3 + i2] = (byte) ((bArrM68282[i2] ^ bArrM6828[i2]) ^ bArrM68283[i2]);
        }
        return bArrCopyOf;
    }
}
