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;

/* renamed from: ⁱᴵ, reason: contains not printable characters */
/* loaded from: classes3.dex */
public final class C5547 implements InterfaceC2556 {

    /* renamed from: ˇʼʤˎ, reason: contains not printable characters */
    public static final C1907 f20820 = new C1907(1);

    /* renamed from: ˏᵙ, reason: contains not printable characters */
    public final SecretKeySpec f20821;

    /* renamed from: ᵥᵯˎ, reason: contains not printable characters */
    public final byte[] f20822;

    /* renamed from: ᵴᵳ, reason: contains not printable characters */
    public final InterfaceC5287 f20823;

    /* renamed from: ᵻᵢﹳᵰ, reason: contains not printable characters */
    public final int f20824;

    public C5547(int i, byte[] bArr, byte[] bArr2) throws GeneralSecurityException {
        if (!AbstractC2990.m7330(1)) {
            C0910.m3048("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.f20824 = i;
        AbstractC5437.m11082(bArr.length);
        this.f20821 = new SecretKeySpec(bArr, "AES");
        this.f20823 = ᵱᵞᵪ.ᵹᵝᵶ(C0770.m2857(C5169.m10668(bArr.length), new ᵿʤˑᵦ(21, C4542.m9654(bArr))));
        this.f20822 = bArr2;
    }

    /* renamed from: ˏᵙ, reason: contains not printable characters */
    public final byte[] m11153(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.f20823.mo5875(16, bArr2);
    }

    @Override // defpackage.InterfaceC2556
    /* renamed from: ᵥᵯˎ */
    public final byte[] mo2411(byte[] bArr, byte[] bArr2) throws GeneralSecurityException {
        int length = bArr.length;
        byte[] bArr3 = this.f20822;
        int length2 = Integer.MAX_VALUE - bArr3.length;
        int i = this.f20824;
        if (length > (length2 - i) - 16) {
            C0910.m3048("plaintext too long");
            return null;
        }
        byte[] bArrCopyOf = Arrays.copyOf(bArr3, bArr3.length + i + bArr.length + 16);
        byte[] bArrM11138 = AbstractC5513.m11138(i);
        System.arraycopy(bArrM11138, 0, bArrCopyOf, bArr3.length, i);
        byte[] bArrM11153 = m11153(0, 0, bArrM11138.length, bArrM11138);
        if (bArr2 == null) {
            bArr2 = new byte[0];
        }
        byte[] bArrM111532 = m11153(1, 0, bArr2.length, bArr2);
        Cipher cipher = (Cipher) f20820.get();
        cipher.init(1, this.f20821, new IvParameterSpec(bArrM11153));
        cipher.doFinal(bArr, 0, bArr.length, bArrCopyOf, bArr3.length + i);
        byte[] bArrM111533 = m11153(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) ((bArrM111532[i2] ^ bArrM11153[i2]) ^ bArrM111533[i2]);
        }
        return bArrCopyOf;
    }

    @Override // defpackage.InterfaceC2556
    /* renamed from: ᵴᵳ */
    public final byte[] mo2412(byte[] bArr, byte[] bArr2) throws GeneralSecurityException {
        int length = bArr.length;
        byte[] bArr3 = this.f20822;
        int length2 = length - bArr3.length;
        int i = this.f20824;
        int i2 = (length2 - i) - 16;
        if (i2 < 0) {
            C0910.m3048("ciphertext too short");
            return null;
        }
        if (!AbstractC1067.m3457(bArr3, bArr)) {
            C0910.m3048("Decryption failed (OutputPrefix mismatch).");
            return null;
        }
        byte[] bArrM11153 = m11153(0, bArr3.length, i, bArr);
        if (bArr2 == null) {
            bArr2 = new byte[0];
        }
        byte[] bArrM111532 = m11153(1, 0, bArr2.length, bArr2);
        byte[] bArrM111533 = m11153(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] ^ bArrM111532[i3]) ^ bArrM11153[i3]) ^ bArrM111533[i3]));
        }
        if (b != 0) {
            throw new AEADBadTagException("tag mismatch");
        }
        Cipher cipher = (Cipher) f20820.get();
        cipher.init(1, this.f20821, new IvParameterSpec(bArrM11153));
        return cipher.doFinal(bArr, bArr3.length + i, i2);
    }
}
