diff options
author | tege <tege@gmplib.org> | 2001-10-23 01:44:12 +0200 |
---|---|---|
committer | tege <tege@gmplib.org> | 2001-10-23 01:44:12 +0200 |
commit | d2f3ef53c50e06d1d21d5f9d6c8e9cd942cadf63 (patch) | |
tree | b6b98f9698bf6599634c93bf2cacba0b802e003e /mpz | |
parent | ed82887c365d381964a59c71fee9b035125f27ad (diff) | |
download | gmp-d2f3ef53c50e06d1d21d5f9d6c8e9cd942cadf63.tar.gz |
(mpz_millerrabin): Remove function and its descendant.
Diffstat (limited to 'mpz')
-rw-r--r-- | mpz/pprime_p.c | 76 |
1 files changed, 0 insertions, 76 deletions
diff --git a/mpz/pprime_p.c b/mpz/pprime_p.c index e20f7dd1f..819f48084 100644 --- a/mpz/pprime_p.c +++ b/mpz/pprime_p.c @@ -151,79 +151,3 @@ isprime (unsigned long int t) } return 0; } - -static int millerrabin _PROTO ((mpz_srcptr n, mpz_srcptr nm1, - mpz_ptr x, mpz_ptr y, - mpz_srcptr q, unsigned long int k)); - -static int -mpz_millerrabin (mpz_srcptr n, int reps) -{ - int r; - mpz_t nm1, x, y, q; - unsigned long int k; - gmp_randstate_t rstate; - int is_prime; - TMP_DECL (marker); - TMP_MARK (marker); - - MPZ_TMP_INIT (nm1, SIZ (n) + 1); - mpz_sub_ui (nm1, n, 1L); - - MPZ_TMP_INIT (x, SIZ (n)); - MPZ_TMP_INIT (y, 2 * SIZ (n)); /* mpz_powm_ui needs excessive memory!!! */ - - /* Perform a Fermat test. */ - mpz_set_ui (x, 210L); - mpz_powm (y, x, nm1, n); - if (mpz_cmp_ui (y, 1L) != 0) - { - TMP_FREE (marker); - return 0; - } - - MPZ_TMP_INIT (q, SIZ (n)); - - /* Find q and k, where q is odd and n = 1 + 2**k * q. */ - k = mpz_scan1 (nm1, 0L); - mpz_tdiv_q_2exp (q, nm1, k); - - gmp_randinit (rstate, GMP_RAND_ALG_DEFAULT, 32L); - - is_prime = 1; - for (r = 0; r < reps && is_prime; r++) - { - do - mpz_urandomb (x, rstate, mpz_sizeinbase (n, 2) - 1); - while (mpz_cmp_ui (x, 1L) <= 0); - - is_prime = millerrabin (n, nm1, x, y, q, k); - } - - gmp_randclear (rstate); - - TMP_FREE (marker); - return is_prime; -} - -static int -millerrabin (mpz_srcptr n, mpz_srcptr nm1, mpz_ptr x, mpz_ptr y, - mpz_srcptr q, unsigned long int k) -{ - unsigned long int i; - - mpz_powm (y, x, q, n); - - if (mpz_cmp_ui (y, 1L) == 0 || mpz_cmp (y, nm1) == 0) - return 1; - - for (i = 1; i < k; i++) - { - mpz_powm_ui (y, y, 2L, n); - if (mpz_cmp (y, nm1) == 0) - return 1; - if (mpz_cmp_ui (y, 1L) == 0) - return 0; - } - return 0; -} |