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

bignum_mod: Adjusted input checking for mbedtls_mpi_mod_residue_setup()

This patch adjusts the logic of the size checking of the method,
and refactors the tests. Documentation has also been updated.

Signed-off-by: Minos Galanakis <minos.galanakis@arm.com>
This commit is contained in:
Minos Galanakis
2022-11-24 09:09:47 +00:00
committed by Janos Follath
parent a17ad48e2d
commit aed832ac16
4 changed files with 39 additions and 37 deletions

View File

@ -39,7 +39,7 @@ int mbedtls_mpi_mod_residue_setup( mbedtls_mpi_mod_residue *r,
mbedtls_mpi_uint *p,
size_t p_limbs )
{
if( p_limbs > m->limbs || !mbedtls_mpi_core_lt_ct( p, m->p, m->limbs ) )
if( p_limbs > m->limbs || !mbedtls_mpi_core_lt_ct( p, m->p, p_limbs ) )
return( MBEDTLS_ERR_MPI_BAD_INPUT_DATA );
r->limbs = m->limbs;

View File

@ -75,16 +75,17 @@ typedef struct {
/** Setup a residue structure.
*
* \param[out] r The address of residue to setup. The size is determined by
* \p m.
* (In particular, it must have at least as many limbs as the
* modulus \p m.)
* \param[out] r The address of residue to setup. The resulting structure's
* size is determined by \p m.
* \param[in] m The address of the modulus related to \p r.
* \param[in] p The address of the limb array storing the value of \p r.
* The memory pointed to by \p p will be used by \p r and must
* not be modified in any way until after
* mbedtls_mpi_mod_residue_release() is called.
* \param p_limbs The number of limbs of \p p.
* mbedtls_mpi_mod_residue_release() is called. The data
* pointed by p should be compatible (in terms of size/endianness)
* with the representation used in \p m.
* \param p_limbs The number of limbs of \p p. It must have at most as
* many limbs as the modulus \p m.)
*
* \return \c 0 if successful.
* \return #MBEDTLS_ERR_MPI_BAD_INPUT_DATA if \p p_limbs is less than the