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

import java.security.GeneralSecurityException;
import java.security.InvalidAlgorithmParameterException;
import java.security.Key;
import java.security.NoSuchAlgorithmException;
import java.util.Arrays;
import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;

/* JADX INFO: loaded from: classes2.dex */
public final class a92 implements q22, com.google.android.gms.internal.pal.ia {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final /* synthetic */ int f8586a;

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

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

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public final Key f8589d;

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

    /* JADX WARN: Can't fix incorrect switch cases order, some code will duplicate */
    /* JADX WARN: Removed duplicated region for block: B:10:0x004a  */
    /* JADX WARN: Removed duplicated region for block: B:50:0x00c7  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public a92(String str, SecretKeySpec secretKeySpec, int i10) throws GeneralSecurityException {
        int i11;
        this.f8586a = i10;
        int i12 = 64;
        if (i10 != 1) {
            z82 z82Var = new z82(this);
            this.f8587b = z82Var;
            if (!ih1.z(2)) {
                throw new GeneralSecurityException("Can not use HMAC in FIPS-mode, as BoringCrypto module is not available.");
            }
            this.f8588c = str;
            this.f8589d = secretKeySpec;
            if (secretKeySpec.getEncoded().length < 16) {
                throw new InvalidAlgorithmParameterException("key size too small, need at least 16 bytes");
            }
            str.getClass();
            switch (str) {
                case "HMACSHA1":
                    i12 = 20;
                    break;
                case "HMACSHA224":
                    i12 = 28;
                    break;
                case "HMACSHA256":
                    i12 = 32;
                    break;
                case "HMACSHA384":
                    i12 = 48;
                    break;
                case "HMACSHA512":
                    break;
                default:
                    throw new NoSuchAlgorithmException("unknown Hmac algorithm: ".concat(str));
            }
            this.f8590e = i12;
            z82Var.get();
            return;
        }
        z82 z82Var2 = new z82(this, 1);
        this.f8587b = z82Var2;
        if (!com.google.android.gms.internal.pal.q9.y(2)) {
            throw new GeneralSecurityException("Can not use HMAC in FIPS-mode, as BoringCrypto module is not available.");
        }
        this.f8588c = str;
        this.f8589d = secretKeySpec;
        if (secretKeySpec.getEncoded().length < 16) {
            throw new InvalidAlgorithmParameterException("key size too small, need at least 16 bytes");
        }
        str.getClass();
        switch (str) {
            case "HMACSHA1":
                this.f8590e = 20;
                z82Var2.get();
                return;
            case "HMACSHA224":
                i11 = 28;
                this.f8590e = i11;
                z82Var2.get();
                return;
            case "HMACSHA256":
                i11 = 32;
                this.f8590e = i11;
                z82Var2.get();
                return;
            case "HMACSHA384":
                this.f8590e = 48;
                z82Var2.get();
                return;
            case "HMACSHA512":
                this.f8590e = 64;
                z82Var2.get();
                return;
            default:
                throw new NoSuchAlgorithmException("unknown Hmac algorithm: ".concat(str));
        }
    }

    @Override // com.google.android.gms.internal.ads.q22, com.google.android.gms.internal.pal.ia
    public final byte[] a(int i10, byte[] bArr) throws InvalidAlgorithmParameterException {
        int i11 = this.f8586a;
        z82 z82Var = this.f8587b;
        int i12 = this.f8590e;
        switch (i11) {
            case 0:
                if (i10 > i12) {
                    throw new InvalidAlgorithmParameterException("tag size too big");
                }
                ((Mac) z82Var.get()).update(bArr);
                return Arrays.copyOf(((Mac) z82Var.get()).doFinal(), i10);
            default:
                if (i10 > i12) {
                    throw new InvalidAlgorithmParameterException("tag size too big");
                }
                ((Mac) z82Var.get()).update(bArr);
                return Arrays.copyOf(((Mac) z82Var.get()).doFinal(), i10);
        }
    }
}
