From: Loup Vaillant Date: Tue, 2 Jan 2018 22:43:42 +0000 (+0100) Subject: removed monocypher dependency from utils.h X-Git-Url: https://git.codecow.com/?a=commitdiff_plain;h=c93a880188a514297654f3952f45f7752060d782;p=Monocypher.git removed monocypher dependency from utils.h --- diff --git a/tests/utils.c b/tests/utils.c index a4fc529..bedb2de 100644 --- a/tests/utils.c +++ b/tests/utils.c @@ -1,5 +1,4 @@ #include "utils.h" -#include "monocypher.h" #include "stdio.h" static void store64_le(u8 out[8], u64 in) @@ -26,32 +25,22 @@ u64 load64_le(const u8 s[8]) | ((u64)s[7] << 56); } -// Deterministic "random" number generator, so we can make "random", yet -// reproducible tests. To change the random stream, change the seed. -void p_random(u8 *stream, size_t size) + +// Pseudo-random 64 bit number, based on xorshift* +u64 rand64() { - static crypto_chacha_ctx ctx; - static int is_init = 0; - if (!is_init) { - static const u8 seed[32] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; - crypto_chacha20_init(&ctx, seed, seed); - is_init = 1; - } - crypto_chacha20_stream(&ctx, stream, size); + static u64 x = 12345; // Must be seeded with a nonzero value. + x ^= x >> 12; + x ^= x << 25; + x ^= x >> 27; + return x * 0x2545F4914F6CDD1D; // magic constant } -// Random 64 bit number -u64 rand64() +void p_random(u8 *stream, size_t size) { - u8 tmp; - u64 result = 0; - FOR (i, 0, 8) { - p_random(&tmp, 1); - result <<= 8; - result += tmp; + FOR (i, 0, size) { + stream[i] = (u8)rand64(); } - return result; } void print_vector(u8 *buf, size_t size)