mbedtls_dhm_get_value parameter order: context first, output last
mbedtls_dhm_get_value can be seen as either a copy function or a getter
function. Given the name and the semantics, it's more of a getter, even if
it "gets" by doing a copy. Therefore, put the context first, and the
selector next, leaving the output for last.
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
diff --git a/include/mbedtls/dhm.h b/include/mbedtls/dhm.h
index 6c319f8..e8c8a82 100644
--- a/include/mbedtls/dhm.h
+++ b/include/mbedtls/dhm.h
@@ -315,18 +315,18 @@
/**
* \brief This function copies a parameter of a DHM key.
*
- * \param dest The MPI object to copy the value into. It must be
- * initialized.
* \param ctx The DHM context to query.
* \param param The parameter to copy.
+ * \param dest The MPI object to copy the value into. It must be
+ * initialized.
*
* \return \c 0 on success.
* \return #MBEDTLS_ERR_DHM_BAD_INPUT_DATA if \p field is invalid.
* \return An \c MBEDTLS_ERR_MPI_XXX error code if the copy fails.
*/
-int mbedtls_dhm_get_value( mbedtls_mpi *dest,
- const mbedtls_dhm_context *ctx,
- mbedtls_dhm_parameter param );
+int mbedtls_dhm_get_value( const mbedtls_dhm_context *ctx,
+ mbedtls_dhm_parameter param,
+ mbedtls_mpi *dest );
/**
* \brief This function frees and clears the components
diff --git a/library/dhm.c b/library/dhm.c
index cb9299f..e88f3a2 100644
--- a/library/dhm.c
+++ b/library/dhm.c
@@ -134,9 +134,9 @@
return( mbedtls_mpi_size( &ctx->P ) );
}
-int mbedtls_dhm_get_value( mbedtls_mpi *dest,
- const mbedtls_dhm_context *ctx,
- mbedtls_dhm_parameter param )
+int mbedtls_dhm_get_value( const mbedtls_dhm_context *ctx,
+ mbedtls_dhm_parameter param,
+ mbedtls_mpi *dest )
{
const mbedtls_mpi *src = NULL;
switch( param )
diff --git a/library/ssl_tls.c b/library/ssl_tls.c
index bef6864..560597d 100644
--- a/library/ssl_tls.c
+++ b/library/ssl_tls.c
@@ -3871,10 +3871,10 @@
{
int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
- if( ( ret = mbedtls_dhm_get_value( &conf->dhm_P, dhm_ctx,
- MBEDTLS_DHM_PARAM_P ) ) != 0 ||
- ( ret = mbedtls_dhm_get_value( &conf->dhm_G, dhm_ctx,
- MBEDTLS_DHM_PARAM_G ) ) != 0 )
+ if( ( ret = mbedtls_dhm_get_value( dhm_ctx, MBEDTLS_DHM_PARAM_P,
+ &conf->dhm_P ) ) != 0 ||
+ ( ret = mbedtls_dhm_get_value( dhm_ctx, MBEDTLS_DHM_PARAM_G,
+ &conf->dhm_G ) ) != 0 )
{
mbedtls_mpi_free( &conf->dhm_P );
mbedtls_mpi_free( &conf->dhm_G );
diff --git a/tests/suites/test_suite_dhm.function b/tests/suites/test_suite_dhm.function
index d48c4e3..62e634a 100644
--- a/tests/suites/test_suite_dhm.function
+++ b/tests/suites/test_suite_dhm.function
@@ -9,7 +9,7 @@
int ok = 0;
mbedtls_mpi_init( &actual );
- TEST_ASSERT( mbedtls_dhm_get_value( &actual, ctx, param ) == 0 );
+ TEST_ASSERT( mbedtls_dhm_get_value( ctx, param, &actual ) == 0 );
TEST_ASSERT( mbedtls_mpi_cmp_mpi( &actual, expected ) == 0 );
ok = 1;