mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-11-28 14:23:30 +01:00
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.
This commit is contained in:
parent
2d467544fe
commit
72e9c427b8
@ -124,10 +124,23 @@ enable_deterministic_rng_impl(const uint8_t *seed, size_t seed_len)
|
||||
void
|
||||
testing_enable_reproducible_rng(void)
|
||||
{
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Replace our get_thread_fast_rng(), crypto_rand() and
|
||||
|
Loading…
Reference in New Issue
Block a user