diff options
author | Nick Mathewson <nickm@torproject.org> | 2010-11-29 15:53:33 -0500 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2010-11-29 16:00:47 -0500 |
commit | 89e97bdf940d6c063fc9860306395c500d1c7027 (patch) | |
tree | 4363f41168ede3a9aa6da61cfc8282508b84568d /src/common/compat.c | |
parent | 0eafe23ff38dd895c15b2deba70e5df997cf97e9 (diff) | |
download | tor-89e97bdf940d6c063fc9860306395c500d1c7027.tar.gz tor-89e97bdf940d6c063fc9860306395c500d1c7027.zip |
Add wrappers function for libc random()
On windows, it's called something different.
Diffstat (limited to 'src/common/compat.c')
-rw-r--r-- | src/common/compat.c | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/src/common/compat.c b/src/common/compat.c index 20394b4c5d..4d556a85e6 100644 --- a/src/common/compat.c +++ b/src/common/compat.c @@ -1679,6 +1679,30 @@ tor_lookup_hostname(const char *name, uint32_t *addr) return -1; } +/** Initialize the insecure libc RNG. */ +void +tor_init_weak_random(unsigned seed) +{ +#ifdef MS_WINDOWS + srand(seed); +#else + srandom(seed); +#endif +} + +/** Return a randomly chosen value in the range 0..TOR_RAND_MAX. This + * entropy will not be cryptographically strong; do not rely on it + * for anything an adversary should not be able to predict. */ +long +tor_weak_random(void) +{ +#ifdef MS_WINDOWS + return rand(); +#else + return random(); +#endif +} + /** Hold the result of our call to <b>uname</b>. */ static char uname_result[256]; /** True iff uname_result is set. */ |