package com.google.android.gms.internal.ads;

import android.os.Build;
import java.security.GeneralSecurityException;
import java.util.Arrays;
import java.util.Objects;
import javax.crypto.Cipher;
import javax.crypto.spec.GCMParameterSpec;
import javax.crypto.spec.SecretKeySpec;

/* JADX INFO: loaded from: classes2.dex */
public final class fz1 implements qv1 {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final byte[] f11440a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public final int f11441b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public final q22 f11442c;

    public fz1(byte[] bArr, i92 i92Var, int i10) {
        this.f11442c = ih1.W(o22.z(p22.b(bArr.length), jc1.d(bArr)));
        this.f11440a = i92Var.b();
        this.f11441b = i10;
    }

    @Override // com.google.android.gms.internal.ads.qv1
    public final byte[] zza(byte[] bArr, byte[] bArr2) throws GeneralSecurityException {
        if (bArr == null) {
            throw new NullPointerException("ciphertext is null");
        }
        int length = bArr.length;
        byte[] bArr3 = this.f11440a;
        int length2 = bArr3.length;
        int i10 = this.f11441b + length2;
        int i11 = i10 + 28;
        if (length < i11) {
            throw new GeneralSecurityException("ciphertext too short");
        }
        if (!q12.c(bArr3, bArr)) {
            throw new GeneralSecurityException("Decryption failed (OutputPrefix mismatch).");
        }
        byte[] bArrCopyOfRange = Arrays.copyOfRange(bArr, length2, i10);
        byte[] bArr4 = {0, 1, 88, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
        byte[] bArr5 = {0, 2, 88, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
        int length3 = bArrCopyOfRange.length;
        if (length3 > 12 || length3 < 8) {
            throw new GeneralSecurityException("invalid salt size");
        }
        System.arraycopy(bArrCopyOfRange, 0, bArr4, 4, length3);
        System.arraycopy(bArrCopyOfRange, 0, bArr5, 4, length3);
        byte[] bArr6 = new byte[32];
        q22 q22Var = this.f11442c;
        System.arraycopy(q22Var.a(16, bArr4), 0, bArr6, 0, 16);
        System.arraycopy(q22Var.a(16, bArr5), 0, bArr6, 16, 16);
        if (!ih1.z(2)) {
            throw new GeneralSecurityException("Can not use AES-GCM in FIPS-mode, as BoringCrypto module is not available.");
        }
        com.google.android.gms.common.api.internal.x0 x0Var = sy1.f16625a;
        h92.a(32);
        SecretKeySpec secretKeySpec = new SecretKeySpec(bArr6, "AES");
        int i12 = i10 + 12;
        byte[] bArrCopyOfRange2 = Arrays.copyOfRange(bArr, i10, i12);
        if (bArrCopyOfRange2.length != 12) {
            throw new GeneralSecurityException("iv is wrong size");
        }
        if (length < i11) {
            throw new GeneralSecurityException("ciphertext too short");
        }
        Integer numValueOf = !Objects.equals(System.getProperty("java.vendor"), "The Android Project") ? null : Integer.valueOf(Build.VERSION.SDK_INT);
        if (numValueOf != null) {
            numValueOf.intValue();
        }
        GCMParameterSpec gCMParameterSpec = new GCMParameterSpec(128, bArrCopyOfRange2, 0, 12);
        Cipher cipher = (Cipher) sy1.f16625a.get();
        cipher.init(2, secretKeySpec, gCMParameterSpec);
        if (bArr2 != null && bArr2.length != 0) {
            cipher.updateAAD(bArr2);
        }
        return cipher.doFinal(bArr, i12, length - i12);
    }
}
