[Gmp-commit] /var/hg/gmp: 2 new changesets

mercurial at gmplib.org mercurial at gmplib.org
Thu Mar 6 18:00:11 UTC 2014


details:   /var/hg/gmp/rev/265c1b0c0e29
changeset: 16326:265c1b0c0e29
user:      Niels M?ller <nisse at lysator.liu.se>
date:      Thu Mar 06 18:51:29 2014 +0100
description:
mini-gmp: Fixed testing of mpz_probab_prime_p with composites.

details:   /var/hg/gmp/rev/dec8cfaa7096
changeset: 16327:dec8cfaa7096
user:      Niels M?ller <nisse at lysator.liu.se>
date:      Thu Mar 06 18:59:38 2014 +0100
description:
Additional tests for mpz_probab_prime_p.

diffstat:

 ChangeLog                   |   4 ++
 mini-gmp/tests/t-pprime_p.c |   1 +
 tests/mpz/t-pprime_p.c      |  79 ++++++++++++++++++++++++++++++++++++++++++++-
 3 files changed, 83 insertions(+), 1 deletions(-)

diffs (118 lines):

diff -r 8d71961d8ad2 -r dec8cfaa7096 ChangeLog
--- a/ChangeLog	Thu Mar 06 18:44:18 2014 +0100
+++ b/ChangeLog	Thu Mar 06 18:59:38 2014 +0100
@@ -1,5 +1,9 @@
 2014-03-06  Niels Möller  <nisse at lysator.liu.se>
 
+	* tests/mpz/t-pprime_p.c (check_composites): New function.
+	(check_primes): New function.
+	(main): Call them. Also use TESTS_REPS.
+
 	* mini-gmp/mini-gmp.c (gmp_millerrabin): New internal function.
 	(mpz_probab_prime_p): New function.
 	* mini-gmp/mini-gmp.h (mpz_probab_prime_p): Declare it.
diff -r 8d71961d8ad2 -r dec8cfaa7096 mini-gmp/tests/t-pprime_p.c
--- a/mini-gmp/tests/t-pprime_p.c	Thu Mar 06 18:44:18 2014 +0100
+++ b/mini-gmp/tests/t-pprime_p.c	Thu Mar 06 18:59:38 2014 +0100
@@ -126,6 +126,7 @@
 
       mini_urandomb (bs, 32);
       size_range = mpz_get_ui (bs) % 12 + 1; /* 0..4096 bit operands */
+      mini_rrandomb (b, size);
 
       /* Exclude trivial factors */
       if (mpz_cmp_ui (a, 1) == 0)
diff -r 8d71961d8ad2 -r dec8cfaa7096 tests/mpz/t-pprime_p.c
--- a/tests/mpz/t-pprime_p.c	Thu Mar 06 18:44:18 2014 +0100
+++ b/tests/mpz/t-pprime_p.c	Thu Mar 06 18:59:38 2014 +0100
@@ -101,12 +101,89 @@
   mpz_clear (n);
 }
 
+void
+check_composites (int count)
+{
+  int i;
+  mpz_t a, b, n, bs;
+  unsigned long size_range, size;
+  gmp_randstate_ptr rands = RANDS;
+
+  mpz_init (a);
+  mpz_init (b);
+  mpz_init (n);
+  mpz_init (bs);
+
+  for (i = 0; i < count; i++)
+    {
+      mpz_urandomb (bs, rands, 32);
+      size_range = mpz_get_ui (bs) % 13 + 1; /* 0..8192 bit operands */
+
+      mpz_urandomb (bs, rands, size_range);
+      size = mpz_get_ui (bs);
+      mpz_rrandomb (a, rands, size);
+
+      mpz_urandomb (bs, rands, 32);
+      size_range = mpz_get_ui (bs) % 13 + 1; /* 0..8192 bit operands */
+      mpz_rrandomb (b, rands, size);
+
+      /* Exclude trivial factors */
+      if (mpz_cmp_ui (a, 1) == 0)
+	mpz_set_ui (a, 2);
+      if (mpz_cmp_ui (b, 1) == 0)
+	mpz_set_ui (b, 2);
+
+      mpz_mul (n, a, b);
+      
+      check_pn (n, 0);
+    }
+  mpz_clear (a);
+  mpz_clear (b);
+  mpz_clear (n);
+  mpz_clear (bs);
+}
+
+static void
+check_primes (void)
+{
+  static const char * const primes[] = {
+    "2", "17", "65537",
+    /* diffie-hellman-group1-sha1, also "Well known group 2" in RFC
+       2412, 2^1024 - 2^960 - 1 + 2^64 * { [2^894 pi] + 129093 } */  
+    "0xFFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD1"
+    "29024E088A67CC74020BBEA63B139B22514A08798E3404DD"
+    "EF9519B3CD3A431B302B0A6DF25F14374FE1356D6D51C245"
+    "E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406B7ED"
+    "EE386BFB5A899FA5AE9F24117C4B1FE649286651ECE65381"
+    "FFFFFFFFFFFFFFFF",
+    NULL
+  };
+
+  mpz_t n;
+  int i;
+
+  mpz_init (n);
+
+  for (i = 0; primes[i]; i++)
+    {
+      mpz_set_str_or_abort (n, primes[i], 0);
+      check_one (n, 1);
+    }
+  mpz_clear (n);  
+}
+
 int
-main (void)
+main (int argc, char **argv)
 {
+  int count = 1000;
+
+  TESTS_REPS (count, argv, argc);
+
   tests_start ();
 
   check_small ();
+  check_composites (count);
+  check_primes ();
 
   tests_end ();
   exit (0);


More information about the gmp-commit mailing list