Move mbedtls_cf_uint_mask function to the constant-time module
Signed-off-by: gabor-mezei-arm <gabor.mezei@arm.com>
This commit is contained in:
parent
db9a38c672
commit
340948e4a5
3 changed files with 22 additions and 19 deletions
|
@ -92,3 +92,22 @@ int mbedtls_safer_memcmp( const void *a, const void *b, size_t n )
|
||||||
|
|
||||||
return( diff );
|
return( diff );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Turn zero-or-nonzero into zero-or-all-bits-one, without branches.
|
||||||
|
*
|
||||||
|
* \param value The value to analyze.
|
||||||
|
* \return Zero if \p value is zero, otherwise all-bits-one.
|
||||||
|
*/
|
||||||
|
unsigned mbedtls_cf_uint_mask( unsigned value )
|
||||||
|
{
|
||||||
|
/* MSVC has a warning about unary minus on unsigned, but this is
|
||||||
|
* well-defined and precisely what we want to do here */
|
||||||
|
#if defined(_MSC_VER)
|
||||||
|
#pragma warning( push )
|
||||||
|
#pragma warning( disable : 4146 )
|
||||||
|
#endif
|
||||||
|
return( - ( ( value | - value ) >> ( sizeof( value ) * 8 - 1 ) ) );
|
||||||
|
#if defined(_MSC_VER)
|
||||||
|
#pragma warning( pop )
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
|
@ -28,3 +28,6 @@ int mbedtls_constant_time_memcmp( const void *v1, const void *v2, size_t len );
|
||||||
unsigned char mbedtls_nist_kw_safer_memcmp( const void *a, const void *b, size_t n );
|
unsigned char mbedtls_nist_kw_safer_memcmp( const void *a, const void *b, size_t n );
|
||||||
|
|
||||||
int mbedtls_safer_memcmp( const void *a, const void *b, size_t n );
|
int mbedtls_safer_memcmp( const void *a, const void *b, size_t n );
|
||||||
|
|
||||||
|
|
||||||
|
unsigned mbedtls_cf_uint_mask( unsigned value );
|
||||||
|
|
|
@ -1458,25 +1458,6 @@ cleanup:
|
||||||
#endif /* MBEDTLS_PKCS1_V21 */
|
#endif /* MBEDTLS_PKCS1_V21 */
|
||||||
|
|
||||||
#if defined(MBEDTLS_PKCS1_V15)
|
#if defined(MBEDTLS_PKCS1_V15)
|
||||||
/** Turn zero-or-nonzero into zero-or-all-bits-one, without branches.
|
|
||||||
*
|
|
||||||
* \param value The value to analyze.
|
|
||||||
* \return Zero if \p value is zero, otherwise all-bits-one.
|
|
||||||
*/
|
|
||||||
static unsigned mbedtls_cf_uint_mask( unsigned value )
|
|
||||||
{
|
|
||||||
/* MSVC has a warning about unary minus on unsigned, but this is
|
|
||||||
* well-defined and precisely what we want to do here */
|
|
||||||
#if defined(_MSC_VER)
|
|
||||||
#pragma warning( push )
|
|
||||||
#pragma warning( disable : 4146 )
|
|
||||||
#endif
|
|
||||||
return( - ( ( value | - value ) >> ( sizeof( value ) * 8 - 1 ) ) );
|
|
||||||
#if defined(_MSC_VER)
|
|
||||||
#pragma warning( pop )
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Check whether a size is out of bounds, without branches.
|
/** Check whether a size is out of bounds, without branches.
|
||||||
*
|
*
|
||||||
* This is equivalent to `size > max`, but is likely to be compiled to
|
* This is equivalent to `size > max`, but is likely to be compiled to
|
||||||
|
|
Loading…
Reference in a new issue