package org.bouncycastle.crypto.params;

/* JADX INFO: loaded from: E:\ios\vf_dex\classes4.dex */
public class RSAKeyParameters extends org.bouncycastle.crypto.params.AsymmetricKeyParameter {
    private static final org.bouncycastle.util.BigIntegers.Cache d = new org.bouncycastle.util.BigIntegers.Cache();
    private static final java.math.BigInteger e = new java.math.BigInteger("8138e8a0fcf3a4e84a771d40fd305d7f4aa59306d7251de54d98af8fe95729a1f73d893fa424cd2edc8636a6c3285e022b0e3866a565ae8108eed8591cd4fe8d2ce86165a978d719ebf647f362d33fca29cd179fb42401cbaf3df0c614056f9c8f3cfd51e474afb6bc6974f78db8aba8e9e517fded658591ab7502bd41849462f", 16);
    private java.math.BigInteger b;
    private java.math.BigInteger c;

    public RSAKeyParameters(boolean z, java.math.BigInteger bigInteger, java.math.BigInteger bigInteger2) {
        this(z, bigInteger, bigInteger2, false);
    }

    private static int h(int i) {
        if (i >= 1536) {
            return 3;
        }
        if (i >= 1024) {
            return 4;
        }
        return i >= 512 ? 7 : 50;
    }

    private static boolean j(java.math.BigInteger bigInteger) {
        java.math.BigInteger bigInteger2 = e;
        if (bigInteger.bitLength() < bigInteger2.bitLength()) {
            bigInteger2 = bigInteger;
            bigInteger = bigInteger2;
        }
        return !org.bouncycastle.util.BigIntegers.q(bigInteger, bigInteger2);
    }

    private static java.math.BigInteger k(java.math.BigInteger bigInteger, boolean z) {
        if (!z) {
            if ((bigInteger.intValue() & 1) == 0) {
                throw new java.lang.IllegalArgumentException("RSA modulus is even");
            }
            if (org.bouncycastle.util.Properties.d("org.bouncycastle.rsa.allow_unsafe_mod")) {
                return bigInteger;
            }
            if (org.bouncycastle.util.Properties.b("org.bouncycastle.rsa.max_size", 16384) < bigInteger.bitLength()) {
                throw new java.lang.IllegalArgumentException("RSA modulus out of range");
            }
            if (j(bigInteger)) {
                throw new java.lang.IllegalArgumentException("RSA modulus has a small prime factor");
            }
            int iB = org.bouncycastle.util.Properties.b("org.bouncycastle.rsa.max_mr_tests", h(bigInteger.bitLength() / 2));
            if (iB > 0 && !org.bouncycastle.math.Primes.b(bigInteger, org.bouncycastle.crypto.CryptoServicesRegistrar.d(), iB).d()) {
                throw new java.lang.IllegalArgumentException("RSA modulus is not composite");
            }
        }
        d.a(bigInteger);
        return bigInteger;
    }

    public java.math.BigInteger g() {
        return this.c;
    }

    public java.math.BigInteger i() {
        return this.b;
    }

    public RSAKeyParameters(boolean z, java.math.BigInteger bigInteger, java.math.BigInteger bigInteger2, boolean z2) {
        super(z);
        if (!z && (bigInteger2.intValue() & 1) == 0) {
            throw new java.lang.IllegalArgumentException("RSA publicExponent is even");
        }
        this.b = d.b(bigInteger) ? bigInteger : k(bigInteger, z2);
        this.c = bigInteger2;
    }
}
