package sa;

import com.google.android.gms.internal.ads.z82;
import com.google.crypto.tink.config.internal.TinkFipsUtil$AlgorithmFipsCompatibility;
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 m implements pa.c {

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

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

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

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

    public m(String str, SecretKeySpec secretKeySpec) throws GeneralSecurityException {
        z82 z82Var = new z82(this, 2);
        this.f32737a = z82Var;
        if (!TinkFipsUtil$AlgorithmFipsCompatibility.f23815b.a()) {
            throw new GeneralSecurityException("Can not use HMAC in FIPS-mode, as BoringCrypto module is not available.");
        }
        this.f32738b = str;
        this.f32739c = 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.f32740d = 20;
                break;
            case "HMACSHA224":
                this.f32740d = 28;
                break;
            case "HMACSHA256":
                this.f32740d = 32;
                break;
            case "HMACSHA384":
                this.f32740d = 48;
                break;
            case "HMACSHA512":
                this.f32740d = 64;
                break;
            default:
                throw new NoSuchAlgorithmException("unknown Hmac algorithm: ".concat(str));
        }
        z82Var.get();
    }

    @Override // pa.c
    public final byte[] e(int i10, byte[] bArr) throws InvalidAlgorithmParameterException {
        if (i10 > this.f32740d) {
            throw new InvalidAlgorithmParameterException("tag size too big");
        }
        z82 z82Var = this.f32737a;
        ((Mac) z82Var.get()).update(bArr);
        return Arrays.copyOf(((Mac) z82Var.get()).doFinal(), i10);
    }
}
