projects
/
oweals
/
gnunet.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
change default configurations on systems with UNIX domain sockets to NOT specify...
[oweals/gnunet.git]
/
src
/
util
/
crypto_random.c
diff --git
a/src/util/crypto_random.c
b/src/util/crypto_random.c
index 9fc14863cc4f30d3d85d95f45a56c3e692113a0a..121dbef9a544809cf56b9498243e729bec433347 100644
(file)
--- a/
src/util/crypto_random.c
+++ b/
src/util/crypto_random.c
@@
-38,10
+38,10
@@
/* The code is derived from glibc, obviously */
#if MINGW
#ifdef RANDOM
/* The code is derived from glibc, obviously */
#if MINGW
#ifdef RANDOM
-#
undef RANDOM
+#undef RANDOM
#endif
#ifdef SRANDOM
#endif
#ifdef SRANDOM
-#
undef SRANDOM
+#undef SRANDOM
#endif
#define RANDOM() glibc_weak_rand32()
#define SRANDOM(s) glibc_weak_srand32(s)
#endif
#define RANDOM() glibc_weak_rand32()
#define SRANDOM(s) glibc_weak_srand32(s)
@@
-57,6
+57,7
@@
int32_t
glibc_weak_rand32 ()
{
int32_t val = glibc_weak_rand32_state;
glibc_weak_rand32 ()
{
int32_t val = glibc_weak_rand32_state;
+
val = ((glibc_weak_rand32_state * 1103515245) + 12345) & 0x7fffffff;
glibc_weak_rand32_state = val;
return val;
val = ((glibc_weak_rand32_state * 1103515245) + 12345) & 0x7fffffff;
glibc_weak_rand32_state = val;
return val;
@@
-74,6
+75,17
@@
weak_random ()
return ((double) RANDOM () / RAND_MAX);
}
return ((double) RANDOM () / RAND_MAX);
}
+/**
+ * Seed a weak random generator. Only GNUNET_CRYPTO_QUALITY_WEAK-mode generator
+ * can be seeded.
+ *
+ * @param seed the seed to use
+ */
+void
+GNUNET_CRYPTO_seed_weak_random (int32_t seed)
+{
+ SRANDOM (seed);
+}
/**
* Produce a random value.
/**
* Produce a random value.
@@
-291,7
+303,7
@@
void __attribute__ ((constructor)) GNUNET_CRYPTO_random_init ()
gcry_control (GCRYCTL_DISABLE_SECMEM, 0);
if (!gcry_check_version (GCRYPT_VERSION))
{
gcry_control (GCRYCTL_DISABLE_SECMEM, 0);
if (!gcry_check_version (GCRYPT_VERSION))
{
-
fprintf
(stderr,
+
FPRINTF
(stderr,
_
("libgcrypt has not the expected version (version %s is required).\n"),
GCRYPT_VERSION);
_
("libgcrypt has not the expected version (version %s is required).\n"),
GCRYPT_VERSION);
@@
-302,8
+314,9
@@
void __attribute__ ((constructor)) GNUNET_CRYPTO_random_init ()
#endif
gcry_set_progress_handler (&entropy_generator, NULL);
atexit (&killfind);
#endif
gcry_set_progress_handler (&entropy_generator, NULL);
atexit (&killfind);
- SRANDOM (time (NULL) ^
- GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, UINT32_MAX));
+ GNUNET_CRYPTO_seed_weak_random (time (NULL) ^
+ GNUNET_CRYPTO_random_u32
+ (GNUNET_CRYPTO_QUALITY_NONCE, UINT32_MAX));
}
}