Skip to content

Commit

Permalink
github #484 added greatest common divisor test to weed out poor candi…
Browse files Browse the repository at this point in the history
…dates
  • Loading branch information
dghgit committed Apr 4, 2019
1 parent 868720f commit f72dd46
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions core/src/main/java/org/bouncycastle/util/BigIntegers.java
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,13 @@ public static BigInteger createRandomBigInteger(int bitLength, SecureRandom rand
return new BigInteger(1, createRandom(bitLength, random));
}

// Hexadecimal value of the product of the 131 smallest odd primes from 3 to 743
private static final BigInteger SMALL_PRIMES_PRODUCT = new BigInteger(
"8138e8a0fcf3a4e84a771d40fd305d7f4aa59306d7251de54d98af8fe95729a1f"
+ "73d893fa424cd2edc8636a6c3285e022b0e3866a565ae8108eed8591cd4fe8d2"
+ "ce86165a978d719ebf647f362d33fca29cd179fb42401cbaf3df0c614056f9c8"
+ "f3cfd51e474afb6bc6974f78db8aba8e9e517fded658591ab7502bd41849462f",
16);
/**
* Return a prime number candidate of the specified bit length.
*
Expand Down Expand Up @@ -174,6 +181,11 @@ 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))
{
rv = rv.add(TWO);
}
}
while (!rv.isProbablePrime(certainty));

Expand Down

0 comments on commit f72dd46

Please sign in to comment.