From 540ff246b952bd91381bfe4fdfbc613983326379 Mon Sep 17 00:00:00 2001 From: Mark Wooding Date: Thu, 11 May 2017 10:42:15 +0100 Subject: [PATCH] math/strongprime.c: Reduce failures by adding some more slop bits. 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 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/math/strongprime.c b/math/strongprime.c index fc20bfea..e8834925 100644 --- a/math/strongprime.c +++ b/math/strongprime.c @@ -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; } } -- 2.11.0