Unify RNG initialization that must be unified
mpi_core_random_basic and mpi_random_values must generate the same random
sequences in order to get the expected test coverage (where we know we'll
hit certain numbers of retries). Facilitate this by defining the RNG seed
only once.
Fix the seed to explicitly list all 16 words of the key. This isn't strictly
required (missing initializer fields get the value zero), but it's clearer.
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
diff --git a/tests/suites/test_suite_bignum_random.function b/tests/suites/test_suite_bignum_random.function
index c8bca6e..184de5a 100644
--- a/tests/suites/test_suite_bignum_random.function
+++ b/tests/suites/test_suite_bignum_random.function
@@ -16,6 +16,15 @@
return( X->s == 1 );
}
+/* A common initializer for test functions that should generate the same
+ * sequences for reproducibility and good coverage. */
+const mbedtls_test_rnd_pseudo_info rnd_pseudo_seed = {
+ /* 16-word key */
+ {'T', 'h', 'i', 's', ' ', 'i', 's', ' ',
+ 'a', ' ', 's', 'e', 'e', 'd', '!', 0},
+ /* 2-word initial state, should be zero */
+ 0, 0};
+
/* Test whether bytes represents (in big-endian base 256) a number b that
* is significantly above a power of 2. That is, b must not have a long run
* of unset bits after the most significant bit.
@@ -71,10 +80,7 @@
void mpi_core_random_basic( int min, char *bound_bytes, int expected_ret )
{
/* Same RNG as in mpi_random_values */
- mbedtls_test_rnd_pseudo_info rnd = {
- {'T', 'h', 'i', 's', ' ', 'i', ',', 'a',
- 's', 'e', 'e', 'd', '!', 0},
- 0, 0};
+ mbedtls_test_rnd_pseudo_info rnd = rnd_pseudo_seed;
size_t limbs;
mbedtls_mpi_uint *lower_bound = NULL;
mbedtls_mpi_uint *upper_bound = NULL;
@@ -107,10 +113,7 @@
void mpi_random_values( int min, char *max_hex )
{
/* Same RNG as in mpi_core_random_basic */
- mbedtls_test_rnd_pseudo_info rnd_core = {
- {'T', 'h', 'i', 's', ' ', 'i', ',', 'a',
- 's', 'e', 'e', 'd', '!', 0},
- 0, 0};
+ mbedtls_test_rnd_pseudo_info rnd_core = rnd_pseudo_seed;
mbedtls_test_rnd_pseudo_info rnd_legacy;
memcpy( &rnd_legacy, &rnd_core, sizeof( rnd_core ) );
mbedtls_mpi max_legacy;