github added greatest common divisor test to weed out poor candidates
@@ -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.
*
@@ -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));
