mirror of
https://github.com/jedisct1/libsodium.git
synced 2024-12-31 22:42:57 -07:00
Add tests for custom randombytes_uniform.
Check for crypto_auth_hmacsha512256_statebytes() presence.
This commit is contained in:
parent
fe02b1db1b
commit
ee97d5e3f8
@ -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() ==
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user