package defpackage;

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

/* renamed from: ᵨᵢʩʝ, reason: contains not printable characters */
/* loaded from: classes3.dex */
public final class C3745 implements InterfaceC2556 {

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

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

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

    public C3745(byte[] bArr, C4542 c4542, int i) {
        this.f13980 = ᵱᵞᵪ.ᵹᵝᵶ(C0770.m2857(C5169.m10668(bArr.length), new ᵿʤˑᵦ(21, C4542.m9654(bArr))));
        this.f13981 = c4542.m9655();
        this.f13982 = i;
    }

    /* renamed from: ˏᵙ, reason: contains not printable characters */
    public final byte[] m8369(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) {
            C0910.m3048("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];
        InterfaceC5287 interfaceC5287 = this.f13980;
        System.arraycopy(interfaceC5287.mo5875(16, bArr2), 0, bArr4, 0, 16);
        System.arraycopy(interfaceC5287.mo5875(16, bArr3), 0, bArr4, 16, 16);
        return bArr4;
    }

    @Override // defpackage.InterfaceC2556
    /* renamed from: ᵥᵯˎ */
    public final byte[] mo2411(byte[] bArr, byte[] bArr2) throws GeneralSecurityException {
        if (bArr == null) {
            C1260.m3813("plaintext is null");
            return null;
        }
        int i = this.f13982;
        int i2 = i + 12;
        byte[] bArrM11138 = AbstractC5513.m11138(i2);
        byte[] bArrCopyOf = Arrays.copyOf(bArrM11138, i);
        byte[] bArrCopyOfRange = Arrays.copyOfRange(bArrM11138, i, i2);
        byte[] bArrM8369 = m8369(bArrCopyOf);
        if (!AbstractC2990.m7308(2)) {
            C0910.m3048("Can not use AES-GCM in FIPS-mode, as BoringCrypto module is not available.");
            return null;
        }
        C1907 c1907 = AbstractC0974.f4337;
        AbstractC5437.m11082(32);
        SecretKeySpec secretKeySpec = new SecretKeySpec(bArrM8369, "AES");
        byte[] bArr3 = this.f13981;
        int length = bArr3.length + i + bArrCopyOfRange.length;
        if (bArrCopyOfRange.length != 12) {
            C0910.m3048("iv is wrong size");
            return null;
        }
        AlgorithmParameterSpec algorithmParameterSpecM3319 = AbstractC0974.m3319(bArrCopyOfRange, 0, bArrCopyOfRange.length);
        Cipher cipher = (Cipher) AbstractC0974.f4337.get();
        cipher.init(1, secretKeySpec, algorithmParameterSpecM3319);
        if (bArr2 != null && bArr2.length != 0) {
            cipher.updateAAD(bArr2);
        }
        int outputSize = cipher.getOutputSize(bArr.length);
        if (outputSize > Integer.MAX_VALUE - length) {
            C0910.m3048("plaintext too long");
            return null;
        }
        byte[] bArr4 = new byte[length + outputSize];
        if (cipher.doFinal(bArr, 0, bArr.length, bArr4, length) != outputSize) {
            C0910.m3048("not enough data written");
            return null;
        }
        System.arraycopy(bArr3, 0, bArr4, 0, bArr3.length);
        System.arraycopy(bArrM11138, 0, bArr4, bArr3.length, bArrM11138.length);
        return bArr4;
    }

    @Override // defpackage.InterfaceC2556
    /* renamed from: ᵴᵳ */
    public final byte[] mo2412(byte[] bArr, byte[] bArr2) throws GeneralSecurityException {
        if (bArr == null) {
            C1260.m3813("ciphertext is null");
            return null;
        }
        int length = bArr.length;
        byte[] bArr3 = this.f13981;
        int length2 = bArr3.length;
        int i = this.f13982;
        if (length < length2 + i + 28) {
            C0910.m3048("ciphertext too short");
            return null;
        }
        if (!AbstractC1067.m3457(bArr3, bArr)) {
            C0910.m3048("Decryption failed (OutputPrefix mismatch).");
            return null;
        }
        int length3 = bArr3.length + i;
        byte[] bArrM8369 = m8369(Arrays.copyOfRange(bArr, bArr3.length, length3));
        if (!AbstractC2990.m7308(2)) {
            C0910.m3048("Can not use AES-GCM in FIPS-mode, as BoringCrypto module is not available.");
            return null;
        }
        C1907 c1907 = AbstractC0974.f4337;
        AbstractC5437.m11082(32);
        SecretKeySpec secretKeySpec = new SecretKeySpec(bArrM8369, "AES");
        int i2 = length3 + 12;
        byte[] bArrCopyOfRange = Arrays.copyOfRange(bArr, length3, i2);
        if (bArrCopyOfRange.length != 12) {
            C0910.m3048("iv is wrong size");
            return null;
        }
        if (bArr.length < length3 + 28) {
            C0910.m3048("ciphertext too short");
            return null;
        }
        AlgorithmParameterSpec algorithmParameterSpecM3319 = AbstractC0974.m3319(bArrCopyOfRange, 0, bArrCopyOfRange.length);
        Cipher cipher = (Cipher) AbstractC0974.f4337.get();
        cipher.init(2, secretKeySpec, algorithmParameterSpecM3319);
        if (bArr2 != null && bArr2.length != 0) {
            cipher.updateAAD(bArr2);
        }
        return cipher.doFinal(bArr, i2, bArr.length - i2);
    }
}
