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

import android.os.Build;
import java.math.BigInteger;
import java.security.GeneralSecurityException;
import java.security.KeyFactory;
import java.security.NoSuchProviderException;
import java.security.Provider;
import java.security.interfaces.RSAPrivateCrtKey;
import java.security.spec.PKCS8EncodedKeySpec;
import java.security.spec.RSAPrivateCrtKeySpec;
import java.util.Objects;

/* JADX INFO: loaded from: classes2.dex */
public final class g82 implements ew1 {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public static final byte[] f11618a = {48, 46, 2, 1, 0, 48, 5, 6, 3, 43, 101, 112, 4, 34, 4, 32};

    public /* synthetic */ g82(RSAPrivateCrtKey rSAPrivateCrtKey, zzhxn zzhxnVar, zzhxn zzhxnVar2) throws GeneralSecurityException {
        if (mz1.a()) {
            throw new GeneralSecurityException("Can not use RSA PSS in FIPS-mode, as BoringCrypto module is not available.");
        }
        h92.b(zzhxnVar);
        if (!zzhxnVar.equals(zzhxnVar2)) {
            throw new GeneralSecurityException("sigHash and mgf1Hash must be the same");
        }
        h92.c(rSAPrivateCrtKey.getModulus().bitLength());
        h92.d(rSAPrivateCrtKey.getPublicExponent());
    }

    public static g82 a(z62 z62Var) throws GeneralSecurityException {
        Provider providerE = vj1.e();
        if (providerE == null) {
            throw new NoSuchProviderException("Ed25519SignJce requires the Conscrypt provider.");
        }
        byte[] bArrH = z62Var.f19101c.h();
        c72 c72Var = z62Var.f19100b;
        c72Var.f9799d.b();
        c72Var.f9797b.f18672a.getClass();
        g82 g82Var = new g82();
        if (!ih1.z(1)) {
            throw new GeneralSecurityException("Can not use Ed25519 in FIPS-mode.");
        }
        if (bArrH.length != 32) {
            throw new IllegalArgumentException(String.format("Given private key's length is not %s", 32));
        }
        KeyFactory.getInstance("Ed25519", providerE).generatePrivate(new PKCS8EncodedKeySpec(ih1.G(f11618a, bArrH)));
        return g82Var;
    }

    /* JADX WARN: Removed duplicated region for block: B:11:0x002c  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public static g82 b(w72 w72Var) throws GeneralSecurityException {
        Provider providerE;
        int i10 = q12.f15571a;
        if (Objects.equals(System.getProperty("java.vendor"), "The Android Project")) {
            providerE = (!Objects.equals(System.getProperty("java.vendor"), "The Android Project") ? null : Integer.valueOf(Build.VERSION.SDK_INT)).intValue() > 23 ? vj1.e() : null;
        }
        if (providerE == null) {
            throw new NoSuchProviderException("RSA SSA PSS using Conscrypt is not supported.");
        }
        KeyFactory keyFactory = KeyFactory.getInstance("RSA", providerE);
        v72 v72Var = w72Var.f17899b.f18344b;
        x72 x72Var = w72Var.f17899b;
        RSAPrivateCrtKey rSAPrivateCrtKey = (RSAPrivateCrtKey) keyFactory.generatePrivate(new RSAPrivateCrtKeySpec(x72Var.f18345c, v72Var.f17534b, (BigInteger) w72Var.f17900c.f12808b, (BigInteger) w72Var.f17901d.f12808b, (BigInteger) w72Var.f17902e.f12808b, (BigInteger) w72Var.f17903f.f12808b, (BigInteger) w72Var.f17904g.f12808b, (BigInteger) w72Var.f17905h.f12808b));
        x72Var.f18346d.b();
        v72Var.f17535c.getClass();
        g82 g82Var = new g82();
        if (!ih1.z(2)) {
            throw new GeneralSecurityException("Cannot use RSA PSS in FIPS-mode, as BoringCrypto module is not available.");
        }
        h92.c(rSAPrivateCrtKey.getModulus().bitLength());
        h92.d(rSAPrivateCrtKey.getPublicExponent());
        t72 t72Var = v72Var.f17536d;
        n82.a(t72Var);
        n82.b(t72Var, v72Var.f17537e, v72Var.f17538f);
        return g82Var;
    }

    public g82(byte[] bArr) throws GeneralSecurityException {
        if (ih1.z(1)) {
            if (bArr.length == 32) {
                ih1.K(ih1.l0(bArr));
                return;
            }
            throw new IllegalArgumentException(String.format("Given private key's length is not %s", 32));
        }
        throw new GeneralSecurityException("Can not use Ed25519 in FIPS-mode.");
    }
}
