diff options
author | Nick Mathewson <nickm@torproject.org> | 2015-04-23 09:10:35 -0400 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2015-04-23 09:10:35 -0400 |
commit | 647b7d37c2b3de4a837d0a4bf810c0132624c15d (patch) | |
tree | d2619889049cdd30f62ddebffb96cf62835cb6e5 /src/test/test_crypto.c | |
parent | 3acee6142221839137607c9a9cbf8ca4feea5993 (diff) | |
parent | e48ad353a31f3ee376f7914563d960916ad6aecd (diff) | |
download | tor-647b7d37c2b3de4a837d0a4bf810c0132624c15d.tar.gz tor-647b7d37c2b3de4a837d0a4bf810c0132624c15d.zip |
Merge remote-tracking branch 'public/bug15745_027_03'
Diffstat (limited to 'src/test/test_crypto.c')
-rw-r--r-- | src/test/test_crypto.c | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/src/test/test_crypto.c b/src/test/test_crypto.c index 7f4aa13ac2..bcd7069b9d 100644 --- a/src/test/test_crypto.c +++ b/src/test/test_crypto.c @@ -107,6 +107,30 @@ test_crypto_rng(void *arg) ; } +static void +test_crypto_rng_range(void *arg) +{ + int got_smallest = 0, got_largest = 0; + int i; + + (void)arg; + for (i = 0; i < 1000; ++i) { + int x = crypto_rand_int_range(5,9); + tt_int_op(x, OP_GE, 5); + tt_int_op(x, OP_LT, 9); + if (x == 5) + got_smallest = 1; + if (x == 8) + got_largest = 1; + } + + /* These fail with probability 1/10^603. */ + tt_assert(got_smallest); + tt_assert(got_largest); + done: + ; +} + /** Run unit tests for our AES functionality */ static void test_crypto_aes(void *arg) @@ -1637,6 +1661,7 @@ test_crypto_siphash(void *arg) struct testcase_t crypto_tests[] = { CRYPTO_LEGACY(formats), CRYPTO_LEGACY(rng), + { "rng_range", test_crypto_rng_range, 0, NULL, NULL }, { "aes_AES", test_crypto_aes, TT_FORK, &passthrough_setup, (void*)"aes" }, { "aes_EVP", test_crypto_aes, TT_FORK, &passthrough_setup, (void*)"evp" }, CRYPTO_LEGACY(sha), |