bignum_mod: Renamed m -> N in mbedtls_mpi_mod_write()

Signed-off-by: Mihir Raj Singh <mihirrajsingh123@gmail.com>
This commit is contained in:
Mihir Raj Singh 2023-01-11 20:46:18 +05:30
parent fdc314b6fe
commit a43290d556
2 changed files with 24 additions and 23 deletions

View File

@ -380,37 +380,38 @@ cleanup:
return ret; return ret;
} }
int mbedtls_mpi_mod_write(const mbedtls_mpi_mod_residue *r, int mbedtls_mpi_mod_write( const mbedtls_mpi_mod_residue *r,
const mbedtls_mpi_mod_modulus *m, const mbedtls_mpi_mod_modulus *N,
unsigned char *buf, unsigned char *buf,
size_t buflen, size_t buflen,
mbedtls_mpi_mod_ext_rep ext_rep) mbedtls_mpi_mod_ext_rep ext_rep )
{ {
int ret = MBEDTLS_ERR_MPI_BAD_INPUT_DATA; int ret = MBEDTLS_ERR_MPI_BAD_INPUT_DATA;
/* Do our best to check if r and m have been set up */ /* Do our best to check if r and m have been set up */
if (r->limbs == 0 || m->limbs == 0) { if (r->limbs == 0 || N->limbs == 0) {
goto cleanup; goto cleanup;
} }
if (r->limbs != m->limbs) { if (r->limbs != N->limbs) {
goto cleanup; goto cleanup;
} }
if (m->int_rep == MBEDTLS_MPI_MOD_REP_MONTGOMERY) { if (N->int_rep == MBEDTLS_MPI_MOD_REP_MONTGOMERY) {
ret = mbedtls_mpi_mod_raw_from_mont_rep(r->p, m); ret = mbedtls_mpi_mod_raw_from_mont_rep(r->p, N);
if (ret != 0) { if (ret != 0) {
goto cleanup; goto cleanup;
} }
} }
ret = mbedtls_mpi_mod_raw_write(r->p, m, buf, buflen, ext_rep); ret = mbedtls_mpi_mod_raw_write( r->p, N, buf, buflen, ext_rep );
if (m->int_rep == MBEDTLS_MPI_MOD_REP_MONTGOMERY) { if( N->int_rep == MBEDTLS_MPI_MOD_REP_MONTGOMERY )
{
/* If this fails, the value of r is corrupted and we want to return /* If this fails, the value of r is corrupted and we want to return
* this error (as opposed to the error code from the write above) to * this error (as opposed to the error code from the write above) to
* let the caller know. If it succeeds, we want to return the error * let the caller know. If it succeeds, we want to return the error
* code from write above. */ * code from write above. */
int conv_ret = mbedtls_mpi_mod_raw_to_mont_rep(r->p, m); int conv_ret = mbedtls_mpi_mod_raw_to_mont_rep(r->p, N);
if (ret == 0) { if (ret == 0) {
ret = conv_ret; ret = conv_ret;
} }

View File

@ -429,22 +429,22 @@ int mbedtls_mpi_mod_read( mbedtls_mpi_mod_residue *r,
/** Write a residue into a byte buffer. /** Write a residue into a byte buffer.
* *
* The modulus \p m must be the modulus associated with \p r (see * The modulus \p N must be the modulus associated with \p r (see
* mbedtls_mpi_mod_residue_setup() and mbedtls_mpi_mod_read()). * mbedtls_mpi_mod_residue_setup() and mbedtls_mpi_mod_read()).
* *
* The residue will be automatically converted from the internal representation * The residue will be automatically converted from the internal representation
* based on the value of `m->int_rep` field. * based on the value of `N->int_rep` field.
* *
* \warning If the buffer is smaller than `m->bits`, the number of * \warning If the buffer is smaller than `N->bits`, the number of
* leading zeroes is leaked through timing. If \p r is * leading zeroes is leaked through timing. If \p r is
* secret, the caller must ensure that \p buflen is at least * secret, the caller must ensure that \p buflen is at least
* (`m->bits`+7)/8. * (`N->bits`+7)/8.
* *
* \param[in] r The address of the residue. It must have the same number of * \param[in] r The address of the residue. It must have the same number of
* limbs as the modulus \p m. (\p r is an input parameter, but * limbs as the modulus \p N. (\p r is an input parameter, but
* its value will be modified during execution and restored * its value will be modified during execution and restored
* before the function returns.) * before the function returns.)
* \param[in] m The address of the modulus associated with \r. * \param[in] N The address of the modulus associated with \r.
* \param[out] buf The output buffer to export to. * \param[out] buf The output buffer to export to.
* \param buflen The length in bytes of \p buf. * \param buflen The length in bytes of \p buf.
* \param ext_rep The endianness in which the number should be written into * \param ext_rep The endianness in which the number should be written into
@ -459,11 +459,11 @@ int mbedtls_mpi_mod_read( mbedtls_mpi_mod_residue *r,
* memory for conversion. Can occur only for moduli with * memory for conversion. Can occur only for moduli with
* MBEDTLS_MPI_MOD_REP_MONTGOMERY. * MBEDTLS_MPI_MOD_REP_MONTGOMERY.
*/ */
int mbedtls_mpi_mod_write(const mbedtls_mpi_mod_residue *r, int mbedtls_mpi_mod_write( const mbedtls_mpi_mod_residue *r,
const mbedtls_mpi_mod_modulus *m, const mbedtls_mpi_mod_modulus *N,
unsigned char *buf, unsigned char *buf,
size_t buflen, size_t buflen,
mbedtls_mpi_mod_ext_rep ext_rep); mbedtls_mpi_mod_ext_rep ext_rep );
/* END MERGE SLOT 7 */ /* END MERGE SLOT 7 */
/* BEGIN MERGE SLOT 8 */ /* BEGIN MERGE SLOT 8 */