math/strongprime.c: Reduce failures by adding some more slop bits.
authorMark Wooding <mdw@distorted.org.uk>
Thu, 11 May 2017 09:42:15 +0000 (10:42 +0100)
committerMark Wooding <mdw@distorted.org.uk>
Sun, 14 May 2017 03:00:35 +0000 (04:00 +0100)
In my experiments, failures were happening about 2--3% of the time,
which is way more than one is really willing to tolerate.

math/strongprime.c

index fc20bfe..e883492 100644 (file)
@@ -87,11 +87,11 @@ mp *strongprime_setup(const char *name, mp *d, pfilt *f, unsigned nbits,
    * i.e., if %$J \le N - (k + \log_2 N)$%.
    *
    * Experimentation shows that taking %$k + \log_2 N = 12$% works well for
-   * %$N = 1024$%, so %$k = 2$%.
+   * %$N = 1024$%, so %$k = 2$%.  Add a few extra bits for luck.
    */
 
   for (i = 1; i && nbits >> i; i <<= 1); assert(i);
-  for (slop = 2, nb = nbits; nb > 1; i >>= 1) {
+  for (slop = 6, nb = nbits; nb > 1; i >>= 1) {
     u = nb >> i;
     if (u) { slop += i; nb = u; }
   }