package R3;

import Y3.s;
import Y3.t;
import android.security.keystore.KeyGenParameterSpec;
import android.util.Log;
import java.io.IOException;
import java.security.GeneralSecurityException;
import java.security.InvalidAlgorithmParameterException;
import java.security.KeyStore;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
import java.security.NoSuchProviderException;
import java.util.Arrays;
import javax.crypto.KeyGenerator;

/* JADX INFO: loaded from: classes3.dex */
public final class d {

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public static final Object f6082b = new Object();

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public KeyStore f6083a;

    public d() {
        try {
            KeyStore keyStore = KeyStore.getInstance("AndroidKeyStore");
            keyStore.load(null);
            this.f6083a = keyStore;
        } catch (IOException | GeneralSecurityException e6) {
            throw new IllegalStateException(e6);
        }
    }

    public static boolean a(String str) {
        d dVar = new d();
        synchronized (f6082b) {
            try {
                if (dVar.d(str)) {
                    return false;
                }
                b(str);
                return true;
            } catch (Throwable th) {
                throw th;
            }
        }
    }

    public static void b(String str) throws NoSuchAlgorithmException, NoSuchProviderException, InvalidAlgorithmParameterException {
        String strB = t.b(str);
        KeyGenerator keyGenerator = KeyGenerator.getInstance("AES", "AndroidKeyStore");
        keyGenerator.init(new KeyGenParameterSpec.Builder(strB, 3).setKeySize(256).setBlockModes("GCM").setEncryptionPaddings("NoPadding").build());
        keyGenerator.generateKey();
    }

    public final synchronized c c(String str) {
        c cVar;
        cVar = new c(t.b(str), this.f6083a);
        byte[] bArrA = s.a(10);
        byte[] bArr = new byte[0];
        if (!Arrays.equals(bArrA, cVar.b(cVar.a(bArrA, bArr), bArr))) {
            throw new KeyStoreException("cannot use Android Keystore: encryption/decryption of non-empty message and empty aad returns an incorrect result");
        }
        return cVar;
    }

    public final synchronized boolean d(String str) {
        String strB;
        strB = t.b(str);
        try {
        } catch (NullPointerException unused) {
            Log.w("d", "Keystore is temporarily unavailable, wait, reinitialize Keystore and try again.");
            try {
                try {
                    Thread.sleep((int) (Math.random() * 40.0d));
                } catch (InterruptedException unused2) {
                }
                KeyStore keyStore = KeyStore.getInstance("AndroidKeyStore");
                this.f6083a = keyStore;
                keyStore.load(null);
                return this.f6083a.containsAlias(strB);
            } catch (IOException e6) {
                throw new GeneralSecurityException(e6);
            }
        }
        return this.f6083a.containsAlias(strB);
    }
}
