1
0
mirror of https://github.com/Mbed-TLS/mbedtls.git synced 2025-07-28 00:21:48 +03:00

Merge pull request #6903 from Mihir-Raj-Singh/Bignum_rename_mtoN

Rename modulus input argument from m to N
This commit is contained in:
Gilles Peskine
2023-01-24 21:48:54 +01:00
committed by GitHub
4 changed files with 122 additions and 122 deletions

View File

@ -35,15 +35,15 @@
#include "constant_time_internal.h" #include "constant_time_internal.h"
int mbedtls_mpi_mod_residue_setup(mbedtls_mpi_mod_residue *r, int mbedtls_mpi_mod_residue_setup(mbedtls_mpi_mod_residue *r,
const mbedtls_mpi_mod_modulus *m, const mbedtls_mpi_mod_modulus *N,
mbedtls_mpi_uint *p, mbedtls_mpi_uint *p,
size_t p_limbs) size_t p_limbs)
{ {
if (p_limbs != m->limbs || !mbedtls_mpi_core_lt_ct(p, m->p, m->limbs)) { if (p_limbs != N->limbs || !mbedtls_mpi_core_lt_ct(p, N->p, N->limbs)) {
return MBEDTLS_ERR_MPI_BAD_INPUT_DATA; return MBEDTLS_ERR_MPI_BAD_INPUT_DATA;
} }
r->limbs = m->limbs; r->limbs = N->limbs;
r->p = p; r->p = p;
return 0; return 0;
@ -59,45 +59,45 @@ void mbedtls_mpi_mod_residue_release(mbedtls_mpi_mod_residue *r)
r->p = NULL; r->p = NULL;
} }
void mbedtls_mpi_mod_modulus_init(mbedtls_mpi_mod_modulus *m) void mbedtls_mpi_mod_modulus_init(mbedtls_mpi_mod_modulus *N)
{ {
if (m == NULL) { if (N == NULL) {
return; return;
} }
m->p = NULL; N->p = NULL;
m->limbs = 0; N->limbs = 0;
m->bits = 0; N->bits = 0;
m->int_rep = MBEDTLS_MPI_MOD_REP_INVALID; N->int_rep = MBEDTLS_MPI_MOD_REP_INVALID;
} }
void mbedtls_mpi_mod_modulus_free(mbedtls_mpi_mod_modulus *m) void mbedtls_mpi_mod_modulus_free(mbedtls_mpi_mod_modulus *N)
{ {
if (m == NULL) { if (N == NULL) {
return; return;
} }
switch (m->int_rep) { switch (N->int_rep) {
case MBEDTLS_MPI_MOD_REP_MONTGOMERY: case MBEDTLS_MPI_MOD_REP_MONTGOMERY:
if (m->rep.mont.rr != NULL) { if (N->rep.mont.rr != NULL) {
mbedtls_platform_zeroize((mbedtls_mpi_uint *) m->rep.mont.rr, mbedtls_platform_zeroize((mbedtls_mpi_uint *) N->rep.mont.rr,
m->limbs * sizeof(mbedtls_mpi_uint)); N->limbs * sizeof(mbedtls_mpi_uint));
mbedtls_free((mbedtls_mpi_uint *) m->rep.mont.rr); mbedtls_free((mbedtls_mpi_uint *) N->rep.mont.rr);
m->rep.mont.rr = NULL; N->rep.mont.rr = NULL;
} }
m->rep.mont.mm = 0; N->rep.mont.mm = 0;
break; break;
case MBEDTLS_MPI_MOD_REP_OPT_RED: case MBEDTLS_MPI_MOD_REP_OPT_RED:
mbedtls_free(m->rep.ored); mbedtls_free(N->rep.ored);
break; break;
case MBEDTLS_MPI_MOD_REP_INVALID: case MBEDTLS_MPI_MOD_REP_INVALID:
break; break;
} }
m->p = NULL; N->p = NULL;
m->limbs = 0; N->limbs = 0;
m->bits = 0; N->bits = 0;
m->int_rep = MBEDTLS_MPI_MOD_REP_INVALID; N->int_rep = MBEDTLS_MPI_MOD_REP_INVALID;
} }
static int set_mont_const_square(const mbedtls_mpi_uint **X, static int set_mont_const_square(const mbedtls_mpi_uint **X,
@ -136,26 +136,26 @@ cleanup:
return ret; return ret;
} }
int mbedtls_mpi_mod_modulus_setup(mbedtls_mpi_mod_modulus *m, int mbedtls_mpi_mod_modulus_setup(mbedtls_mpi_mod_modulus *N,
const mbedtls_mpi_uint *p, const mbedtls_mpi_uint *p,
size_t p_limbs, size_t p_limbs,
mbedtls_mpi_mod_rep_selector int_rep) mbedtls_mpi_mod_rep_selector int_rep)
{ {
int ret = 0; int ret = 0;
m->p = p; N->p = p;
m->limbs = p_limbs; N->limbs = p_limbs;
m->bits = mbedtls_mpi_core_bitlen(p, p_limbs); N->bits = mbedtls_mpi_core_bitlen(p, p_limbs);
switch (int_rep) { switch (int_rep) {
case MBEDTLS_MPI_MOD_REP_MONTGOMERY: case MBEDTLS_MPI_MOD_REP_MONTGOMERY:
m->int_rep = int_rep; N->int_rep = int_rep;
m->rep.mont.mm = mbedtls_mpi_core_montmul_init(m->p); N->rep.mont.mm = mbedtls_mpi_core_montmul_init(N->p);
ret = set_mont_const_square(&m->rep.mont.rr, m->p, m->limbs); ret = set_mont_const_square(&N->rep.mont.rr, N->p, N->limbs);
break; break;
case MBEDTLS_MPI_MOD_REP_OPT_RED: case MBEDTLS_MPI_MOD_REP_OPT_RED:
m->int_rep = int_rep; N->int_rep = int_rep;
m->rep.ored = NULL; N->rep.ored = NULL;
break; break;
default: default:
ret = MBEDTLS_ERR_MPI_BAD_INPUT_DATA; ret = MBEDTLS_ERR_MPI_BAD_INPUT_DATA;
@ -165,7 +165,7 @@ int mbedtls_mpi_mod_modulus_setup(mbedtls_mpi_mod_modulus *m,
exit: exit:
if (ret != 0) { if (ret != 0) {
mbedtls_mpi_mod_modulus_free(m); mbedtls_mpi_mod_modulus_free(N);
} }
return ret; return ret;
@ -349,7 +349,7 @@ int mbedtls_mpi_mod_random(mbedtls_mpi_mod_residue *X,
/* BEGIN MERGE SLOT 7 */ /* BEGIN MERGE SLOT 7 */
int mbedtls_mpi_mod_read(mbedtls_mpi_mod_residue *r, int mbedtls_mpi_mod_read(mbedtls_mpi_mod_residue *r,
const mbedtls_mpi_mod_modulus *m, const mbedtls_mpi_mod_modulus *N,
const unsigned char *buf, const unsigned char *buf,
size_t buflen, size_t buflen,
mbedtls_mpi_mod_ext_rep ext_rep) mbedtls_mpi_mod_ext_rep ext_rep)
@ -357,28 +357,28 @@ int mbedtls_mpi_mod_read(mbedtls_mpi_mod_residue *r,
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;
} }
ret = mbedtls_mpi_mod_raw_read(r->p, m, buf, buflen, ext_rep); ret = mbedtls_mpi_mod_raw_read(r->p, N, buf, buflen, ext_rep);
if (ret != 0) { if (ret != 0) {
goto cleanup; goto cleanup;
} }
r->limbs = m->limbs; r->limbs = N->limbs;
ret = mbedtls_mpi_mod_raw_canonical_to_modulus_rep(r->p, m); ret = mbedtls_mpi_mod_raw_canonical_to_modulus_rep(r->p, N);
cleanup: 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)
@ -386,28 +386,28 @@ int mbedtls_mpi_mod_write(const mbedtls_mpi_mod_residue *r,
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

@ -140,34 +140,34 @@ typedef struct {
/** Setup a residue structure. /** Setup a residue structure.
* *
* The residue will be set up with the buffer \p p and modulus \p m. * The residue will be set up with the buffer \p p and modulus \p N.
* *
* The memory pointed to by \p p will be used by the resulting residue structure. * The memory pointed to by \p p will be used by the resulting residue structure.
* The value at the pointed-to memory will be the initial value of \p r and must * The value at the pointed-to memory will be the initial value of \p r and must
* hold a value that is less than the modulus. This value will be used as-is * hold a value that is less than the modulus. This value will be used as-is
* and interpreted according to the value of the `m->int_rep` field. * and interpreted according to the value of the `N->int_rep` field.
* *
* The modulus \p m will be the modulus associated with \p r. The residue \p r * The modulus \p N will be the modulus associated with \p r. The residue \p r
* should only be used in operations where the modulus is \p m. * should only be used in operations where the modulus is \p N.
* *
* \param[out] r The address of the residue to setup. * \param[out] r The address of the residue to setup.
* \param[in] m The address of the modulus related to \p r. * \param[in] N The address of the modulus related to \p r.
* \param[in] p The address of the limb array containing the value of \p r. * \param[in] p The address of the limb array containing the value of \p r.
* The memory pointed to by \p p will be used by \p r and must * The memory pointed to by \p p will be used by \p r and must
* not be modified in any way until after * not be modified in any way until after
* mbedtls_mpi_mod_residue_release() is called. The data * mbedtls_mpi_mod_residue_release() is called. The data
* pointed to by \p p must be less than the modulus (the value * pointed to by \p p must be less than the modulus (the value
* pointed to by `m->p`) and already in the representation * pointed to by `N->p`) and already in the representation
* indicated by `m->int_rep`. * indicated by `N->int_rep`.
* \param p_limbs The number of limbs of \p p. Must be the same as the number * \param p_limbs The number of limbs of \p p. Must be the same as the number
* of limbs in the modulus \p m. * of limbs in the modulus \p N.
* *
* \return \c 0 if successful. * \return \c 0 if successful.
* \return #MBEDTLS_ERR_MPI_BAD_INPUT_DATA if \p p_limbs is less than the * \return #MBEDTLS_ERR_MPI_BAD_INPUT_DATA if \p p_limbs is less than the
* limbs in \p m or if \p p is not less than \p m. * limbs in \p N or if \p p is not less than \p N.
*/ */
int mbedtls_mpi_mod_residue_setup(mbedtls_mpi_mod_residue *r, int mbedtls_mpi_mod_residue_setup(mbedtls_mpi_mod_residue *r,
const mbedtls_mpi_mod_modulus *m, const mbedtls_mpi_mod_modulus *N,
mbedtls_mpi_uint *p, mbedtls_mpi_uint *p,
size_t p_limbs); size_t p_limbs);
@ -185,25 +185,25 @@ void mbedtls_mpi_mod_residue_release(mbedtls_mpi_mod_residue *r);
/** Initialize a modulus structure. /** Initialize a modulus structure.
* *
* \param[out] m The address of the modulus structure to initialize. * \param[out] N The address of the modulus structure to initialize.
*/ */
void mbedtls_mpi_mod_modulus_init(mbedtls_mpi_mod_modulus *m); void mbedtls_mpi_mod_modulus_init(mbedtls_mpi_mod_modulus *N);
/** Setup a modulus structure. /** Setup a modulus structure.
* *
* \param[out] m The address of the modulus structure to populate. * \param[out] N The address of the modulus structure to populate.
* \param[in] p The address of the limb array storing the value of \p m. * \param[in] p The address of the limb array storing the value of \p N.
* The memory pointed to by \p p will be used by \p m and must * The memory pointed to by \p p will be used by \p N and must
* not be modified in any way until after * not be modified in any way until after
* mbedtls_mpi_mod_modulus_free() is called. * mbedtls_mpi_mod_modulus_free() is called.
* \param p_limbs The number of limbs of \p p. * \param p_limbs The number of limbs of \p p.
* \param int_rep The internal representation to be used for residues * \param int_rep The internal representation to be used for residues
* associated with \p m (see #mbedtls_mpi_mod_rep_selector). * associated with \p N (see #mbedtls_mpi_mod_rep_selector).
* *
* \return \c 0 if successful. * \return \c 0 if successful.
* \return #MBEDTLS_ERR_MPI_BAD_INPUT_DATA if \p int_rep is invalid. * \return #MBEDTLS_ERR_MPI_BAD_INPUT_DATA if \p int_rep is invalid.
*/ */
int mbedtls_mpi_mod_modulus_setup(mbedtls_mpi_mod_modulus *m, int mbedtls_mpi_mod_modulus_setup(mbedtls_mpi_mod_modulus *N,
const mbedtls_mpi_uint *p, const mbedtls_mpi_uint *p,
size_t p_limbs, size_t p_limbs,
mbedtls_mpi_mod_rep_selector int_rep); mbedtls_mpi_mod_rep_selector int_rep);
@ -216,9 +216,9 @@ int mbedtls_mpi_mod_modulus_setup(mbedtls_mpi_mod_modulus *m,
* mbedtls_mpi_mod_modulus_setup() only removes the reference to it, * mbedtls_mpi_mod_modulus_setup() only removes the reference to it,
* making it safe to free or to use it again. * making it safe to free or to use it again.
* *
* \param[in,out] m The address of the modulus structure to free. * \param[in,out] N The address of the modulus structure to free.
*/ */
void mbedtls_mpi_mod_modulus_free(mbedtls_mpi_mod_modulus *m); void mbedtls_mpi_mod_modulus_free(mbedtls_mpi_mod_modulus *N);
/* BEGIN MERGE SLOT 1 */ /* BEGIN MERGE SLOT 1 */
@ -401,16 +401,16 @@ int mbedtls_mpi_mod_random(mbedtls_mpi_mod_residue *X,
/** Read a residue from a byte buffer. /** Read a residue from a byte buffer.
* *
* The residue will be automatically converted to the internal representation * The residue will be automatically converted to the internal representation
* based on the value of the `m->int_rep` field. * based on the value of the `N->int_rep` field.
* *
* The modulus \p m will be the modulus associated with \p r. The residue \p r * The modulus \p N will be the modulus associated with \p r. The residue \p r
* should only be used in operations where the modulus is \p m or a modulus * should only be used in operations where the modulus is \p N or a modulus
* equivalent to \p m (in the sense that all their fields or memory pointed by * equivalent to \p N (in the sense that all their fields or memory pointed by
* their fields hold the same value). * their fields hold the same value).
* *
* \param[out] r The address of the residue. It must have exactly the same * \param[out] r The address of the residue. It must have exactly the same
* number of limbs as the modulus \p m. * number of limbs as the modulus \p N.
* \param[in] m The address of the modulus. * \param[in] N The address of the modulus.
* \param[in] buf The input buffer to import from. * \param[in] buf The input buffer to import from.
* \param buflen The length in bytes of \p buf. * \param buflen The length in bytes of \p buf.
* \param ext_rep The endianness of the number in the input buffer. * \param ext_rep The endianness of the number in the input buffer.
@ -419,32 +419,32 @@ int mbedtls_mpi_mod_random(mbedtls_mpi_mod_residue *X,
* \return #MBEDTLS_ERR_MPI_BUFFER_TOO_SMALL if \p r isn't * \return #MBEDTLS_ERR_MPI_BUFFER_TOO_SMALL if \p r isn't
* large enough to hold the value in \p buf. * large enough to hold the value in \p buf.
* \return #MBEDTLS_ERR_MPI_BAD_INPUT_DATA if \p ext_rep * \return #MBEDTLS_ERR_MPI_BAD_INPUT_DATA if \p ext_rep
* is invalid or the value in the buffer is not less than \p m. * is invalid or the value in the buffer is not less than \p N.
*/ */
int mbedtls_mpi_mod_read(mbedtls_mpi_mod_residue *r, int mbedtls_mpi_mod_read(mbedtls_mpi_mod_residue *r,
const mbedtls_mpi_mod_modulus *m, const mbedtls_mpi_mod_modulus *N,
const unsigned char *buf, const unsigned char *buf,
size_t buflen, size_t buflen,
mbedtls_mpi_mod_ext_rep ext_rep); mbedtls_mpi_mod_ext_rep ext_rep);
/** 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
@ -460,7 +460,7 @@ int mbedtls_mpi_mod_read(mbedtls_mpi_mod_residue *r,
* 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);

View File

@ -50,7 +50,7 @@ void mbedtls_mpi_mod_raw_cond_swap(mbedtls_mpi_uint *X,
} }
int mbedtls_mpi_mod_raw_read(mbedtls_mpi_uint *X, int mbedtls_mpi_mod_raw_read(mbedtls_mpi_uint *X,
const mbedtls_mpi_mod_modulus *m, const mbedtls_mpi_mod_modulus *N,
const unsigned char *input, const unsigned char *input,
size_t input_length, size_t input_length,
mbedtls_mpi_mod_ext_rep ext_rep) mbedtls_mpi_mod_ext_rep ext_rep)
@ -59,11 +59,11 @@ int mbedtls_mpi_mod_raw_read(mbedtls_mpi_uint *X,
switch (ext_rep) { switch (ext_rep) {
case MBEDTLS_MPI_MOD_EXT_REP_LE: case MBEDTLS_MPI_MOD_EXT_REP_LE:
ret = mbedtls_mpi_core_read_le(X, m->limbs, ret = mbedtls_mpi_core_read_le(X, N->limbs,
input, input_length); input, input_length);
break; break;
case MBEDTLS_MPI_MOD_EXT_REP_BE: case MBEDTLS_MPI_MOD_EXT_REP_BE:
ret = mbedtls_mpi_core_read_be(X, m->limbs, ret = mbedtls_mpi_core_read_be(X, N->limbs,
input, input_length); input, input_length);
break; break;
default: default:
@ -74,7 +74,7 @@ int mbedtls_mpi_mod_raw_read(mbedtls_mpi_uint *X,
goto cleanup; goto cleanup;
} }
if (!mbedtls_mpi_core_lt_ct(X, m->p, m->limbs)) { if (!mbedtls_mpi_core_lt_ct(X, N->p, N->limbs)) {
ret = MBEDTLS_ERR_MPI_BAD_INPUT_DATA; ret = MBEDTLS_ERR_MPI_BAD_INPUT_DATA;
goto cleanup; goto cleanup;
} }
@ -85,17 +85,17 @@ cleanup:
} }
int mbedtls_mpi_mod_raw_write(const mbedtls_mpi_uint *A, int mbedtls_mpi_mod_raw_write(const mbedtls_mpi_uint *A,
const mbedtls_mpi_mod_modulus *m, const mbedtls_mpi_mod_modulus *N,
unsigned char *output, unsigned char *output,
size_t output_length, size_t output_length,
mbedtls_mpi_mod_ext_rep ext_rep) mbedtls_mpi_mod_ext_rep ext_rep)
{ {
switch (ext_rep) { switch (ext_rep) {
case MBEDTLS_MPI_MOD_EXT_REP_LE: case MBEDTLS_MPI_MOD_EXT_REP_LE:
return mbedtls_mpi_core_write_le(A, m->limbs, return mbedtls_mpi_core_write_le(A, N->limbs,
output, output_length); output, output_length);
case MBEDTLS_MPI_MOD_EXT_REP_BE: case MBEDTLS_MPI_MOD_EXT_REP_BE:
return mbedtls_mpi_core_write_be(A, m->limbs, return mbedtls_mpi_core_write_be(A, N->limbs,
output, output_length); output, output_length);
default: default:
return MBEDTLS_ERR_MPI_BAD_INPUT_DATA; return MBEDTLS_ERR_MPI_BAD_INPUT_DATA;
@ -229,17 +229,17 @@ int mbedtls_mpi_mod_raw_random(mbedtls_mpi_uint *X,
/* BEGIN MERGE SLOT 7 */ /* BEGIN MERGE SLOT 7 */
int mbedtls_mpi_mod_raw_to_mont_rep(mbedtls_mpi_uint *X, int mbedtls_mpi_mod_raw_to_mont_rep(mbedtls_mpi_uint *X,
const mbedtls_mpi_mod_modulus *m) const mbedtls_mpi_mod_modulus *N)
{ {
mbedtls_mpi_uint *T; mbedtls_mpi_uint *T;
const size_t t_limbs = mbedtls_mpi_core_montmul_working_limbs(m->limbs); const size_t t_limbs = mbedtls_mpi_core_montmul_working_limbs(N->limbs);
if ((T = (mbedtls_mpi_uint *) mbedtls_calloc(t_limbs, ciL)) == NULL) { if ((T = (mbedtls_mpi_uint *) mbedtls_calloc(t_limbs, ciL)) == NULL) {
return MBEDTLS_ERR_MPI_ALLOC_FAILED; return MBEDTLS_ERR_MPI_ALLOC_FAILED;
} }
mbedtls_mpi_core_to_mont_rep(X, X, m->p, m->limbs, mbedtls_mpi_core_to_mont_rep(X, X, N->p, N->limbs,
m->rep.mont.mm, m->rep.mont.rr, T); N->rep.mont.mm, N->rep.mont.rr, T);
mbedtls_platform_zeroize(T, t_limbs * ciL); mbedtls_platform_zeroize(T, t_limbs * ciL);
mbedtls_free(T); mbedtls_free(T);
@ -247,16 +247,16 @@ int mbedtls_mpi_mod_raw_to_mont_rep(mbedtls_mpi_uint *X,
} }
int mbedtls_mpi_mod_raw_from_mont_rep(mbedtls_mpi_uint *X, int mbedtls_mpi_mod_raw_from_mont_rep(mbedtls_mpi_uint *X,
const mbedtls_mpi_mod_modulus *m) const mbedtls_mpi_mod_modulus *N)
{ {
const size_t t_limbs = mbedtls_mpi_core_montmul_working_limbs(m->limbs); const size_t t_limbs = mbedtls_mpi_core_montmul_working_limbs(N->limbs);
mbedtls_mpi_uint *T; mbedtls_mpi_uint *T;
if ((T = (mbedtls_mpi_uint *) mbedtls_calloc(t_limbs, ciL)) == NULL) { if ((T = (mbedtls_mpi_uint *) mbedtls_calloc(t_limbs, ciL)) == NULL) {
return MBEDTLS_ERR_MPI_ALLOC_FAILED; return MBEDTLS_ERR_MPI_ALLOC_FAILED;
} }
mbedtls_mpi_core_from_mont_rep(X, X, m->p, m->limbs, m->rep.mont.mm, T); mbedtls_mpi_core_from_mont_rep(X, X, N->p, N->limbs, N->rep.mont.mm, T);
mbedtls_platform_zeroize(T, t_limbs * ciL); mbedtls_platform_zeroize(T, t_limbs * ciL);
mbedtls_free(T); mbedtls_free(T);
@ -265,14 +265,14 @@ int mbedtls_mpi_mod_raw_from_mont_rep(mbedtls_mpi_uint *X,
void mbedtls_mpi_mod_raw_neg(mbedtls_mpi_uint *X, void mbedtls_mpi_mod_raw_neg(mbedtls_mpi_uint *X,
const mbedtls_mpi_uint *A, const mbedtls_mpi_uint *A,
const mbedtls_mpi_mod_modulus *m) const mbedtls_mpi_mod_modulus *N)
{ {
mbedtls_mpi_core_sub(X, m->p, A, m->limbs); mbedtls_mpi_core_sub(X, N->p, A, N->limbs);
/* If A=0 initially, then X=N now. Detect this by /* If A=0 initially, then X=N now. Detect this by
* subtracting N and catching the carry. */ * subtracting N and catching the carry. */
mbedtls_mpi_uint borrow = mbedtls_mpi_core_sub(X, X, m->p, m->limbs); mbedtls_mpi_uint borrow = mbedtls_mpi_core_sub(X, X, N->p, N->limbs);
(void) mbedtls_mpi_core_add_if(X, m->p, m->limbs, (unsigned) borrow); (void) mbedtls_mpi_core_add_if(X, N->p, N->limbs, (unsigned) borrow);
} }
/* END MERGE SLOT 7 */ /* END MERGE SLOT 7 */

View File

@ -145,10 +145,10 @@ void mbedtls_mpi_mod_raw_cond_swap(mbedtls_mpi_uint *X,
* The MPI needs to have enough limbs to store the full value (including any * The MPI needs to have enough limbs to store the full value (including any
* most significant zero bytes in the input). * most significant zero bytes in the input).
* *
* \param[out] X The address of the MPI. The size is determined by \p m. * \param[out] X The address of the MPI. The size is determined by \p N.
* (In particular, it must have at least as many limbs as * (In particular, it must have at least as many limbs as
* the modulus \p m.) * the modulus \p N.)
* \param[in] m The address of the modulus related to \p X. * \param[in] N The address of the modulus related to \p X.
* \param[in] input The input buffer to import from. * \param[in] input The input buffer to import from.
* \param input_length The length in bytes of \p input. * \param input_length The length in bytes of \p input.
* \param ext_rep The endianness of the number in the input buffer. * \param ext_rep The endianness of the number in the input buffer.
@ -157,20 +157,20 @@ void mbedtls_mpi_mod_raw_cond_swap(mbedtls_mpi_uint *X,
* \return #MBEDTLS_ERR_MPI_BUFFER_TOO_SMALL if \p X isn't * \return #MBEDTLS_ERR_MPI_BUFFER_TOO_SMALL if \p X isn't
* large enough to hold the value in \p input. * large enough to hold the value in \p input.
* \return #MBEDTLS_ERR_MPI_BAD_INPUT_DATA if the external representation * \return #MBEDTLS_ERR_MPI_BAD_INPUT_DATA if the external representation
* of \p m is invalid or \p X is not less than \p m. * of \p N is invalid or \p X is not less than \p N.
*/ */
int mbedtls_mpi_mod_raw_read(mbedtls_mpi_uint *X, int mbedtls_mpi_mod_raw_read(mbedtls_mpi_uint *X,
const mbedtls_mpi_mod_modulus *m, const mbedtls_mpi_mod_modulus *N,
const unsigned char *input, const unsigned char *input,
size_t input_length, size_t input_length,
mbedtls_mpi_mod_ext_rep ext_rep); mbedtls_mpi_mod_ext_rep ext_rep);
/** Export A into unsigned binary data. /** Export A into unsigned binary data.
* *
* \param[in] A The address of the MPI. The size is determined by \p m. * \param[in] A The address of the MPI. The size is determined by \p N.
* (In particular, it must have at least as many limbs as * (In particular, it must have at least as many limbs as
* the modulus \p m.) * the modulus \p N.)
* \param[in] m The address of the modulus related to \p A. * \param[in] N The address of the modulus related to \p A.
* \param[out] output The output buffer to export to. * \param[out] output The output buffer to export to.
* \param output_length The length in bytes of \p output. * \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. * \param ext_rep The endianness in which the number should be written into the output buffer.
@ -179,10 +179,10 @@ int mbedtls_mpi_mod_raw_read(mbedtls_mpi_uint *X,
* \return #MBEDTLS_ERR_MPI_BUFFER_TOO_SMALL if \p output isn't * \return #MBEDTLS_ERR_MPI_BUFFER_TOO_SMALL if \p output isn't
* large enough to hold the value of \p A. * large enough to hold the value of \p A.
* \return #MBEDTLS_ERR_MPI_BAD_INPUT_DATA if the external representation * \return #MBEDTLS_ERR_MPI_BAD_INPUT_DATA if the external representation
* of \p m is invalid. * of \p N is invalid.
*/ */
int mbedtls_mpi_mod_raw_write(const mbedtls_mpi_uint *A, int mbedtls_mpi_mod_raw_write(const mbedtls_mpi_uint *A,
const mbedtls_mpi_mod_modulus *m, const mbedtls_mpi_mod_modulus *N,
unsigned char *output, unsigned char *output,
size_t output_length, size_t output_length,
mbedtls_mpi_mod_ext_rep ext_rep); mbedtls_mpi_mod_ext_rep ext_rep);
@ -410,43 +410,43 @@ int mbedtls_mpi_mod_raw_random(mbedtls_mpi_uint *X,
/** Convert an MPI into Montgomery form. /** Convert an MPI into Montgomery form.
* *
* \param X The address of the MPI. * \param X The address of the MPI.
* Must have the same number of limbs as \p m. * Must have the same number of limbs as \p N.
* \param m The address of the modulus, which gives the size of * \param N The address of the modulus, which gives the size of
* the base `R` = 2^(biL*m->limbs). * the base `R` = 2^(biL*N->limbs).
* *
* \return \c 0 if successful. * \return \c 0 if successful.
*/ */
int mbedtls_mpi_mod_raw_to_mont_rep(mbedtls_mpi_uint *X, int mbedtls_mpi_mod_raw_to_mont_rep(mbedtls_mpi_uint *X,
const mbedtls_mpi_mod_modulus *m); const mbedtls_mpi_mod_modulus *N);
/** Convert an MPI back from Montgomery representation. /** Convert an MPI back from Montgomery representation.
* *
* \param X The address of the MPI. * \param X The address of the MPI.
* Must have the same number of limbs as \p m. * Must have the same number of limbs as \p N.
* \param m The address of the modulus, which gives the size of * \param N The address of the modulus, which gives the size of
* the base `R`= 2^(biL*m->limbs). * the base `R`= 2^(biL*N->limbs).
* *
* \return \c 0 if successful. * \return \c 0 if successful.
*/ */
int mbedtls_mpi_mod_raw_from_mont_rep(mbedtls_mpi_uint *X, int mbedtls_mpi_mod_raw_from_mont_rep(mbedtls_mpi_uint *X,
const mbedtls_mpi_mod_modulus *m); const mbedtls_mpi_mod_modulus *N);
/** \brief Perform fixed width modular negation. /** \brief Perform fixed width modular negation.
* *
* The size of the operation is determined by \p m. \p A must have * The size of the operation is determined by \p N. \p A must have
* the same number of limbs as \p m. * the same number of limbs as \p N.
* *
* \p X may be aliased to \p A. * \p X may be aliased to \p A.
* *
* \param[out] X The result of the modular negation. * \param[out] X The result of the modular negation.
* This must be initialized. * This must be initialized.
* \param[in] A Little-endian presentation of the input operand. This * \param[in] A Little-endian presentation of the input operand. This
* must be less than or equal to \p m. * must be less than or equal to \p N.
* \param[in] m The modulus to use. * \param[in] N The modulus to use.
*/ */
void mbedtls_mpi_mod_raw_neg(mbedtls_mpi_uint *X, void mbedtls_mpi_mod_raw_neg(mbedtls_mpi_uint *X,
const mbedtls_mpi_uint *A, const mbedtls_mpi_uint *A,
const mbedtls_mpi_mod_modulus *m); const mbedtls_mpi_mod_modulus *N);
/* END MERGE SLOT 7 */ /* END MERGE SLOT 7 */
/* BEGIN MERGE SLOT 8 */ /* BEGIN MERGE SLOT 8 */