diff options
author | Christian Grothoff <christian@grothoff.org> | 2011-11-23 19:23:03 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2011-11-23 19:23:03 +0000 |
commit | a39e9010af50091561d45bf04bfedd10fb4cc70a (patch) | |
tree | bd7c2e5c736fa4e49e900e4b714e746a3cc0de2f /src/util/crypto_random.c | |
parent | 383241240e8b1409c5e36dd00074af8402aa6c10 (diff) | |
download | gnunet-a39e9010af50091561d45bf04bfedd10fb4cc70a.tar.gz gnunet-a39e9010af50091561d45bf04bfedd10fb4cc70a.zip |
LRN: fixing 1956 by using a better random generator on W32
Diffstat (limited to 'src/util/crypto_random.c')
-rw-r--r-- | src/util/crypto_random.c | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/src/util/crypto_random.c b/src/util/crypto_random.c index 719acf07c..9fc14863c 100644 --- a/src/util/crypto_random.c +++ b/src/util/crypto_random.c | |||
@@ -34,6 +34,35 @@ | |||
34 | 34 | ||
35 | #define LOG_STRERROR(kind,syscall) GNUNET_log_from_strerror (kind, "util", syscall) | 35 | #define LOG_STRERROR(kind,syscall) GNUNET_log_from_strerror (kind, "util", syscall) |
36 | 36 | ||
37 | /* TODO: ndurner, move this to plibc? */ | ||
38 | /* The code is derived from glibc, obviously */ | ||
39 | #if MINGW | ||
40 | #ifdef RANDOM | ||
41 | # undef RANDOM | ||
42 | #endif | ||
43 | #ifdef SRANDOM | ||
44 | # undef SRANDOM | ||
45 | #endif | ||
46 | #define RANDOM() glibc_weak_rand32() | ||
47 | #define SRANDOM(s) glibc_weak_srand32(s) | ||
48 | static int32_t glibc_weak_rand32_state = 1; | ||
49 | |||
50 | void | ||
51 | glibc_weak_srand32 (int32_t s) | ||
52 | { | ||
53 | glibc_weak_rand32_state = s; | ||
54 | } | ||
55 | |||
56 | int32_t | ||
57 | glibc_weak_rand32 () | ||
58 | { | ||
59 | int32_t val = glibc_weak_rand32_state; | ||
60 | val = ((glibc_weak_rand32_state * 1103515245) + 12345) & 0x7fffffff; | ||
61 | glibc_weak_rand32_state = val; | ||
62 | return val; | ||
63 | } | ||
64 | #endif | ||
65 | |||
37 | /** | 66 | /** |
38 | * Create a cryptographically weak pseudo-random number in the interval of 0 to 1. | 67 | * Create a cryptographically weak pseudo-random number in the interval of 0 to 1. |
39 | * | 68 | * |