Add an extra test for randombytes

This commit is contained in:
Frank Denis 2015-01-18 10:34:31 +01:00
parent e2a24e69ec
commit 388baa5380

View File

@ -27,7 +27,9 @@ static int compat_tests(void)
static int randombytes_tests(void)
{
unsigned int f = 0U;
unsigned int i;
uint32_t n;
#ifdef __EMSCRIPTEN__
assert(strcmp(randombytes_implementation_name(), "sysrandom"));
@ -35,8 +37,14 @@ static int randombytes_tests(void)
assert(strcmp(randombytes_implementation_name(), "js"));
#endif
randombytes(x, 1U);
while (randombytes_random() <= (uint32_t) 0x7fffffff);
while (randombytes_random() >= (uint32_t) 0x128);
do {
n = randombytes_random();
f |= ((n >> 24) > 1);
f |= ((n >> 16) > 1) << 1;
f |= ((n >> 8) > 1) << 2;
f |= ((n ) > 1) << 3;
f |= (n > 0x7fffffff) << 4;
} while (f != 0x1f);
randombytes_close();
for (i = 0; i < 256; ++i) {