diff --git a/test/cryptsuite.py b/test/cryptsuite.py index 02f77d56..e6f638d6 100755 --- a/test/cryptsuite.py +++ b/test/cryptsuite.py @@ -103,6 +103,12 @@ def queued_specific_random_data(data): yield None random_clear() +@contextlib.contextmanager +def random_prng(seed): + random_make_prng('sha256', seed) + yield None + random_clear() + def hash_str(alg, message): h = ssh_hash_new(alg) ssh_hash_update(h, message) diff --git a/testcrypt.c b/testcrypt.c index 94d9baaf..e01ed606 100644 --- a/testcrypt.c +++ b/testcrypt.c @@ -55,10 +55,15 @@ static bool old_keyfile_warning_given; void old_keyfile_warning(void) { old_keyfile_warning_given = true; } static bufchain random_data_queue; +static prng *test_prng; void random_read(void *buf, size_t size) { - if (!bufchain_try_fetch_consume(&random_data_queue, buf, size)) - fatal_error("No random data in queue"); + if (test_prng) { + prng_read(test_prng, buf, size); + } else { + if (!bufchain_try_fetch_consume(&random_data_queue, buf, size)) + fatal_error("No random data in queue"); + } } uint64_t prng_reseed_time_ms(void) @@ -673,9 +678,24 @@ static size_t random_queue_len(void) static void random_clear(void) { + if (test_prng) { + prng_free(test_prng); + test_prng = NULL; + } + bufchain_clear(&random_data_queue); } +static void random_make_prng(const ssh_hashalg *hashalg, ptrlen seed) +{ + random_clear(); + + test_prng = prng_new(hashalg); + prng_seed_begin(test_prng); + put_datapl(test_prng, seed); + prng_seed_finish(test_prng); +} + mp_int *monty_identity_wrapper(MontyContext *mc) { return mp_copy(monty_identity(mc)); diff --git a/testcrypt.h b/testcrypt.h index 2fec0ba2..4ed190af 100644 --- a/testcrypt.h +++ b/testcrypt.h @@ -290,4 +290,5 @@ FUNC2(boolean, crcda_detect, val_string_ptrlen, val_string_ptrlen) */ FUNC1(void, random_queue, val_string_ptrlen) FUNC0(uint, random_queue_len) +FUNC2(void, random_make_prng, hashalg, val_string_ptrlen) FUNC0(void, random_clear)