diff options
author | Nick Mathewson <nickm@torproject.org> | 2015-04-23 09:16:42 -0400 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2015-04-23 09:16:42 -0400 |
commit | 241e6b093730106978ceef5b500c7049b9846084 (patch) | |
tree | 2f3ada40c5da0dc23530a223f34cc5a624556d5a /src/common | |
parent | 647b7d37c2b3de4a837d0a4bf810c0132624c15d (diff) | |
download | tor-241e6b093730106978ceef5b500c7049b9846084.tar.gz tor-241e6b093730106978ceef5b500c7049b9846084.zip |
Fix some conversion problems
Diffstat (limited to 'src/common')
-rw-r--r-- | src/common/crypto.c | 15 | ||||
-rw-r--r-- | src/common/crypto.h | 2 | ||||
-rw-r--r-- | src/common/tortls.c | 2 |
3 files changed, 18 insertions, 1 deletions
diff --git a/src/common/crypto.c b/src/common/crypto.c index e723f3d5d2..f0d4fbbf21 100644 --- a/src/common/crypto.c +++ b/src/common/crypto.c @@ -2336,6 +2336,21 @@ crypto_rand_int_range(unsigned int min, unsigned int max) return min + crypto_rand_int(max - min); } +/** As crypto_rand_int_range, but supports uint64_t. */ +uint64_t +crypto_rand_uint64_range(uint64_t min, uint64_t max) +{ + tor_assert(min < max); + return min + crypto_rand_uint64(max - min); +} + +/** As crypto_rand_int_range, but supports time_t. */ +time_t +crypto_rand_time_range(time_t min, time_t max) +{ + return (time_t) crypto_rand_uint64_range(min, max); +} + /** Return a pseudorandom 64-bit integer, chosen uniformly from the values * between 0 and <b>max</b>-1. */ uint64_t diff --git a/src/common/crypto.h b/src/common/crypto.h index aa587fd08b..1ac02ea7a5 100644 --- a/src/common/crypto.h +++ b/src/common/crypto.h @@ -255,6 +255,8 @@ MOCK_DECL(int,crypto_rand,(char *to, size_t n)); int crypto_strongest_rand(uint8_t *out, size_t out_len); 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); uint64_t crypto_rand_uint64(uint64_t max); double crypto_rand_double(void); struct tor_weak_rng_t; diff --git a/src/common/tortls.c b/src/common/tortls.c index 7809c1adaa..bd7e95c033 100644 --- a/src/common/tortls.c +++ b/src/common/tortls.c @@ -660,7 +660,7 @@ tor_tls_create_certificate(crypto_pk_t *rsa, * then we might pick a time where we're about to expire. Lastly, be * sure to start on a day boundary. */ time_t now = time(NULL); - start_time = crypto_rand_int_range(now - cert_lifetime, now) + 2*24*3600; + start_time = crypto_rand_time_range(now - cert_lifetime, now) + 2*24*3600; start_time -= start_time % (24*3600); tor_assert(rsa); |