diff --git a/library/dhm.c b/library/dhm.c index 2ec8bb74f..ee28572f1 100644 --- a/library/dhm.c +++ b/library/dhm.c @@ -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 ) ); diff --git a/tests/suites/test_suite_dhm.function b/tests/suites/test_suite_dhm.function index dad6be1e2..8a05a38df 100644 --- a/tests/suites/test_suite_dhm.function +++ b/tests/suites/test_suite_dhm.function @@ -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,