2008-06-25 03:33:36 -04:00
|
|
|
/* mpz_millerrabin(n,reps) -- An implementation of the probabilistic primality
|
|
|
|
test found in Knuth's Seminumerical Algorithms book. If the function
|
|
|
|
mpz_millerrabin() returns 0 then n is not prime. If it returns 1, then n is
|
|
|
|
'probably' prime. The probability of a false positive is (1/4)**reps, where
|
|
|
|
reps is the number of internal passes of the probabilistic algorithm. Knuth
|
|
|
|
indicates that 25 passes are reasonable.
|
|
|
|
|
|
|
|
THE FUNCTIONS IN THIS FILE ARE FOR INTERNAL USE ONLY. THEY'RE ALMOST
|
|
|
|
CERTAIN TO BE SUBJECT TO INCOMPATIBLE CHANGES OR DISAPPEAR COMPLETELY IN
|
|
|
|
FUTURE GNU MP RELEASES.
|
|
|
|
|
|
|
|
Copyright 1991, 1993, 1994, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2005 Free
|
|
|
|
Software Foundation, Inc. Contributed by John Amanatides.
|
2011-12-05 03:47:04 -05:00
|
|
|
Copyright 2011, Brian Gladman
|
2008-06-25 03:33:36 -04:00
|
|
|
|
|
|
|
This file is part of the GNU MP Library.
|
|
|
|
|
|
|
|
The GNU MP 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.
|
|
|
|
|
|
|
|
The GNU MP Library is distributed in the hope that it will be useful, but
|
|
|
|
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
|
|
|
|
along with the GNU MP 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. */
|
|
|
|
|
2009-02-12 05:24:24 -05:00
|
|
|
#include "mpir.h"
|
2008-06-25 03:33:36 -04:00
|
|
|
#include "gmp-impl.h"
|
|
|
|
|
2011-12-04 16:56:25 -05:00
|
|
|
// This function is obsolete 4/12/2011
|
2008-06-25 03:33:36 -04:00
|
|
|
|
|
|
|
int
|
|
|
|
mpz_millerrabin (mpz_srcptr n, int reps)
|
|
|
|
{
|
|
|
|
gmp_randstate_t rstate;
|
|
|
|
int is_prime;
|
|
|
|
|
2011-12-04 16:56:25 -05:00
|
|
|
gmp_randinit_default(rstate);
|
|
|
|
is_prime = mpz_miller_rabin(n, reps, rstate);
|
|
|
|
gmp_randclear(rstate);
|
2008-06-25 03:33:36 -04:00
|
|
|
return is_prime;
|
|
|
|
}
|