From ee97d5e3f8f5a4e4c827247738cd192a6ea4ab90 Mon Sep 17 00:00:00 2001 From: Frank Denis Date: Sat, 9 May 2015 15:54:18 +0200 Subject: [PATCH] Add tests for custom randombytes_uniform. Check for crypto_auth_hmacsha512256_statebytes() presence. --- test/default/auth.c | 2 ++ test/default/randombytes.c | 27 +++++++++++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/test/default/auth.c b/test/default/auth.c index 1773a14d..f9ecbeb7 100644 --- a/test/default/auth.c +++ b/test/default/auth.c @@ -57,6 +57,8 @@ int main(void) assert(crypto_auth_hmacsha512_keybytes() > 0U); assert(crypto_auth_hmacsha512256_bytes() == crypto_auth_bytes()); assert(crypto_auth_hmacsha512256_keybytes() == crypto_auth_keybytes()); + assert(crypto_auth_hmacsha512256_statebytes() >= + crypto_auth_hmacsha512256_keybytes()); assert(crypto_auth_hmacsha256_statebytes() == sizeof(crypto_auth_hmacsha256_state)); assert(crypto_auth_hmacsha512_statebytes() == diff --git a/test/default/randombytes.c b/test/default/randombytes.c index 231a29bd..4d8efff0 100644 --- a/test/default/randombytes.c +++ b/test/default/randombytes.c @@ -98,10 +98,37 @@ static int randombytes_tests(void) return 0; } +static uint32_t randombytes_uniform_impl(const uint32_t upper_bound) +{ + return upper_bound; +} + +static int impl_tests(void) +{ + randombytes_implementation impl = randombytes_sysrandom_implementation; + uint32_t v = randombytes_random(); + + impl.uniform = randombytes_uniform_impl; + randombytes_close(); + randombytes_set_implementation(&impl); + assert(randombytes_uniform(v) == v); + assert(randombytes_uniform(v) == v); + assert(randombytes_uniform(v) == v); + assert(randombytes_uniform(v) == v); + randombytes_close(); + impl.close = NULL; + randombytes_close(); + + return 0; +} + int main(void) { compat_tests(); randombytes_tests(); +#ifndef __EMSCRIPTEN__ + impl_tests(); +#endif printf("OK\n"); return 0;