]> git.codecow.com Git - Monocypher.git/commitdiff
Allow the test suite to customise its random seed
authorLoup Vaillant <loup@loup-vaillant.fr>
Sat, 26 Jan 2019 14:44:01 +0000 (15:44 +0100)
committerLoup Vaillant <loup@loup-vaillant.fr>
Sat, 26 Jan 2019 14:44:01 +0000 (15:44 +0100)
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).

tests/test.c
tests/utils.h

index 00c8db440a8572bf6475d9e4cb4adcb1e1e70087..ac3014b006d48da6dc562a6c92feed9ea59e69da 100644 (file)
@@ -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");
index ee04f48a2379cb290bc0ad7c4847666bea6ea8ba..e4b6256fdd0f1758dff54b352762cacf6556507b 100644 (file)
@@ -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)