diff --git a/library/bignum_mod_raw.c b/library/bignum_mod_raw.c index 2f49ea2d9e..22e56b7e63 100644 --- a/library/bignum_mod_raw.c +++ b/library/bignum_mod_raw.c @@ -52,11 +52,12 @@ void mbedtls_mpi_mod_raw_cond_swap( mbedtls_mpi_uint *X, int mbedtls_mpi_mod_raw_read( mbedtls_mpi_uint *X, const mbedtls_mpi_mod_modulus *m, const unsigned char *input, - size_t input_length ) + size_t input_length, + mbedtls_mpi_mod_ext_rep ext_rep ) { int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; - switch( m->ext_rep ) + switch( ext_rep ) { case MBEDTLS_MPI_MOD_EXT_REP_LE: ret = mbedtls_mpi_core_read_le( X, m->limbs, @@ -87,9 +88,10 @@ cleanup: int mbedtls_mpi_mod_raw_write( const mbedtls_mpi_uint *A, const mbedtls_mpi_mod_modulus *m, unsigned char *output, - size_t output_length ) + size_t output_length, + mbedtls_mpi_mod_ext_rep ext_rep ) { - switch( m->ext_rep ) + switch( ext_rep ) { case MBEDTLS_MPI_MOD_EXT_REP_LE: return( mbedtls_mpi_core_write_le( A, m->limbs, diff --git a/library/bignum_mod_raw.h b/library/bignum_mod_raw.h index f6c6ebd8f2..d7b6dd115e 100644 --- a/library/bignum_mod_raw.h +++ b/library/bignum_mod_raw.h @@ -106,6 +106,7 @@ void mbedtls_mpi_mod_raw_cond_swap( mbedtls_mpi_uint *X, * \param[in] m The address of the modulus related to \p X. * \param[in] input The input buffer to import from. * \param input_length The length in bytes of \p input. + * \param ext_rep The endianness of the number in the input buffer. * * \return \c 0 if successful. * \return #MBEDTLS_ERR_MPI_BUFFER_TOO_SMALL if \p X isn't @@ -116,7 +117,8 @@ void mbedtls_mpi_mod_raw_cond_swap( mbedtls_mpi_uint *X, int mbedtls_mpi_mod_raw_read( mbedtls_mpi_uint *X, const mbedtls_mpi_mod_modulus *m, const unsigned char *input, - size_t input_length ); + size_t input_length, + mbedtls_mpi_mod_ext_rep ext_rep ); /** Export A into unsigned binary data. * @@ -126,6 +128,7 @@ int mbedtls_mpi_mod_raw_read( mbedtls_mpi_uint *X, * \param[in] m The address of the modulus related to \p A. * \param[out] output The output buffer to export to. * \param output_length The length in bytes of \p output. + * \param ext_rep The endianness in which the number should be written into the output buffer. * * \return \c 0 if successful. * \return #MBEDTLS_ERR_MPI_BUFFER_TOO_SMALL if \p output isn't @@ -136,7 +139,8 @@ int mbedtls_mpi_mod_raw_read( mbedtls_mpi_uint *X, int mbedtls_mpi_mod_raw_write( const mbedtls_mpi_uint *A, const mbedtls_mpi_mod_modulus *m, unsigned char *output, - size_t output_length ); + size_t output_length, + mbedtls_mpi_mod_ext_rep ext_rep ); /* BEGIN MERGE SLOT 1 */ diff --git a/tests/suites/test_suite_bignum_mod_raw.function b/tests/suites/test_suite_bignum_mod_raw.function index 00ed005f50..031897889c 100644 --- a/tests/suites/test_suite_bignum_mod_raw.function +++ b/tests/suites/test_suite_bignum_mod_raw.function @@ -54,17 +54,17 @@ void mpi_mod_raw_io( data_t *input, int nb_int, int nx_32_int, TEST_EQUAL( ret, 0 ); if( iendian == MBEDTLS_MPI_MOD_EXT_REP_INVALID && iret != 0 ) - m.ext_rep = MBEDTLS_MPI_MOD_EXT_REP_INVALID; + endian = MBEDTLS_MPI_MOD_EXT_REP_INVALID; - ret = mbedtls_mpi_mod_raw_read( X, &m, input->x, input->len ); + ret = mbedtls_mpi_mod_raw_read( X, &m, input->x, input->len, endian ); TEST_EQUAL( ret, iret ); if( iret == 0 ) { if( iendian == MBEDTLS_MPI_MOD_EXT_REP_INVALID && oret != 0 ) - m.ext_rep = MBEDTLS_MPI_MOD_EXT_REP_INVALID; + endian = MBEDTLS_MPI_MOD_EXT_REP_INVALID; - ret = mbedtls_mpi_mod_raw_write( X, &m, buf, nb ); + ret = mbedtls_mpi_mod_raw_write( X, &m, buf, nb, endian ); TEST_EQUAL( ret, oret ); }