Make RNG parameters mandatory in ECDH functions
Again, no check in the code - will be checked by ECP Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
This commit is contained in:
parent
1a87722bb6
commit
7861ecf838
2 changed files with 20 additions and 12 deletions
|
@ -222,10 +222,7 @@ int mbedtls_ecdh_gen_public( mbedtls_ecp_group *grp, mbedtls_mpi *d, mbedtls_ecp
|
|||
* This must be initialized.
|
||||
* \param d Our secret exponent (private key).
|
||||
* This must be initialized.
|
||||
* \param f_rng The RNG function. This may be \c NULL if randomization
|
||||
* of intermediate results during the ECP computations is
|
||||
* not needed (discouraged). See the documentation of
|
||||
* mbedtls_ecp_mul() for more.
|
||||
* \param f_rng The RNG function to use. This must not be \c NULL.
|
||||
* \param p_rng The RNG context to be passed to \p f_rng. This may be
|
||||
* \c NULL if \p f_rng is \c NULL or doesn't need a
|
||||
* context argument.
|
||||
|
@ -428,8 +425,7 @@ int mbedtls_ecdh_read_public( mbedtls_ecdh_context *ctx,
|
|||
* \param buf The buffer to write the generated shared key to. This
|
||||
* must be a writable buffer of size \p blen Bytes.
|
||||
* \param blen The length of the destination buffer \p buf in Bytes.
|
||||
* \param f_rng The RNG function, for blinding purposes. This may
|
||||
* b \c NULL if blinding isn't needed.
|
||||
* \param f_rng The RNG function to use. This must not be \c NULL.
|
||||
* \param p_rng The RNG context. This may be \c NULL if \p f_rng
|
||||
* doesn't need a context argument.
|
||||
*
|
||||
|
|
|
@ -85,7 +85,8 @@ void ecdh_primitive_random( int id )
|
|||
&mbedtls_test_rnd_pseudo_rand,
|
||||
&rnd_info ) == 0 );
|
||||
TEST_ASSERT( mbedtls_ecdh_compute_shared( &grp, &zB, &qA, &dB,
|
||||
NULL, NULL ) == 0 );
|
||||
&mbedtls_test_rnd_pseudo_rand,
|
||||
&rnd_info ) == 0 );
|
||||
|
||||
TEST_ASSERT( mbedtls_mpi_cmp_mpi( &zA, &zB ) == 0 );
|
||||
|
||||
|
@ -106,11 +107,13 @@ void ecdh_primitive_testvec( int id, data_t * rnd_buf_A, char * xA_str,
|
|||
mbedtls_ecp_point qA, qB;
|
||||
mbedtls_mpi dA, dB, zA, zB, check;
|
||||
mbedtls_test_rnd_buf_info rnd_info_A, rnd_info_B;
|
||||
mbedtls_test_rnd_pseudo_info rnd_info;
|
||||
|
||||
mbedtls_ecp_group_init( &grp );
|
||||
mbedtls_ecp_point_init( &qA ); mbedtls_ecp_point_init( &qB );
|
||||
mbedtls_mpi_init( &dA ); mbedtls_mpi_init( &dB );
|
||||
mbedtls_mpi_init( &zA ); mbedtls_mpi_init( &zB ); mbedtls_mpi_init( &check );
|
||||
memset( &rnd_info, 0x00, sizeof( mbedtls_test_rnd_pseudo_info ) );
|
||||
|
||||
TEST_ASSERT( mbedtls_ecp_group_load( &grp, id ) == 0 );
|
||||
|
||||
|
@ -169,9 +172,13 @@ void ecdh_primitive_testvec( int id, data_t * rnd_buf_A, char * xA_str,
|
|||
TEST_ASSERT( mbedtls_mpi_cmp_mpi( &qB.Y, &check ) == 0 );
|
||||
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &check, 16, z_str ) == 0 );
|
||||
TEST_ASSERT( mbedtls_ecdh_compute_shared( &grp, &zA, &qB, &dA, NULL, NULL ) == 0 );
|
||||
TEST_ASSERT( mbedtls_ecdh_compute_shared( &grp, &zA, &qB, &dA,
|
||||
&mbedtls_test_rnd_pseudo_rand,
|
||||
&rnd_info ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_cmp_mpi( &zA, &check ) == 0 );
|
||||
TEST_ASSERT( mbedtls_ecdh_compute_shared( &grp, &zB, &qA, &dB, NULL, NULL ) == 0 );
|
||||
TEST_ASSERT( mbedtls_ecdh_compute_shared( &grp, &zB, &qA, &dB,
|
||||
&mbedtls_test_rnd_pseudo_rand,
|
||||
&rnd_info ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_cmp_mpi( &zB, &check ) == 0 );
|
||||
|
||||
exit:
|
||||
|
@ -215,7 +222,8 @@ void ecdh_exchange( int id )
|
|||
&mbedtls_test_rnd_pseudo_rand,
|
||||
&rnd_info ) == 0 );
|
||||
TEST_ASSERT( mbedtls_ecdh_calc_secret( &cli, &res_len, res_buf, 1000,
|
||||
NULL, NULL ) == 0 );
|
||||
&mbedtls_test_rnd_pseudo_rand,
|
||||
&rnd_info ) == 0 );
|
||||
TEST_ASSERT( len == res_len );
|
||||
TEST_ASSERT( memcmp( buf, res_buf, len ) == 0 );
|
||||
|
||||
|
@ -235,12 +243,14 @@ void ecdh_restart( int id, data_t *dA, data_t *dB, data_t *z,
|
|||
const unsigned char *vbuf;
|
||||
size_t len;
|
||||
mbedtls_test_rnd_buf_info rnd_info_A, rnd_info_B;
|
||||
mbedtls_test_rnd_pseudo_info rnd_info;
|
||||
int cnt_restart;
|
||||
mbedtls_ecp_group grp;
|
||||
|
||||
mbedtls_ecp_group_init( &grp );
|
||||
mbedtls_ecdh_init( &srv );
|
||||
mbedtls_ecdh_init( &cli );
|
||||
memset( &rnd_info, 0x00, sizeof( mbedtls_test_rnd_pseudo_info ) );
|
||||
|
||||
rnd_info_A.fallback_f_rng = mbedtls_test_rnd_std_rand;
|
||||
rnd_info_A.fallback_p_rng = NULL;
|
||||
|
@ -315,7 +325,8 @@ void ecdh_restart( int id, data_t *dA, data_t *dB, data_t *z,
|
|||
cnt_restart = 0;
|
||||
do {
|
||||
ret = mbedtls_ecdh_calc_secret( &srv, &len, buf, sizeof( buf ),
|
||||
NULL, NULL );
|
||||
&mbedtls_test_rnd_pseudo_rand,
|
||||
&rnd_info );
|
||||
} while( ret == MBEDTLS_ERR_ECP_IN_PROGRESS && ++cnt_restart );
|
||||
|
||||
TEST_ASSERT( ret == 0 );
|
||||
|
@ -332,7 +343,8 @@ void ecdh_restart( int id, data_t *dA, data_t *dB, data_t *z,
|
|||
cnt_restart = 0;
|
||||
do {
|
||||
ret = mbedtls_ecdh_calc_secret( &cli, &len, buf, sizeof( buf ),
|
||||
NULL, NULL );
|
||||
&mbedtls_test_rnd_pseudo_rand,
|
||||
&rnd_info );
|
||||
} while( ret == MBEDTLS_ERR_ECP_IN_PROGRESS && ++cnt_restart );
|
||||
|
||||
TEST_ASSERT( ret == 0 );
|
||||
|
|
Loading…
Reference in a new issue