summaryrefslogtreecommitdiff
path: root/src/lib/crypt_ops
diff options
context:
space:
mode:
authorDavid Goulet <dgoulet@torproject.org>2019-03-01 09:36:23 -0500
committerDavid Goulet <dgoulet@torproject.org>2019-03-01 09:36:23 -0500
commit13e93bdfd5a3bc8349723a0e3a9e05f2dd300f99 (patch)
tree6e5d1e896150cb136fb092ca9a5633c93d3c7e85 /src/lib/crypt_ops
parentcb0d40304968735db5e85fc81e451a149bf05cc0 (diff)
parent64f594499a3e8893a6097fa5db7d47962f83d2f5 (diff)
downloadtor-13e93bdfd5a3bc8349723a0e3a9e05f2dd300f99.tar.gz
tor-13e93bdfd5a3bc8349723a0e3a9e05f2dd300f99.zip
Merge branch 'tor-github/pr/718'
Diffstat (limited to 'src/lib/crypt_ops')
-rw-r--r--src/lib/crypt_ops/crypto_rand.h9
1 files changed, 9 insertions, 0 deletions
diff --git a/src/lib/crypt_ops/crypto_rand.h b/src/lib/crypt_ops/crypto_rand.h
index 6eef22ed4d..6f09aedf6a 100644
--- a/src/lib/crypt_ops/crypto_rand.h
+++ b/src/lib/crypt_ops/crypto_rand.h
@@ -68,6 +68,15 @@ unsigned crypto_fast_rng_get_uint(crypto_fast_rng_t *rng, unsigned limit);
uint64_t crypto_fast_rng_get_uint64(crypto_fast_rng_t *rng, uint64_t limit);
double crypto_fast_rng_get_double(crypto_fast_rng_t *rng);
+/**
+ * Using the fast_rng <b>rng</b>, yield true with probability
+ * 1/<b>n</b>. Otherwise yield false.
+ *
+ * <b>n</b> must not be zero.
+ **/
+#define crypto_fast_rng_one_in_n(rng, n) \
+ (0 == (crypto_fast_rng_get_uint((rng), (n))))
+
crypto_fast_rng_t *get_thread_fast_rng(void);
#ifdef CRYPTO_PRIVATE