added check for system property capping MR tests
@@ -88,22 +88,31 @@ private BigInteger validate(BigInteger modulus, boolean isInternal)
}
int bits = modulus.bitLength() / 2;
- int iterations = bits >= 1536 ? 3
- : bits >= 1024 ? 4
- : bits >= 512 ? 7
- : 50;
+ int iterations = Properties.asInteger("org.bouncycastle.rsa.max_mr_tests", getMRIterations(bits));
+ if (iterations > 0)
+ {
Primes.MROutput mr = Primes.enhancedMRProbablePrimeTest(modulus, CryptoServicesRegistrar.getSecureRandom(), iterations);
if (!mr.isProvablyComposite())
{
throw new IllegalArgumentException("RSA modulus is not composite");
}
+ }
validated.add(modulus);
return modulus;
}
+ private static int getMRIterations(int bits)
+ {
+ int iterations = bits >= 1536 ? 3
+ : bits >= 1024 ? 4
+ : bits >= 512 ? 7
+ : 50;
+ return iterations;
+ }
+
public BigInteger getModulus()
{
return modulus;
