From 0d8b59ca28a1bb29a75a9cfa84a27d59bcdf11f5 Mon Sep 17 00:00:00 2001 From: William Hart Date: Wed, 26 Mar 2014 12:39:08 +0000 Subject: [PATCH] Fix mpz_nextprime so it runs 25 rounds of miller-rabin in total (same as GMP). --- mpz/nextprime.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/mpz/nextprime.c b/mpz/nextprime.c index 97b17ed4..75f3248c 100644 --- a/mpz/nextprime.c +++ b/mpz/nextprime.c @@ -25,11 +25,25 @@ Boston, MA 02110-1301, USA. /* This function is Obsolete 17/8/2009 */ + +/* + But people use it anyway! + + FIXME: This function should prove the primality of x using + ECPP or APR-CL. +*/ void mpz_nextprime(mpz_ptr x, mpz_srcptr y) { gmp_randstate_t rnd; gmp_randinit_default(rnd); mpz_next_prime_candidate(x, y, rnd); + + while (!mpz_miller_rabin (x, 23, rnd)) /* we've done 2 rounds already, do another 23 */ + { + mpz_add_ui(x, x, 2); + mpz_next_prime_candidate(x, x, rnd); + } + gmp_randclear(rnd); }