mirror of
https://github.com/cuberite/polarssl.git
synced 2025-09-30 00:46:22 -04:00
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>
This commit is contained in:
parent
6b7ce968d2
commit
acdefdd51a
@ -16,6 +16,15 @@ static int sign_is_valid( const mbedtls_mpi *X )
|
|||||||
return( X->s == 1 );
|
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
|
/* 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
|
* is significantly above a power of 2. That is, b must not have a long run
|
||||||
* of unset bits after the most significant bit.
|
* of unset bits after the most significant bit.
|
||||||
@ -71,10 +80,7 @@ static int is_significantly_above_a_power_of_2( data_t *bytes )
|
|||||||
void mpi_core_random_basic( int min, char *bound_bytes, int expected_ret )
|
void mpi_core_random_basic( int min, char *bound_bytes, int expected_ret )
|
||||||
{
|
{
|
||||||
/* Same RNG as in mpi_random_values */
|
/* Same RNG as in mpi_random_values */
|
||||||
mbedtls_test_rnd_pseudo_info rnd = {
|
mbedtls_test_rnd_pseudo_info rnd = rnd_pseudo_seed;
|
||||||
{'T', 'h', 'i', 's', ' ', 'i', ',', 'a',
|
|
||||||
's', 'e', 'e', 'd', '!', 0},
|
|
||||||
0, 0};
|
|
||||||
size_t limbs;
|
size_t limbs;
|
||||||
mbedtls_mpi_uint *lower_bound = NULL;
|
mbedtls_mpi_uint *lower_bound = NULL;
|
||||||
mbedtls_mpi_uint *upper_bound = NULL;
|
mbedtls_mpi_uint *upper_bound = NULL;
|
||||||
@ -107,10 +113,7 @@ exit:
|
|||||||
void mpi_random_values( int min, char *max_hex )
|
void mpi_random_values( int min, char *max_hex )
|
||||||
{
|
{
|
||||||
/* Same RNG as in mpi_core_random_basic */
|
/* Same RNG as in mpi_core_random_basic */
|
||||||
mbedtls_test_rnd_pseudo_info rnd_core = {
|
mbedtls_test_rnd_pseudo_info rnd_core = rnd_pseudo_seed;
|
||||||
{'T', 'h', 'i', 's', ' ', 'i', ',', 'a',
|
|
||||||
's', 'e', 'e', 'd', '!', 0},
|
|
||||||
0, 0};
|
|
||||||
mbedtls_test_rnd_pseudo_info rnd_legacy;
|
mbedtls_test_rnd_pseudo_info rnd_legacy;
|
||||||
memcpy( &rnd_legacy, &rnd_core, sizeof( rnd_core ) );
|
memcpy( &rnd_legacy, &rnd_core, sizeof( rnd_core ) );
|
||||||
mbedtls_mpi max_legacy;
|
mbedtls_mpi max_legacy;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user