Minor improvements to DHM module

This commit is contained in:
Hanno Becker 2018-12-17 09:34:36 +00:00
parent 8c8a93c574
commit adc9b178ca
2 changed files with 18 additions and 18 deletions

View File

@ -108,7 +108,6 @@ static int dhm_check_range( const mbedtls_mpi *param, const mbedtls_mpi *P )
mbedtls_mpi L, U;
int ret = 0;
mbedtls_mpi_init( &L ); mbedtls_mpi_init( &U );
MBEDTLS_MPI_CHK( mbedtls_mpi_lset( &L, 2 ) );

View File

@ -14,6 +14,7 @@ void dhm_invalid_params( )
unsigned char buf[42] = { 0 };
unsigned char *buf_null = NULL;
mbedtls_mpi X;
size_t const buflen = sizeof( buf );
size_t len;
TEST_INVALID_PARAM( mbedtls_dhm_init( NULL ) );
@ -33,22 +34,22 @@ void dhm_invalid_params( )
NULL ) );
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_DHM_BAD_INPUT_DATA,
mbedtls_dhm_make_params( NULL, 42,
mbedtls_dhm_make_params( NULL, buflen,
buf, &len,
rnd_std_rand,
NULL ) );
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_DHM_BAD_INPUT_DATA,
mbedtls_dhm_make_params( &ctx, 42,
mbedtls_dhm_make_params( &ctx, buflen,
NULL, &len,
rnd_std_rand,
NULL ) );
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_DHM_BAD_INPUT_DATA,
mbedtls_dhm_make_params( &ctx, 42,
mbedtls_dhm_make_params( &ctx, buflen,
buf, NULL,
rnd_std_rand,
NULL ) );
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_DHM_BAD_INPUT_DATA,
mbedtls_dhm_make_params( &ctx, 42,
mbedtls_dhm_make_params( &ctx, buflen,
buf, &len,
NULL,
NULL ) );
@ -61,44 +62,44 @@ void dhm_invalid_params( )
mbedtls_dhm_set_group( &ctx, &X, NULL ) );
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_DHM_BAD_INPUT_DATA,
mbedtls_dhm_read_public( NULL, buf, 42 ) );
mbedtls_dhm_read_public( NULL, buf, buflen ) );
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_DHM_BAD_INPUT_DATA,
mbedtls_dhm_read_public( &ctx, NULL, 42 ) );
mbedtls_dhm_read_public( &ctx, NULL, buflen ) );
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_DHM_BAD_INPUT_DATA,
mbedtls_dhm_make_public( NULL, 42,
buf, 42,
mbedtls_dhm_make_public( NULL, buflen,
buf, buflen,
rnd_std_rand,
NULL ) );
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_DHM_BAD_INPUT_DATA,
mbedtls_dhm_make_public( &ctx, 42,
NULL, 42,
mbedtls_dhm_make_public( &ctx, buflen,
NULL, buflen,
rnd_std_rand,
NULL ) );
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_DHM_BAD_INPUT_DATA,
mbedtls_dhm_make_public( &ctx, 42,
buf, 42,
mbedtls_dhm_make_public( &ctx, buflen,
buf, buflen,
NULL,
NULL ) );
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_DHM_BAD_INPUT_DATA,
mbedtls_dhm_calc_secret( NULL, buf, 42,
mbedtls_dhm_calc_secret( NULL, buf, buflen,
&len, rnd_std_rand,
NULL ) );
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_DHM_BAD_INPUT_DATA,
mbedtls_dhm_calc_secret( &ctx, NULL, 42,
mbedtls_dhm_calc_secret( &ctx, NULL, buflen,
&len, rnd_std_rand,
NULL ) );
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_DHM_BAD_INPUT_DATA,
mbedtls_dhm_calc_secret( &ctx, buf, 42,
mbedtls_dhm_calc_secret( &ctx, buf, buflen,
NULL, rnd_std_rand,
NULL ) );
#if defined(MBEDTLS_ASN1_PARSE_C)
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_DHM_BAD_INPUT_DATA,
mbedtls_dhm_parse_dhm( NULL, buf, 42 ) );
mbedtls_dhm_parse_dhm( NULL, buf, buflen ) );
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_DHM_BAD_INPUT_DATA,
mbedtls_dhm_parse_dhm( &ctx, NULL, 42 ) );
mbedtls_dhm_parse_dhm( &ctx, NULL, buflen ) );
#if defined(MBEDTLS_FS_IO)
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_DHM_BAD_INPUT_DATA,