aboutsummaryrefslogtreecommitdiff
path: root/src/lib/crypt_ops/crypto_rand.h
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2019-02-20 12:21:05 -0500
committerNick Mathewson <nickm@torproject.org>2019-02-20 12:21:05 -0500
commit97b9dfe3052f1fe3b14f47fc1326e235f96305b7 (patch)
tree148edc114c2f53e04e134f79394a72c4e6dc589e /src/lib/crypt_ops/crypto_rand.h
parent208f04e9b8241569fe314f6d5cb65521c9b55d8b (diff)
downloadtor-97b9dfe3052f1fe3b14f47fc1326e235f96305b7.tar.gz
tor-97b9dfe3052f1fe3b14f47fc1326e235f96305b7.zip
Add a convenience macro to get a fast one-in-n calculation
Diffstat (limited to 'src/lib/crypt_ops/crypto_rand.h')
-rw-r--r--src/lib/crypt_ops/crypto_rand.h3
1 files changed, 3 insertions, 0 deletions
diff --git a/src/lib/crypt_ops/crypto_rand.h b/src/lib/crypt_ops/crypto_rand.h
index 6eef22ed4d..bb424fd691 100644
--- a/src/lib/crypt_ops/crypto_rand.h
+++ b/src/lib/crypt_ops/crypto_rand.h
@@ -68,6 +68,9 @@ 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);
+#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