Bignum: update const qualifiers
While at it, mark parameters based on their role.
Signed-off-by: Janos Follath <janos.follath@arm.com>
diff --git a/library/bignum_core.c b/library/bignum_core.c
index c015fc7..606765a 100644
--- a/library/bignum_core.c
+++ b/library/bignum_core.c
@@ -129,7 +129,7 @@
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 397f79a..8266cec 100644
--- a/library/bignum_core.h
+++ b/library/bignum_core.h
@@ -44,8 +44,8 @@
*
* \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 @@
/** 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 @@
* 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 @@
* 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 @@
* 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 @@
* 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 4382bf8..5678ca0 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 d2ba73e..3fbedbf 100644
--- a/library/bignum_mod.h
+++ b/library/bignum_mod.h
@@ -67,22 +67,23 @@
/** 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 @@
* 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 @@
* 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 c4a3eb8..334965d 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 @@
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 e8c2a7d..b4ef83d 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 @@
* \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 );