Function esp_idf_svc::sys::mbedtls_mpi_safe_cond_swap
source · pub unsafe extern "C" fn mbedtls_mpi_safe_cond_swap(
X: *mut mbedtls_mpi,
Y: *mut mbedtls_mpi,
swap: u8,
) -> i32
Expand description
\brief Perform a safe conditional swap which doesn’t reveal whether the condition was true or not.
\param X The first MPI. This must be initialized. \param Y The second MPI. This must be initialized. \param swap The condition deciding whether to perform the swap or not. Must be either 0 or 1: * \c 1: Swap the 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 if( swap ) mbedtls_mpi_swap( X, Y ); except that it avoids leaking any information about whether the swap was done or not (the above code may leak information through branch prediction and/or memory access 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 #MBEDTLS_ERR_MPI_ALLOC_FAILED if memory allocation failed. \return Another negative error code on other kinds of failure.