Skip to content

Commit

Permalink
github #486 added bitLength check for GCD test
Browse files Browse the repository at this point in the history
  • Loading branch information
dghgit committed Apr 4, 2019
1 parent f72dd46 commit 522f6de
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions core/src/main/java/org/bouncycastle/util/BigIntegers.java
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,8 @@ public static BigInteger createRandomBigInteger(int bitLength, SecureRandom rand
+ "ce86165a978d719ebf647f362d33fca29cd179fb42401cbaf3df0c614056f9c8"
+ "f3cfd51e474afb6bc6974f78db8aba8e9e517fded658591ab7502bd41849462f",
16);
private static final int SQR_MAX_SMALL = 20; // bitlength of 743 * 743

/**
* Return a prime number candidate of the specified bit length.
*
Expand Down Expand Up @@ -181,10 +183,12 @@ public static BigInteger createRandomPrime(int bitLength, int certainty, SecureR
base[base.length - 1] |= 0x01;

rv = new BigInteger(1, base);

while (!rv.gcd(SMALL_PRIMES_PRODUCT).equals(ONE))
if (bitLength > SQR_MAX_SMALL)
{
rv = rv.add(TWO);
while (!rv.gcd(SMALL_PRIMES_PRODUCT).equals(ONE))
{
rv = rv.add(TWO);
}
}
}
while (!rv.isProbablePrime(certainty));
Expand Down

0 comments on commit 522f6de

Please sign in to comment.