aboutsummaryrefslogtreecommitdiff
path: root/src/common/compat.c
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2010-11-30 19:23:40 -0500
committerNick Mathewson <nickm@torproject.org>2010-11-30 19:23:40 -0500
commit3ed7505dc5684a235f87042d074b39ad35b4e415 (patch)
tree8eb410908d08550d9ac3bd1245fd800160cca39a /src/common/compat.c
parent8fa4450fde435bcab5e050b3a9b2b34c072f40b9 (diff)
parentad87d6172bc8b06a851da84f5a96ae87446ef90b (diff)
downloadtor-3ed7505dc5684a235f87042d074b39ad35b4e415.tar
tor-3ed7505dc5684a235f87042d074b39ad35b4e415.tar.gz
Merge remote branch 'origin/maint-0.2.2'
Conflicts: src/or/relay.c
Diffstat (limited to 'src/common/compat.c')
-rw-r--r--src/common/compat.c24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/common/compat.c b/src/common/compat.c
index b7f4f17ca..0ebad62de 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. */