Skip to content

Commit fedf8b4

Browse files
committed
added check for system property capping MR tests
1 parent 951b13c commit fedf8b4

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

core/src/main/java/org/bouncycastle/crypto/params/RSAKeyParameters.java

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -88,22 +88,31 @@ private BigInteger validate(BigInteger modulus, boolean isInternal)
8888
}
8989

9090
int bits = modulus.bitLength() / 2;
91-
int iterations = bits >= 1536 ? 3
92-
: bits >= 1024 ? 4
93-
: bits >= 512 ? 7
94-
: 50;
91+
int iterations = Properties.asInteger("org.bouncycastle.rsa.max_mr_tests", getMRIterations(bits));
9592

96-
Primes.MROutput mr = Primes.enhancedMRProbablePrimeTest(modulus, CryptoServicesRegistrar.getSecureRandom(), iterations);
97-
if (!mr.isProvablyComposite())
93+
if (iterations > 0)
9894
{
99-
throw new IllegalArgumentException("RSA modulus is not composite");
95+
Primes.MROutput mr = Primes.enhancedMRProbablePrimeTest(modulus, CryptoServicesRegistrar.getSecureRandom(), iterations);
96+
if (!mr.isProvablyComposite())
97+
{
98+
throw new IllegalArgumentException("RSA modulus is not composite");
99+
}
100100
}
101101

102102
validated.add(modulus);
103103

104104
return modulus;
105105
}
106106

107+
private static int getMRIterations(int bits)
108+
{
109+
int iterations = bits >= 1536 ? 3
110+
: bits >= 1024 ? 4
111+
: bits >= 512 ? 7
112+
: 50;
113+
return iterations;
114+
}
115+
107116
public BigInteger getModulus()
108117
{
109118
return modulus;

0 commit comments

Comments
 (0)