aboutsummaryrefslogtreecommitdiff
path: root/src/lib/crypt_ops
diff options
context:
space:
mode:
authorGeorge Kadianakis <desnacked@riseup.net>2018-11-27 01:56:23 +0200
committerGeorge Kadianakis <desnacked@riseup.net>2019-01-02 15:25:55 +0200
commit2ccf3268375cd46e8c948e94ba58e0d2f03fe722 (patch)
treea6a820abe9af9a65f7648c2fae8a36ff0d81d607 /src/lib/crypt_ops
parent8ad497bb578b13c66489843905764a60545e6388 (diff)
downloadtor-2ccf3268375cd46e8c948e94ba58e0d2f03fe722.tar.gz
tor-2ccf3268375cd46e8c948e94ba58e0d2f03fe722.zip
Implement and test probability distributions used by WTF-PAD.
This project introduces the prob_distr.c subsystem which implements all the probability distributions that WTF-PAD needs. It also adds unittests for all of them. Code and tests courtesy of Riastradh. Co-authored-by: Taylor R Campbell <campbell+tor@mumble.net> Co-authored-by: Mike Perry <mikeperry-git@torproject.org>
Diffstat (limited to 'src/lib/crypt_ops')
-rw-r--r--src/lib/crypt_ops/crypto_rand.c11
-rw-r--r--src/lib/crypt_ops/crypto_rand.h1
2 files changed, 12 insertions, 0 deletions
diff --git a/src/lib/crypt_ops/crypto_rand.c b/src/lib/crypt_ops/crypto_rand.c
index cffd0610f3..7a2c417e5a 100644
--- a/src/lib/crypt_ops/crypto_rand.c
+++ b/src/lib/crypt_ops/crypto_rand.c
@@ -529,6 +529,17 @@ crypto_rand_unmocked(char *to, size_t n)
}
/**
+ * Draw an unsigned 32-bit integer uniformly at random.
+ */
+uint32_t
+crypto_rand_uint32(void)
+{
+ uint32_t rand;
+ crypto_rand((void*)&rand, sizeof(rand));
+ return rand;
+}
+
+/**
* Return a pseudorandom integer, chosen uniformly from the values
* between 0 and <b>max</b>-1 inclusive. <b>max</b> must be between 1 and
* INT_MAX+1, inclusive.
diff --git a/src/lib/crypt_ops/crypto_rand.h b/src/lib/crypt_ops/crypto_rand.h
index 0c538d81ac..61fd82c806 100644
--- a/src/lib/crypt_ops/crypto_rand.h
+++ b/src/lib/crypt_ops/crypto_rand.h
@@ -27,6 +27,7 @@ int crypto_rand_int(unsigned int max);
int crypto_rand_int_range(unsigned int min, unsigned int max);
uint64_t crypto_rand_uint64_range(uint64_t min, uint64_t max);
time_t crypto_rand_time_range(time_t min, time_t max);
+uint32_t crypto_rand_uint32(void);
uint64_t crypto_rand_uint64(uint64_t max);
double crypto_rand_double(void);
struct tor_weak_rng_t;