From 6b8a4ad0d8c14e435adfb6dc931d8f1eb03232dd Mon Sep 17 00:00:00 2001 From: Janos Follath Date: Fri, 19 Aug 2022 10:58:34 +0100 Subject: [PATCH] Bignum: update const qualifiers While at it, mark parameters based on their role. Signed-off-by: Janos Follath --- library/bignum_core.c | 2 +- library/bignum_core.h | 46 ++++++++++++++++++++-------------------- library/bignum_mod.c | 2 +- library/bignum_mod.h | 35 +++++++++++++++--------------- library/bignum_mod_raw.c | 8 +++---- library/bignum_mod_raw.h | 32 ++++++++++++++-------------- 6 files changed, 63 insertions(+), 62 deletions(-) diff --git a/library/bignum_core.c b/library/bignum_core.c index c015fc7ac1..606765a4e2 100644 --- a/library/bignum_core.c +++ b/library/bignum_core.c @@ -129,7 +129,7 @@ static mbedtls_mpi_uint mpi_bigendian_to_host( mbedtls_mpi_uint x ) return( mpi_bigendian_to_host_c( x ) ); } -void mbedtls_mpi_core_bigendian_to_host( mbedtls_mpi_uint * const X, +void mbedtls_mpi_core_bigendian_to_host( mbedtls_mpi_uint *X, size_t limbs ) { mbedtls_mpi_uint *cur_limb_left; diff --git a/library/bignum_core.h b/library/bignum_core.h index 397f79a471..8266cece53 100644 --- a/library/bignum_core.h +++ b/library/bignum_core.h @@ -44,8 +44,8 @@ size_t mbedtls_mpi_core_clz( const mbedtls_mpi_uint x ); * * \note This function returns 0 if all the limbs of \p X are 0. * - * \param X The address of the MPI. - * \param nx The number of limbs of \p X. + * \param[in] X The address of the MPI. + * \param nx The number of limbs of \p X. * * \return The number of bits in \p X. */ @@ -54,10 +54,10 @@ size_t mbedtls_mpi_core_bitlen( const mbedtls_mpi_uint *X, size_t nx ); /** Convert a big-endian byte array aligned to the size of mbedtls_mpi_uint * into the storage form used by mbedtls_mpi. * - * \param X The address of the MPI. - * \param limbs The number of limbs of \p X. + * \param[in,out] X The address of the MPI. + * \param limbs The number of limbs of \p X. */ -void mbedtls_mpi_core_bigendian_to_host( mbedtls_mpi_uint * const X, +void mbedtls_mpi_core_bigendian_to_host( mbedtls_mpi_uint *X, size_t limbs ); /** Import X from unsigned binary data, little endian. @@ -65,10 +65,10 @@ void mbedtls_mpi_core_bigendian_to_host( mbedtls_mpi_uint * const X, * The MPI needs to have enough limbs to store the full value (including any * most significant zero bytes in the input). * - * \param X The address of the MPI. - * \param nx The number of limbs of \p X. - * \param buf The input buffer to import from. - * \param buflen The length in bytes of \p buf. + * \param[out] X The address of the MPI. + * \param nx The number of limbs of \p X. + * \param[in] buf The input buffer to import from. + * \param buflen The length in bytes of \p buf. * * \return \c 0 if successful. * \return #MBEDTLS_ERR_MPI_BUFFER_TOO_SMALL if \p X isn't @@ -84,12 +84,12 @@ int mbedtls_mpi_core_read_le( mbedtls_mpi_uint *X, * The MPI needs to have enough limbs to store the full value (including any * most significant zero bytes in the input). * - * \param X The address of the MPI. - * May only be #NULL if \nx is 0 and \p buflen is 0. - * \param nx The number of limbs of \p X. - * \param buf The input buffer to import from. - * May only be #NULL if \p buflen is 0. - * \param buflen The length in bytes of \p buf. + * \param[out] X The address of the MPI. + * May only be #NULL if \nx is 0 and \p buflen is 0. + * \param nx The number of limbs of \p X. + * \param[in] buf The input buffer to import from. + * May only be #NULL if \p buflen is 0. + * \param buflen The length in bytes of \p buf. * * \return \c 0 if successful. * \return #MBEDTLS_ERR_MPI_BUFFER_TOO_SMALL if \p X isn't @@ -106,10 +106,10 @@ int mbedtls_mpi_core_read_be( mbedtls_mpi_uint *X, * value held in \p X fits in the buffer (that is, if enough of the most * significant bytes of \p X are 0). * - * \param X The address of the MPI. - * \param nx The number of limbs of \p X. - * \param buf The output buffer to export to. - * \param buflen The length in bytes of \p buf. + * \param[in] X The address of the MPI. + * \param nx The number of limbs of \p X. + * \param[out] buf The output buffer to export to. + * \param buflen The length in bytes of \p buf. * * \return \c 0 if successful. * \return #MBEDTLS_ERR_MPI_BUFFER_TOO_SMALL if \p buf isn't @@ -126,10 +126,10 @@ int mbedtls_mpi_core_write_le( const mbedtls_mpi_uint *X, * value held in \p X fits in the buffer (that is, if enough of the most * significant bytes of \p X are 0). * - * \param X The address of the MPI. - * \param nx The number of limbs of \p X. - * \param buf The output buffer to export to. - * \param buflen The length in bytes of \p buf. + * \param[in] X The address of the MPI. + * \param nx The number of limbs of \p X. + * \param[out] buf The output buffer to export to. + * \param buflen The length in bytes of \p buf. * * \return \c 0 if successful. * \return #MBEDTLS_ERR_MPI_BUFFER_TOO_SMALL if \p buf isn't diff --git a/library/bignum_mod.c b/library/bignum_mod.c index 4382bf85a6..5678ca0920 100644 --- a/library/bignum_mod.c +++ b/library/bignum_mod.c @@ -43,7 +43,7 @@ #include "constant_time_internal.h" int mbedtls_mpi_mod_residue_setup( mbedtls_mpi_mod_residue *r, - mbedtls_mpi_mod_modulus *m, + const mbedtls_mpi_mod_modulus *m, mbedtls_mpi_uint *p, size_t pn ) { diff --git a/library/bignum_mod.h b/library/bignum_mod.h index d2ba73ecd1..3fbedbff26 100644 --- a/library/bignum_mod.h +++ b/library/bignum_mod.h @@ -67,22 +67,23 @@ typedef struct { /** Setup a residue structure. * - * \param 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 m The address of the modulus related to \p r. - * \param 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 pn The number of limbs of \p p. + * \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[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 pn The number of limbs of \p p. * * \return \c 0 if successful. * \return #MBEDTLS_ERR_MPI_BAD_INPUT_DATA if \p pn is less than the limbs * in \p m or if \p p is not less than \p m. */ int mbedtls_mpi_mod_residue_setup( mbedtls_mpi_mod_residue *r, - mbedtls_mpi_mod_modulus *m, + const mbedtls_mpi_mod_modulus *m, mbedtls_mpi_uint *p, size_t pn ); @@ -94,22 +95,22 @@ int mbedtls_mpi_mod_residue_setup( mbedtls_mpi_mod_residue *r, * This function invalidates \p r and it must not be used until after * mbedtls_mpi_mod_residue_setup() is called on it again. * - * \param r The address of residue to release. + * \param[out] r The address of residue to release. */ void mbedtls_mpi_mod_residue_release( mbedtls_mpi_mod_residue *r ); /** Initialize a modulus structure. * - * \param m The address of a modulus. + * \param[out] m The address of a modulus. */ void mbedtls_mpi_mod_modulus_init( mbedtls_mpi_mod_modulus *m ); /** Setup a modulus structure. * - * \param m The address of the modulus structure to populate. - * \param p The address of the limb array storing the value of \p m. The - * memory pointed to by \p p will be used by \p m and must not - * be modified in any way until after + * \param[out] m The address of the modulus structure to populate. + * \param[in] p The address of the limb array storing the value of \p m. + * The memory pointed to by \p p will be used by \p m and must + * not be modified in any way until after * mbedtls_mpi_mod_modulus_free() is called. * \param pn The number of limbs of \p p. * \param ext_rep The external representation to be used for residues @@ -135,7 +136,7 @@ int mbedtls_mpi_mod_modulus_setup( mbedtls_mpi_mod_modulus *m, * mbedtls_mpi_mod_modulus_setup() only removes the reference to it, * making it safe to free or to use it again. * - * \param m The address of a modulus. + * \param[in,out] m The address of a modulus. */ void mbedtls_mpi_mod_modulus_free( mbedtls_mpi_mod_modulus *m ); diff --git a/library/bignum_mod_raw.c b/library/bignum_mod_raw.c index c4a3eb8dca..334965d120 100644 --- a/library/bignum_mod_raw.c +++ b/library/bignum_mod_raw.c @@ -42,8 +42,8 @@ #include "constant_time_internal.h" int mbedtls_mpi_mod_raw_read( mbedtls_mpi_uint *X, - 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_ERROR_CORRUPTION_DETECTED; @@ -74,8 +74,8 @@ cleanup: return( ret ); } -int mbedtls_mpi_mod_raw_write( mbedtls_mpi_uint *X, - mbedtls_mpi_mod_modulus *m, +int mbedtls_mpi_mod_raw_write( const mbedtls_mpi_uint *X, + const mbedtls_mpi_mod_modulus *m, unsigned char *buf, size_t buflen ) { diff --git a/library/bignum_mod_raw.h b/library/bignum_mod_raw.h index e8c2a7d652..b4ef83dbf9 100644 --- a/library/bignum_mod_raw.h +++ b/library/bignum_mod_raw.h @@ -38,12 +38,12 @@ * The MPI needs to have enough limbs to store the full value (including any * most significant zero bytes in the input). * - * \param X The address of the MPI. The size is determined by \p m. (In - * particular, it must have at least as many limbs as the modulus - * \p m.) - * \param m The address of the modulus related to \p X. - * \param buf The input buffer to import from. - * \param buflen The length in bytes of \p buf. + * \param[out] X The address of the MPI. The size is determined by \p m. (In + * particular, it must have at least as many limbs as the + * modulus \p m.) + * \param[in] m The address of the modulus related to \p X. + * \param[in] buf The input buffer to import from. + * \param buflen The length in bytes of \p buf. * * \return \c 0 if successful. * \return #MBEDTLS_ERR_MPI_BUFFER_TOO_SMALL if \p X isn't @@ -52,18 +52,18 @@ * of \p m is invalid or \p X is not less than \p m. */ int mbedtls_mpi_mod_raw_read( mbedtls_mpi_uint *X, - mbedtls_mpi_mod_modulus *m, - unsigned char *buf, + const mbedtls_mpi_mod_modulus *m, + const unsigned char *buf, size_t buflen ); /** Export X into unsigned binary data. * - * \param X The address of the MPI. The size is determined by \p m. (In - * particular, it must have at least as many limbs as the modulus - * \p m.) - * \param m The address of the modulus related to \p X. - * \param buf The output buffer to export to. - * \param buflen The length in bytes of \p buf. + * \param[in] X The address of the MPI. The size is determined by \p m. (In + * particular, it must have at least as many limbs as the modulus + * \p m.) + * \param[in] m The address of the modulus related to \p X. + * \param[out] buf The output buffer to export to. + * \param buflen The length in bytes of \p buf. * * \return \c 0 if successful. * \return #MBEDTLS_ERR_MPI_BUFFER_TOO_SMALL if \p buf isn't @@ -71,8 +71,8 @@ int mbedtls_mpi_mod_raw_read( mbedtls_mpi_uint *X, * \return #MBEDTLS_ERR_MPI_BAD_INPUT_DATA if the external representation * of \p m is invalid. */ -int mbedtls_mpi_mod_raw_write( mbedtls_mpi_uint *X, - mbedtls_mpi_mod_modulus *m, +int mbedtls_mpi_mod_raw_write( const mbedtls_mpi_uint *X, + const mbedtls_mpi_mod_modulus *m, unsigned char *buf, size_t buflen );