summaryrefslogtreecommitdiff
path: root/src/lib/intmath/weakrng.h
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2018-06-28 11:39:49 -0400
committerNick Mathewson <nickm@torproject.org>2018-06-28 11:39:49 -0400
commit48ebd9bf76a0e5ff60b88f8906919016de82e819 (patch)
tree76047a0a4227be696a54987d7d6f4430ec4597e3 /src/lib/intmath/weakrng.h
parentaa3edfd2053bb418907f204e171ae8f7e78c30eb (diff)
downloadtor-48ebd9bf76a0e5ff60b88f8906919016de82e819.tar.gz
tor-48ebd9bf76a0e5ff60b88f8906919016de82e819.zip
Move weakrng into lib/intmath
Diffstat (limited to 'src/lib/intmath/weakrng.h')
-rw-r--r--src/lib/intmath/weakrng.h25
1 files changed, 25 insertions, 0 deletions
diff --git a/src/lib/intmath/weakrng.h b/src/lib/intmath/weakrng.h
new file mode 100644
index 0000000000..e5a88b30fe
--- /dev/null
+++ b/src/lib/intmath/weakrng.h
@@ -0,0 +1,25 @@
+/* Copyright (c) 2003, Roger Dingledine
+ * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
+ * Copyright (c) 2007-2018, The Tor Project, Inc. */
+/* See LICENSE for licensing information */
+
+#ifndef TOR_WEAKRNG_H
+#define TOR_WEAKRNG_H
+
+#include "lib/cc/torint.h"
+
+/* ===== Insecure rng */
+typedef struct tor_weak_rng_t {
+ uint32_t state;
+} tor_weak_rng_t;
+
+#define TOR_WEAK_RNG_INIT {383745623}
+#define TOR_WEAK_RANDOM_MAX (INT_MAX)
+void tor_init_weak_random(tor_weak_rng_t *weak_rng, unsigned seed);
+int32_t tor_weak_random(tor_weak_rng_t *weak_rng);
+int32_t tor_weak_random_range(tor_weak_rng_t *rng, int32_t top);
+/** Randomly return true according to <b>rng</b> with probability 1 in
+ * <b>n</b> */
+#define tor_weak_random_one_in_n(rng, n) (0==tor_weak_random_range((rng),(n)))
+
+#endif