package defpackage;

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

/* JADX INFO: renamed from: ᵳˇʖ, reason: contains not printable characters */
/* JADX INFO: loaded from: classes3.dex */
public final class C4567 implements InterfaceC5579 {

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

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

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

    public C4567(byte[] bArr, C2855 c2855, int i) {
        this.f17360 = ˌᵨʽʙ.ᵮᵣᵗˈ(C5537.m11158(C0429.m1828(bArr.length), new ʽˎˇˌ(21, C2855.m6836(bArr))));
        this.f17361 = c2855.m6837();
        this.f17359 = i;
    }

    @Override // defpackage.InterfaceC5579
    /* JADX INFO: renamed from: ʽˈˋ */
    public final byte[] mo1207(byte[] bArr, byte[] bArr2) throws GeneralSecurityException {
        if (bArr == null) {
            C4935.m10233("ciphertext is null");
            return null;
        }
        int length = bArr.length;
        byte[] bArr3 = this.f17361;
        int length2 = bArr3.length;
        int i = this.f17359;
        if (length < length2 + i + 28) {
            C1685.m4558("ciphertext too short");
            return null;
        }
        if (!AbstractC0184.m1341(bArr3, bArr)) {
            C1685.m4558("Decryption failed (OutputPrefix mismatch).");
            return null;
        }
        int length3 = bArr3.length + i;
        byte[] bArrM9652 = m9652(Arrays.copyOfRange(bArr, bArr3.length, length3));
        if (!AbstractC2704.m6531(2)) {
            C1685.m4558("Can not use AES-GCM in FIPS-mode, as BoringCrypto module is not available.");
            return null;
        }
        C0140 c0140 = AbstractC3998.f15305;
        AbstractC1792.m4941(32);
        SecretKeySpec secretKeySpec = new SecretKeySpec(bArrM9652, "AES");
        int i2 = length3 + 12;
        byte[] bArrCopyOfRange = Arrays.copyOfRange(bArr, length3, i2);
        if (bArrCopyOfRange.length != 12) {
            C1685.m4558("iv is wrong size");
            return null;
        }
        if (bArr.length < length3 + 28) {
            C1685.m4558("ciphertext too short");
            return null;
        }
        AlgorithmParameterSpec algorithmParameterSpecM8775 = AbstractC3998.m8775(bArrCopyOfRange, 0, bArrCopyOfRange.length);
        Cipher cipher = (Cipher) AbstractC3998.f15305.get();
        cipher.init(2, secretKeySpec, algorithmParameterSpecM8775);
        if (bArr2 != null && bArr2.length != 0) {
            cipher.updateAAD(bArr2);
        }
        return cipher.doFinal(bArr, i2, bArr.length - i2);
    }

    /* JADX INFO: renamed from: ːˏᵟᵯ, reason: contains not printable characters */
    public final byte[] m9652(byte[] bArr) throws GeneralSecurityException {
        byte[] bArr2 = {0, 1, 88, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
        byte[] bArr3 = {0, 2, 88, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
        if (bArr.length > 12 || bArr.length < 8) {
            C1685.m4558("invalid salt size");
            return null;
        }
        System.arraycopy(bArr, 0, bArr2, 4, bArr.length);
        System.arraycopy(bArr, 0, bArr3, 4, bArr.length);
        byte[] bArr4 = new byte[32];
        InterfaceC2925 interfaceC2925 = this.f17360;
        System.arraycopy(interfaceC2925.mo4740(16, bArr2), 0, bArr4, 0, 16);
        System.arraycopy(interfaceC2925.mo4740(16, bArr3), 0, bArr4, 16, 16);
        return bArr4;
    }

    @Override // defpackage.InterfaceC5579
    /* JADX INFO: renamed from: ᵲᵶᵳˈ */
    public final byte[] mo1208(byte[] bArr, byte[] bArr2) throws GeneralSecurityException {
        if (bArr == null) {
            C4935.m10233("plaintext is null");
            return null;
        }
        int i = this.f17359;
        int i2 = i + 12;
        byte[] bArrM5643 = AbstractC2133.m5643(i2);
        byte[] bArrCopyOf = Arrays.copyOf(bArrM5643, i);
        byte[] bArrCopyOfRange = Arrays.copyOfRange(bArrM5643, i, i2);
        byte[] bArrM9652 = m9652(bArrCopyOf);
        if (!AbstractC2704.m6531(2)) {
            C1685.m4558("Can not use AES-GCM in FIPS-mode, as BoringCrypto module is not available.");
            return null;
        }
        C0140 c0140 = AbstractC3998.f15305;
        AbstractC1792.m4941(32);
        SecretKeySpec secretKeySpec = new SecretKeySpec(bArrM9652, "AES");
        byte[] bArr3 = this.f17361;
        int length = bArr3.length + i + bArrCopyOfRange.length;
        if (bArrCopyOfRange.length != 12) {
            C1685.m4558("iv is wrong size");
            return null;
        }
        AlgorithmParameterSpec algorithmParameterSpecM8775 = AbstractC3998.m8775(bArrCopyOfRange, 0, bArrCopyOfRange.length);
        Cipher cipher = (Cipher) AbstractC3998.f15305.get();
        cipher.init(1, secretKeySpec, algorithmParameterSpecM8775);
        if (bArr2 != null && bArr2.length != 0) {
            cipher.updateAAD(bArr2);
        }
        int outputSize = cipher.getOutputSize(bArr.length);
        if (outputSize > Integer.MAX_VALUE - length) {
            C1685.m4558("plaintext too long");
            return null;
        }
        byte[] bArr4 = new byte[length + outputSize];
        if (cipher.doFinal(bArr, 0, bArr.length, bArr4, length) != outputSize) {
            C1685.m4558("not enough data written");
            return null;
        }
        System.arraycopy(bArr3, 0, bArr4, 0, bArr3.length);
        System.arraycopy(bArrM5643, 0, bArr4, bArr3.length, bArrM5643.length);
        return bArr4;
    }
}
