This commit is contained in:
Frank Denis
2017-02-23 11:21:30 +01:00
parent c8f6121429
commit db7c0e1956
+18 -14
View File
@@ -2,10 +2,11 @@
#define TEST_NAME "randombytes"
#include "cmptest.h"
static unsigned char x[65536];
static unsigned char x[65536];
static unsigned long long freq[256];
static int compat_tests(void)
static int
compat_tests(void)
{
size_t i;
@@ -15,7 +16,7 @@ static int compat_tests(void)
freq[i] = 0;
}
for (i = 0; i < sizeof x; ++i) {
++freq[255 & (int)x[i]];
++freq[255 & (int) x[i]];
}
for (i = 0; i < 256; ++i) {
if (!freq[i]) {
@@ -25,13 +26,13 @@ static int compat_tests(void)
return 0;
}
static int randombytes_tests(void)
static int
randombytes_tests(void)
{
const static unsigned char seed[randombytes_SEEDBYTES] = {
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a,
0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15,
0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f
};
unsigned char out[100];
unsigned int f = 0U;
@@ -50,8 +51,8 @@ static int randombytes_tests(void)
n = randombytes_random();
f |= ((n >> 24) > 1);
f |= ((n >> 16) > 1) << 1;
f |= ((n >> 8) > 1) << 2;
f |= ((n ) > 1) << 3;
f |= ((n >> 8) > 1) << 2;
f |= ((n) > 1) << 3;
f |= (n > 0x7fffffff) << 4;
} while (f != 0x1f);
randombytes_close();
@@ -91,7 +92,7 @@ static int randombytes_tests(void)
freq[i] = 0;
}
for (i = 0; i < sizeof x; ++i) {
++freq[255 & (int)x[i]];
++freq[255 & (int) x[i]];
}
for (i = 0; i < 256; ++i) {
if (!freq[i]) {
@@ -117,12 +118,14 @@ static int randombytes_tests(void)
return 0;
}
static uint32_t randombytes_uniform_impl(const uint32_t upper_bound)
static uint32_t
randombytes_uniform_impl(const uint32_t upper_bound)
{
return upper_bound;
}
static int impl_tests(void)
static int
impl_tests(void)
{
#ifndef __native_client__
randombytes_implementation impl = randombytes_sysrandom_implementation;
@@ -145,7 +148,8 @@ static int impl_tests(void)
return 0;
}
int main(void)
int
main(void)
{
compat_tests();
randombytes_tests();