package sa;

import com.google.android.gms.measurement.internal.c2;
import java.security.GeneralSecurityException;
import java.security.InvalidAlgorithmParameterException;
import java.security.MessageDigest;
import java.util.Arrays;
import javax.crypto.spec.SecretKeySpec;

/* JADX INFO: loaded from: classes2.dex */
public final class n implements da.k {

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public static final byte[] f32741e = {0};

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final pa.c f32742a;

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

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

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

    public n(m mVar, int i10) throws InvalidAlgorithmParameterException {
        this.f32742a = mVar;
        this.f32743b = i10;
        this.f32744c = new byte[0];
        this.f32745d = new byte[0];
        if (i10 < 10) {
            throw new InvalidAlgorithmParameterException("tag size too small, need at least 10 bytes");
        }
        mVar.e(i10, new byte[0]);
    }

    @Override // da.k
    public final void a(byte[] bArr, byte[] bArr2) throws GeneralSecurityException {
        if (!MessageDigest.isEqual(b(bArr2), bArr)) {
            throw new GeneralSecurityException("invalid MAC");
        }
    }

    @Override // da.k
    public final byte[] b(byte[] bArr) {
        byte[] bArr2 = this.f32745d;
        int length = bArr2.length;
        int i10 = this.f32743b;
        pa.c cVar = this.f32742a;
        byte[] bArr3 = this.f32744c;
        return length > 0 ? c2.f(bArr3, cVar.e(i10, c2.f(bArr, bArr2))) : c2.f(bArr3, cVar.e(i10, bArr));
    }

    public n(na.a aVar) {
        this.f32742a = com.bumptech.glide.g.a(pa.a.R(pa.b.b(aVar.f31125b.f31138a), aVar.f31126c));
        na.d dVar = aVar.f31125b;
        this.f32743b = dVar.f31139b;
        this.f32744c = aVar.f31127d.b();
        if (dVar.f31140c.equals(na.c.f31135d)) {
            this.f32745d = Arrays.copyOf(f32741e, 1);
        } else {
            this.f32745d = new byte[0];
        }
    }

    public n(na.h hVar) {
        this.f32742a = new m("HMAC" + hVar.f31142b.f31166d, new SecretKeySpec(hVar.f31143c.F(da.e.f25073b), "HMAC"));
        na.l lVar = hVar.f31142b;
        this.f32743b = lVar.f31164b;
        this.f32744c = hVar.f31144d.b();
        if (lVar.f31165c.equals(na.k.f31160d)) {
            this.f32745d = Arrays.copyOf(f32741e, 1);
        } else {
            this.f32745d = new byte[0];
        }
    }
}
