[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [tor/master] Testing: allow the user to pass a seed in for reproducible-RNG tests
commit 72e9c427b81a1d31f28c8398f516fa7892200ef3
Author: Nick Mathewson <nickm@xxxxxxxxxxxxxx>
Date: Tue May 14 20:05:53 2019 -0400
Testing: allow the user to pass a seed in for reproducible-RNG tests
The environment variable TOR_TEST_RNG_SEED, if provided, is a hex
value for the RNG seed.
---
src/test/rng_test_helpers.c | 19 ++++++++++++++++---
1 file changed, 16 insertions(+), 3 deletions(-)
diff --git a/src/test/rng_test_helpers.c b/src/test/rng_test_helpers.c
index c4243f5e9..1ee267230 100644
--- a/src/test/rng_test_helpers.c
+++ b/src/test/rng_test_helpers.c
@@ -124,9 +124,22 @@ enable_deterministic_rng_impl(const uint8_t *seed, size_t seed_len)
void
testing_enable_reproducible_rng(void)
{
- uint8_t seed[16];
- crypto_rand((char*)seed, sizeof(seed));
- enable_deterministic_rng_impl(seed, sizeof(seed));
+ const char *provided_seed = getenv("TOR_TEST_RNG_SEED");
+ if (provided_seed) {
+ size_t hexlen = strlen(provided_seed);
+ size_t seedlen = hexlen / 2;
+ uint8_t *seed = tor_malloc(hexlen / 2);
+ if (base16_decode((char*)seed, seedlen, provided_seed, hexlen) < 0) {
+ puts("Cannot decode value in TOR_TEST_RNG_SEED");
+ exit(1);
+ }
+ enable_deterministic_rng_impl(seed, seedlen);
+ tor_free(seed);
+ } else {
+ uint8_t seed[16];
+ crypto_rand((char*)seed, sizeof(seed));
+ enable_deterministic_rng_impl(seed, sizeof(seed));
+ }
}
/**
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits