2009-08-17 05:03:35 -04:00
|
|
|
/* mpz_nextprime(x,y) - compute the next probable prime > y and store that in x
|
2008-06-25 03:33:36 -04:00
|
|
|
|
2009-08-17 05:03:35 -04:00
|
|
|
Copyright 2009 Jason Moxham
|
2008-06-25 03:33:36 -04:00
|
|
|
|
2009-08-17 05:03:35 -04:00
|
|
|
This file is part of the MPIR Library.
|
2008-06-25 03:33:36 -04:00
|
|
|
|
2009-08-17 05:03:35 -04:00
|
|
|
The MPIR Library is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU Lesser General Public License as published
|
|
|
|
by the Free Software Foundation; either version 2.1 of the License, or (at
|
|
|
|
your option) any later version.
|
2008-06-25 03:33:36 -04:00
|
|
|
|
2009-08-17 05:03:35 -04:00
|
|
|
The MPIR Library is distributed in the hope that it will be useful, but
|
2008-06-25 03:33:36 -04:00
|
|
|
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
|
|
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
|
|
|
License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public License
|
2009-08-17 05:03:35 -04:00
|
|
|
along with the MPIR Library; see the file COPYING.LIB. If not, write
|
|
|
|
to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
|
|
|
Boston, MA 02110-1301, USA.
|
|
|
|
*/
|
2008-06-25 03:33:36 -04:00
|
|
|
|
2009-02-12 05:24:24 -05:00
|
|
|
#include "mpir.h"
|
2008-06-25 03:33:36 -04:00
|
|
|
#include "gmp-impl.h"
|
|
|
|
|
2009-08-17 07:53:22 -04:00
|
|
|
|
2014-02-16 12:23:27 -05:00
|
|
|
/* This function is Obsolete 17/8/2009 */
|
2014-03-26 08:39:08 -04:00
|
|
|
|
|
|
|
/*
|
|
|
|
But people use it anyway!
|
|
|
|
|
|
|
|
FIXME: This function should prove the primality of x using
|
|
|
|
ECPP or APR-CL.
|
|
|
|
*/
|
2014-02-16 12:23:27 -05:00
|
|
|
void mpz_nextprime(mpz_ptr x, mpz_srcptr y)
|
2011-11-23 10:13:56 -05:00
|
|
|
{
|
2011-12-04 13:43:13 -05:00
|
|
|
gmp_randstate_t rnd;
|
|
|
|
|
2014-02-16 12:23:27 -05:00
|
|
|
gmp_randinit_default(rnd);
|
|
|
|
mpz_next_prime_candidate(x, y, rnd);
|
2014-03-31 09:30:33 -04:00
|
|
|
|
|
|
|
if (mpz_cmp_ui(x, 1000000L) >= 0) /* nextprime_candidate sieves primes up to 1000 */
|
2014-03-26 08:39:08 -04:00
|
|
|
{
|
2014-03-31 09:30:33 -04:00
|
|
|
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);
|
|
|
|
}
|
2014-03-26 08:39:08 -04:00
|
|
|
}
|
|
|
|
|
2014-02-16 12:23:27 -05:00
|
|
|
gmp_randclear(rnd);
|
|
|
|
}
|