Merge pull request #6211 from tom-cosgrove-arm/explicit-warning-re-ct-conditions-not-0-or-1
Be explicit about constant time bignum functions that must take a 0 or 1 condition value
This commit is contained in:
commit
20ebaac85e
2 changed files with 15 additions and 7 deletions
|
@ -277,7 +277,7 @@ void mbedtls_mpi_swap( mbedtls_mpi *X, mbedtls_mpi *Y );
|
||||||
* \param Y The MPI to be assigned from. This must point to an
|
* \param Y The MPI to be assigned from. This must point to an
|
||||||
* initialized MPI.
|
* initialized MPI.
|
||||||
* \param assign The condition deciding whether to perform the
|
* \param assign The condition deciding whether to perform the
|
||||||
* assignment or not. Possible values:
|
* assignment or not. Must be either 0 or 1:
|
||||||
* * \c 1: Perform the assignment `X = Y`.
|
* * \c 1: Perform the assignment `X = Y`.
|
||||||
* * \c 0: Keep the original value of \p X.
|
* * \c 0: Keep the original value of \p X.
|
||||||
*
|
*
|
||||||
|
@ -288,6 +288,10 @@ void mbedtls_mpi_swap( mbedtls_mpi *X, mbedtls_mpi *Y );
|
||||||
* information through branch prediction and/or memory access
|
* information through branch prediction and/or memory access
|
||||||
* patterns analysis).
|
* patterns analysis).
|
||||||
*
|
*
|
||||||
|
* \warning If \p assign is neither 0 nor 1, the result of this function
|
||||||
|
* is indeterminate, and the resulting value in \p X might be
|
||||||
|
* neither its original value nor the value in \p Y.
|
||||||
|
*
|
||||||
* \return \c 0 if successful.
|
* \return \c 0 if successful.
|
||||||
* \return #MBEDTLS_ERR_MPI_ALLOC_FAILED if memory allocation failed.
|
* \return #MBEDTLS_ERR_MPI_ALLOC_FAILED if memory allocation failed.
|
||||||
* \return Another negative error code on other kinds of failure.
|
* \return Another negative error code on other kinds of failure.
|
||||||
|
@ -300,24 +304,28 @@ int mbedtls_mpi_safe_cond_assign( mbedtls_mpi *X, const mbedtls_mpi *Y, unsigned
|
||||||
*
|
*
|
||||||
* \param X The first MPI. This must be initialized.
|
* \param X The first MPI. This must be initialized.
|
||||||
* \param Y The second MPI. This must be initialized.
|
* \param Y The second MPI. This must be initialized.
|
||||||
* \param assign The condition deciding whether to perform
|
* \param swap The condition deciding whether to perform
|
||||||
* the swap or not. Possible values:
|
* the swap or not. Must be either 0 or 1:
|
||||||
* * \c 1: Swap the values of \p X and \p Y.
|
* * \c 1: Swap the values of \p X and \p Y.
|
||||||
* * \c 0: Keep the original values of \p X and \p Y.
|
* * \c 0: Keep the original values of \p X and \p Y.
|
||||||
*
|
*
|
||||||
* \note This function is equivalent to
|
* \note This function is equivalent to
|
||||||
* if( assign ) mbedtls_mpi_swap( X, Y );
|
* if( swap ) mbedtls_mpi_swap( X, Y );
|
||||||
* except that it avoids leaking any information about whether
|
* except that it avoids leaking any information about whether
|
||||||
* the assignment was done or not (the above code may leak
|
* the swap was done or not (the above code may leak
|
||||||
* information through branch prediction and/or memory access
|
* information through branch prediction and/or memory access
|
||||||
* patterns analysis).
|
* patterns analysis).
|
||||||
*
|
*
|
||||||
|
* \warning If \p swap is neither 0 nor 1, the result of this function
|
||||||
|
* is indeterminate, and both \p X and \p Y might end up with
|
||||||
|
* values different to either of the original ones.
|
||||||
|
*
|
||||||
* \return \c 0 if successful.
|
* \return \c 0 if successful.
|
||||||
* \return #MBEDTLS_ERR_MPI_ALLOC_FAILED if memory allocation failed.
|
* \return #MBEDTLS_ERR_MPI_ALLOC_FAILED if memory allocation failed.
|
||||||
* \return Another negative error code on other kinds of failure.
|
* \return Another negative error code on other kinds of failure.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
int mbedtls_mpi_safe_cond_swap( mbedtls_mpi *X, mbedtls_mpi *Y, unsigned char assign );
|
int mbedtls_mpi_safe_cond_swap( mbedtls_mpi *X, mbedtls_mpi *Y, unsigned char swap );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Store integer value in MPI.
|
* \brief Store integer value in MPI.
|
||||||
|
|
|
@ -272,7 +272,7 @@ unsigned mbedtls_ct_uint_if( unsigned condition,
|
||||||
* \note if1 and if0 must be either 1 or -1, otherwise the result
|
* \note if1 and if0 must be either 1 or -1, otherwise the result
|
||||||
* is undefined.
|
* is undefined.
|
||||||
*
|
*
|
||||||
* \param condition Condition to test.
|
* \param condition Condition to test; must be either 0 or 1.
|
||||||
* \param if1 The first sign; must be either +1 or -1.
|
* \param if1 The first sign; must be either +1 or -1.
|
||||||
* \param if0 The second sign; must be either +1 or -1.
|
* \param if0 The second sign; must be either +1 or -1.
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in a new issue