Skip to content

Commit 73780ac

Browse files
committed
BJA-694 cleaned up primality test
1 parent 4988382 commit 73780ac

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

core/src/main/java/org/bouncycastle/crypto/generators/RSAKeyPairGenerator.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,10 @@ public class RSAKeyPairGenerator
2020
private static final BigInteger ONE = BigInteger.valueOf(1);
2121

2222
private RSAKeyGenerationParameters param;
23-
private int iterations;
2423

2524
public void init(KeyGenerationParameters param)
2625
{
2726
this.param = (RSAKeyGenerationParameters)param;
28-
this.iterations = getNumberOfIterations(this.param.getStrength(), this.param.getCertainty());
2927
}
3028

3129
public AsymmetricCipherKeyPair generateKeyPair()
@@ -159,6 +157,8 @@ public AsymmetricCipherKeyPair generateKeyPair()
159157
*/
160158
protected BigInteger chooseRandomPrime(int bitlength, BigInteger e, BigInteger sqrdBound)
161159
{
160+
int iterations = getNumberOfIterations(bitlength, param.getCertainty());
161+
162162
for (int i = 0; i != 5 * bitlength; i++)
163163
{
164164
BigInteger p = new BigInteger(bitlength, 1, param.getRandom());
@@ -173,7 +173,7 @@ protected BigInteger chooseRandomPrime(int bitlength, BigInteger e, BigInteger s
173173
continue;
174174
}
175175

176-
if (!isProbablePrime(p))
176+
if (!isProbablePrime(p, iterations))
177177
{
178178
continue;
179179
}
@@ -189,7 +189,7 @@ protected BigInteger chooseRandomPrime(int bitlength, BigInteger e, BigInteger s
189189
throw new IllegalStateException("unable to generate prime number for RSA key");
190190
}
191191

192-
protected boolean isProbablePrime(BigInteger x)
192+
protected boolean isProbablePrime(BigInteger x, int iterations)
193193
{
194194
/*
195195
* Primes class for FIPS 186-4 C.3 primality checking

0 commit comments

Comments
 (0)