diff options
author | Nick Mathewson <nickm@torproject.org> | 2019-05-14 20:05:53 -0400 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2019-05-15 07:50:56 -0400 |
commit | 72e9c427b81a1d31f28c8398f516fa7892200ef3 (patch) | |
tree | 8aa38d7c3d64bdc7674944a7d2c28192bf00b6e7 /src/test/rng_test_helpers.c | |
parent | 2d467544feadeefa9a484142c433170c66d32786 (diff) | |
download | tor-72e9c427b81a1d31f28c8398f516fa7892200ef3.tar.gz tor-72e9c427b81a1d31f28c8398f516fa7892200ef3.zip |
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.
Diffstat (limited to 'src/test/rng_test_helpers.c')
-rw-r--r-- | src/test/rng_test_helpers.c | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/src/test/rng_test_helpers.c b/src/test/rng_test_helpers.c index c4243f5e9a..1ee2672302 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)); + } } /** |