1
0
mirror of https://github.com/Mbed-TLS/mbedtls.git synced 2025-07-29 11:41:15 +03:00

bignum_mod: Refactored mbedtls_mpi_mod_read/write()

This patch adjusts the I/O methods and the tests.
Documentation has also been updated to be more clear.

Signed-off-by: Minos Galanakis <minos.galanakis@arm.com>
This commit is contained in:
Minos Galanakis
2022-11-24 11:04:11 +00:00
committed by Janos Follath
parent aed832ac16
commit 8b375451c5
3 changed files with 29 additions and 35 deletions

View File

@ -210,8 +210,8 @@ exit:
/* BEGIN MERGE SLOT 7 */
int mbedtls_mpi_mod_read( mbedtls_mpi_mod_residue *r,
mbedtls_mpi_mod_modulus *m,
unsigned char *buf,
const mbedtls_mpi_mod_modulus *m,
const unsigned char *buf,
size_t buflen )
{
int ret = MBEDTLS_ERR_MPI_BAD_INPUT_DATA;
@ -219,7 +219,7 @@ int mbedtls_mpi_mod_read( mbedtls_mpi_mod_residue *r,
if ( r == NULL || m == NULL )
goto cleanup;
if ( r->p == NULL || m->p == NULL || r->limbs > m->limbs ||\
if ( r->p == NULL || m->p == NULL || r->limbs > m->limbs ||
r->limbs == 0 || m->limbs == 0 )
goto cleanup;
@ -228,6 +228,8 @@ int mbedtls_mpi_mod_read( mbedtls_mpi_mod_residue *r,
if( ret != 0 )
goto cleanup;
r->limbs = m->limbs;
if (m->int_rep == MBEDTLS_MPI_MOD_REP_MONTGOMERY)
ret = mbedtls_mpi_mod_raw_to_mont_rep(r->p, m);
@ -235,8 +237,8 @@ cleanup:
return ( ret );
}
int mbedtls_mpi_mod_write( mbedtls_mpi_mod_residue *r,
mbedtls_mpi_mod_modulus *m,
int mbedtls_mpi_mod_write( const mbedtls_mpi_mod_residue *r,
const mbedtls_mpi_mod_modulus *m,
unsigned char *buf,
size_t buflen )
{
@ -245,7 +247,7 @@ int mbedtls_mpi_mod_write( mbedtls_mpi_mod_residue *r,
if ( r == NULL || m == NULL )
goto cleanup;
if ( r->p == NULL || m->p == NULL || r->limbs > m->limbs ||\
if ( r->p == NULL || m->p == NULL || r->limbs > m->limbs ||
r->limbs == 0 || m->limbs == 0 )
goto cleanup;

View File

@ -177,8 +177,9 @@ void mbedtls_mpi_mod_modulus_free( mbedtls_mpi_mod_modulus *m );
/** Read public representation data stored in a buffer into a residue structure.
*
* The `mbedtls_mpi_mod_residue` and `mbedtls_mpi_mod_modulus` structures must
* be compatible. The data will be automatically converted into the appropriate
* representation based on the value of `m->int_rep field`.
* be compatible (Data in public representation is assumed to be in the m->ext_rep
* and will be padded to m->limbs). The data will be automatically converted
* into the appropriate internal representation based on the value of `m->int_rep`.
*
* \param r The address of the residue related to \p m. It must have as
* many limbs as the modulus \p m.
@ -193,15 +194,17 @@ void mbedtls_mpi_mod_modulus_free( mbedtls_mpi_mod_modulus *m );
* of \p m is invalid or \p X is not less than \p m.
*/
int mbedtls_mpi_mod_read( mbedtls_mpi_mod_residue *r,
mbedtls_mpi_mod_modulus *m,
unsigned char *buf,
const mbedtls_mpi_mod_modulus *m,
const unsigned char *buf,
size_t buflen );
/** Write residue data onto a buffer using public representation data.
*
* The `mbedtls_mpi_mod_residue` and `mbedtls_mpi_mod_modulus` structures must
* be compatible. The data will be automatically converted into the appropriate
* representation based on the value of `m->int_rep field`.
* be compatible (Data will be exported onto the bufer using the m->ext_rep
* and will be read as of m->limbs length).The data will be automatically
* converted from the appropriate internal representation based on the
* value of `m->int_rep field`.
*
* \param r The address of the residue related to \p m. It must have as
* many limbs as the modulus \p m.
@ -215,8 +218,8 @@ int mbedtls_mpi_mod_read( mbedtls_mpi_mod_residue *r,
* \return #MBEDTLS_ERR_MPI_BAD_INPUT_DATA if the external representation
* of \p m is invalid.
*/
int mbedtls_mpi_mod_write( mbedtls_mpi_mod_residue *r,
mbedtls_mpi_mod_modulus *m,
int mbedtls_mpi_mod_write( const mbedtls_mpi_mod_residue *r,
const mbedtls_mpi_mod_modulus *m,
unsigned char *buf,
size_t buflen );
/* END MERGE SLOT 7 */