From: Loup Vaillant Date: Sat, 26 Jan 2019 14:44:01 +0000 (+0100) Subject: Allow the test suite to customise its random seed X-Git-Url: https://git.codecow.com/?a=commitdiff_plain;h=6e972aa1445f6009b2a3b47492a5f2bc2d50e666;p=Monocypher.git Allow the test suite to customise its random seed This will only affect the property based tests, not the test vectors themselves. The idea is to let paranoid users run the test suite with lots and lots of different streams of random numbers, just to be safe. Test vector generation could undergo a similar transformation, though it is less likely to be worth the trouble (we'd have to generate the test vectors, compile the test suite all over again). --- diff --git a/tests/test.c b/tests/test.c index 00c8db4..ac3014b 100644 --- a/tests/test.c +++ b/tests/test.c @@ -855,8 +855,13 @@ static int p_auth() return status; } -int main(void) +int main(int argc, char *argv[]) { + if (argc > 1) { + sscanf(argv[1], "%" PRIu64 "", &random_state); + } + printf("\nRandom seed: %" PRIu64 "\n", random_state); + int status = 0; printf("\nTest against vectors"); printf("\n--------------------\n"); diff --git a/tests/utils.h b/tests/utils.h index ee04f48..e4b6256 100644 --- a/tests/utils.h +++ b/tests/utils.h @@ -44,14 +44,17 @@ u64 load64_le(const u8 s[8]) | ((u64)s[7] << 56); } +// Must be seeded with a nonzero value. +// Accessible from the outside so we can modify it +static u64 random_state = 12345; + // Pseudo-random 64 bit number, based on xorshift* u64 rand64() { - 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_state ^= random_state >> 12; + random_state ^= random_state << 25; + random_state ^= random_state >> 27; + return random_state * 0x2545F4914F6CDD1D; // magic constant } void p_random(u8 *stream, size_t size)