[Gmp-commit] /var/hg/gmp: 3 new changesets
mercurial at gmplib.org
mercurial at gmplib.org
Sun Nov 1 22:18:34 UTC 2015
details: /var/hg/gmp/rev/56ae7c0d086d
changeset: 16928:56ae7c0d086d
user: Torbjorn Granlund <torbjorng at google.com>
date: Sun Nov 01 23:17:05 2015 +0100
description:
Default to /dev/random seeding.
details: /var/hg/gmp/rev/8ce23e5d1861
changeset: 16929:8ce23e5d1861
user: Torbjorn Granlund <torbjorng at google.com>
date: Sun Nov 01 23:17:13 2015 +0100
description:
ChangeLog
details: /var/hg/gmp/rev/b08f9b35a40a
changeset: 16930:b08f9b35a40a
user: Torbjorn Granlund <torbjorng at google.com>
date: Sun Nov 01 23:18:32 2015 +0100
description:
Trivial merge.
diffstat:
.hgtags | 1 +
ChangeLog | 5 +++
tests/misc.c | 76 ++++++++++++++++++++++++++++++++++++++---------------------
3 files changed, 55 insertions(+), 27 deletions(-)
diffs (129 lines):
diff -r 89a2bc9b845c -r b08f9b35a40a .hgtags
--- a/.hgtags Sun Nov 01 14:57:58 2015 +0100
+++ b/.hgtags Sun Nov 01 23:18:32 2015 +0100
@@ -11,3 +11,4 @@
3da36b326561f0a99cca688fa7910889b830a8fb gmp-4_3_0
4b14ab8c899a5edd7be6bf0f1a9a04aef8958825 rel-5.1.0
e10ffb0afa6b6728f59cf90dd1584cdd00fe4a3a rel-5.1.1
+89a2bc9b845cf825aec3ad77c98cae318d91a7d7 gmp-6.1.0
diff -r 89a2bc9b845c -r b08f9b35a40a ChangeLog
--- a/ChangeLog Sun Nov 01 14:57:58 2015 +0100
+++ b/ChangeLog Sun Nov 01 23:18:32 2015 +0100
@@ -1,3 +1,8 @@
+2015-11-01 Torbjörn Granlund <torbjorng at google.com>
+
+ * tests/misc.c (seed_from_tod, seed_from_urandom): New functions.
+ (tests_rand_start): Use them.
+
2015-11-01 Marco Bodrato <bodrato at mail.dm.unipi.it>
* Version 6.1.0 released.
diff -r 89a2bc9b845c -r b08f9b35a40a tests/misc.c
--- a/tests/misc.c Sun Nov 01 14:57:58 2015 +0100
+++ b/tests/misc.c Sun Nov 01 23:18:32 2015 +0100
@@ -1,6 +1,6 @@
/* Miscellaneous test program support routines.
-Copyright 2000-2003, 2005, 2013 Free Software Foundation, Inc.
+Copyright 2000-2003, 2005, 2013, 2015 Free Software Foundation, Inc.
This file is part of the GNU MP Library test suite.
@@ -63,13 +63,42 @@
tests_memory_end ();
}
+static void
+seed_from_tod (gmp_randstate_ptr rands)
+{
+ unsigned long seed;
+#if HAVE_GETTIMEOFDAY
+ struct timeval tv;
+ gettimeofday (&tv, NULL);
+ seed = tv.tv_sec ^ (tv.tv_usec << 12);
+ seed &= 0xffffffff;
+#else
+ time_t tv;
+ time (&tv);
+ seed = tv;
+#endif
+ gmp_randseed_ui (rands, seed);
+ printf ("Seed GMP_CHECK_RANDOMIZE=%lu (include this in bug reports)\n", seed);
+}
+
+static void
+seed_from_urandom (gmp_randstate_ptr rands, FILE *fs)
+{
+ mpz_t seed;
+ unsigned char buf[6];
+ fread (buf, 1, 6, fs);
+ mpz_init (seed);
+ mpz_import (seed, 6, 1, 1, 0, 0, buf);
+ gmp_randseed (rands, seed);
+ gmp_printf ("Seed GMP_CHECK_RANDOMIZE=%Zd (include this in bug reports)\n", seed);
+ mpz_clear (seed);
+}
void
tests_rand_start (void)
{
gmp_randstate_ptr rands;
- char *perform_seed;
- unsigned long seed;
+ char *seed_string;
if (__gmp_rands_initialized)
{
@@ -82,35 +111,28 @@
__gmp_rands_initialized = 1;
rands = __gmp_rands;
- perform_seed = getenv ("GMP_CHECK_RANDOMIZE");
- if (perform_seed != NULL)
+ seed_string = getenv ("GMP_CHECK_RANDOMIZE");
+ if (seed_string != NULL)
{
-#ifdef HAVE_STRTOUL
- seed = strtoul (perform_seed, 0, 0);
-#else
- /* This will not work right for seeds >= 2^31 on 64-bit machines.
- Perhaps use atol unconditionally? Is that ubiquitous? */
- seed = atoi (perform_seed);
-#endif
- if (! (seed == 0 || seed == 1))
+ if (strcmp (seed_string, "0") != 0 &&
+ strcmp (seed_string, "1") != 0)
{
- printf ("Re-seeding with GMP_CHECK_RANDOMIZE=%lu\n", seed);
- gmp_randseed_ui (rands, seed);
+ mpz_t seed;
+ mpz_init_set_str (seed, seed_string, 0);
+ gmp_printf ("Re-seeding with GMP_CHECK_RANDOMIZE=%Zd\n", seed);
+ gmp_randseed (rands, seed);
+ mpz_clear (seed);
}
else
{
-#if HAVE_GETTIMEOFDAY
- struct timeval tv;
- gettimeofday (&tv, NULL);
- seed = tv.tv_sec ^ (tv.tv_usec << 12);
- seed &= 0xffffffff;
-#else
- time_t tv;
- time (&tv);
- seed = tv;
-#endif
- gmp_randseed_ui (rands, seed);
- printf ("Seed GMP_CHECK_RANDOMIZE=%lu (include this in bug reports)\n", seed);
+ FILE *fs = fopen ("/dev/urandom", "r");
+ if (fs != NULL)
+ {
+ seed_from_urandom (rands, fs);
+ fclose (fs);
+ }
+ else
+ seed_from_tod (rands);
}
fflush (stdout);
}
More information about the gmp-commit
mailing list