1
0
mirror of https://github.com/Mbed-TLS/mbedtls.git synced 2025-07-30 22:43:08 +03:00

Move mbedtls_cf_uint_if function to the constant-time module

Signed-off-by: gabor-mezei-arm <gabor.mezei@arm.com>
This commit is contained in:
gabor-mezei-arm
2021-09-27 12:59:30 +02:00
parent 3f90fd540a
commit b2dbf2c113
3 changed files with 19 additions and 16 deletions

View File

@ -273,3 +273,19 @@ unsigned mbedtls_cf_mpi_uint_lt( const mbedtls_mpi_uint x,
}
#endif /* MBEDTLS_BIGNUM_C */
/** Choose between two integer values, without branches.
*
* This is equivalent to `cond ? if1 : if0`, but is likely to be compiled
* to code using bitwise operation rather than a branch.
*
* \param cond Condition to test.
* \param if1 Value to use if \p cond is nonzero.
* \param if0 Value to use if \p cond is zero.
* \return \c if1 if \p cond is nonzero, otherwise \c if0.
*/
unsigned mbedtls_cf_uint_if( unsigned cond, unsigned if1, unsigned if0 )
{
unsigned mask = mbedtls_cf_uint_mask( cond );
return( ( mask & if1 ) | (~mask & if0 ) );
}