package org.bouncycastle.jce.provider; import java.security.Permission; import javax.crypto.spec.DHParameterSpec; import org.bouncycastle.jcajce.provider.asymmetric.util.EC5Util; import org.bouncycastle.jcajce.provider.config.ConfigurableProvider; import org.bouncycastle.jcajce.provider.config.ProviderConfiguration; import org.bouncycastle.jcajce.provider.config.ProviderConfigurationPermission; import org.bouncycastle.jce.spec.ECParameterSpec; /* loaded from: classes6.dex */ class BouncyCastleProviderConfiguration implements ProviderConfiguration { private volatile Object dhDefaultParams; private volatile ECParameterSpec ecImplicitCaParams; private static Permission BC_EC_LOCAL_PERMISSION = new ProviderConfigurationPermission(BouncyCastleProvider.PROVIDER_NAME, ConfigurableProvider.THREAD_LOCAL_EC_IMPLICITLY_CA); private static Permission BC_EC_PERMISSION = new ProviderConfigurationPermission(BouncyCastleProvider.PROVIDER_NAME, ConfigurableProvider.EC_IMPLICITLY_CA); private static Permission BC_DH_LOCAL_PERMISSION = new ProviderConfigurationPermission(BouncyCastleProvider.PROVIDER_NAME, ConfigurableProvider.THREAD_LOCAL_DH_DEFAULT_PARAMS); private static Permission BC_DH_PERMISSION = new ProviderConfigurationPermission(BouncyCastleProvider.PROVIDER_NAME, ConfigurableProvider.DH_DEFAULT_PARAMS); private ThreadLocal ecThreadSpec = new ThreadLocal(); private ThreadLocal dhThreadSpec = new ThreadLocal(); /* JADX INFO: Access modifiers changed from: package-private */ public void setParameter(String str, Object obj) { ThreadLocal threadLocal; SecurityManager securityManager = System.getSecurityManager(); if (str.equals(ConfigurableProvider.THREAD_LOCAL_EC_IMPLICITLY_CA)) { if (securityManager != null) { securityManager.checkPermission(BC_EC_LOCAL_PERMISSION); } ECParameterSpec convertSpec = ((obj instanceof ECParameterSpec) || obj == null) ? (ECParameterSpec) obj : EC5Util.convertSpec((java.security.spec.ECParameterSpec) obj, false); if (convertSpec != null) { this.ecThreadSpec.set(convertSpec); return; } threadLocal = this.ecThreadSpec; } else { if (str.equals(ConfigurableProvider.EC_IMPLICITLY_CA)) { if (securityManager != null) { securityManager.checkPermission(BC_EC_PERMISSION); } if ((obj instanceof ECParameterSpec) || obj == null) { this.ecImplicitCaParams = (ECParameterSpec) obj; return; } else { this.ecImplicitCaParams = EC5Util.convertSpec((java.security.spec.ECParameterSpec) obj, false); return; } } if (!str.equals(ConfigurableProvider.THREAD_LOCAL_DH_DEFAULT_PARAMS)) { if (str.equals(ConfigurableProvider.DH_DEFAULT_PARAMS)) { if (securityManager != null) { securityManager.checkPermission(BC_DH_PERMISSION); } if (!(obj instanceof DHParameterSpec) && !(obj instanceof DHParameterSpec[]) && obj != null) { throw new IllegalArgumentException("not a valid DHParameterSpec or DHParameterSpec[]"); } this.dhDefaultParams = obj; return; } return; } if (securityManager != null) { securityManager.checkPermission(BC_DH_LOCAL_PERMISSION); } if (!(obj instanceof DHParameterSpec) && !(obj instanceof DHParameterSpec[]) && obj != null) { throw new IllegalArgumentException("not a valid DHParameterSpec"); } threadLocal = this.dhThreadSpec; if (obj != null) { threadLocal.set(obj); return; } } threadLocal.remove(); } @Override // org.bouncycastle.jcajce.provider.config.ProviderConfiguration public ECParameterSpec getEcImplicitlyCa() { ECParameterSpec eCParameterSpec = (ECParameterSpec) this.ecThreadSpec.get(); return eCParameterSpec != null ? eCParameterSpec : this.ecImplicitCaParams; } @Override // org.bouncycastle.jcajce.provider.config.ProviderConfiguration public DHParameterSpec getDHDefaultParameters(int i) { Object obj = this.dhThreadSpec.get(); if (obj == null) { obj = this.dhDefaultParams; } if (obj instanceof DHParameterSpec) { DHParameterSpec dHParameterSpec = (DHParameterSpec) obj; if (dHParameterSpec.getP().bitLength() == i) { return dHParameterSpec; } return null; } if (!(obj instanceof DHParameterSpec[])) { return null; } DHParameterSpec[] dHParameterSpecArr = (DHParameterSpec[]) obj; for (int i2 = 0; i2 != dHParameterSpecArr.length; i2++) { if (dHParameterSpecArr[i2].getP().bitLength() == i) { return dHParameterSpecArr[i2]; } } return null; } }