Remove mbedtls_ct_int_if

Signed-off-by: Dave Rodgman <dave.rodgman@arm.com>
This commit is contained in:
Dave Rodgman 2023-09-21 21:53:54 +01:00
parent 7ad37e40a6
commit a9d70125a3
2 changed files with 0 additions and 64 deletions

View File

@ -331,42 +331,6 @@ static inline unsigned char mbedtls_ct_uchar_in_range_if(unsigned char low,
return (unsigned char) (~(low_mask | high_mask)) & to;
}
static inline int mbedtls_ct_int_if(mbedtls_ct_condition_t condition, int if1, int if0)
{
/*
* Use memcpy to avoid unsigned-to-signed conversion UB.
*
* Although this looks inefficient, in practice (for gcc and clang),
* the sizeof test is eliminated at compile-time, and identical code is generated
* as for mbedtls_ct_uint_if (for -Os and -O1 or higher).
*/
int result;
if (sizeof(int) <= sizeof(unsigned int)) {
unsigned int uif1 = 0, uif0 = 0;
memcpy(&uif1, &if1, sizeof(if1));
memcpy(&uif0, &if0, sizeof(if0));
unsigned int uresult = mbedtls_ct_uint_if(condition, uif1, uif0);
memcpy(&result, &uresult, sizeof(result));
} else {
mbedtls_ct_memcpy_if(condition, (unsigned char *) &result, (const unsigned char *) &if1,
(const unsigned char *) &if0, sizeof(result));
}
return result;
}
static inline int mbedtls_ct_int_if_else_0(mbedtls_ct_condition_t condition, int if1)
{
if (sizeof(int) <= sizeof(unsigned int)) {
unsigned int uif1 = 0;
memcpy(&uif1, &if1, sizeof(if1));
unsigned int uresult = mbedtls_ct_uint_if_else_0(condition, uif1);
int result;
memcpy(&result, &uresult, sizeof(result));
return result;
} else {
return mbedtls_ct_int_if(condition, if1, 0);
}
}
/* ============================================================================
* Everything below here is trivial wrapper functions

View File

@ -411,34 +411,6 @@ static inline unsigned char mbedtls_ct_uchar_in_range_if(unsigned char low,
unsigned char c,
unsigned char t);
/** Choose between two int values.
*
* Functionally equivalent to:
*
* condition ? if1 : if0.
*
* \param condition Condition to test.
* \param if1 Value to use if \p condition == MBEDTLS_CT_TRUE.
* \param if0 Value to use if \p condition == MBEDTLS_CT_FALSE.
*
* \return \c if1 if \p condition == MBEDTLS_CT_TRUE, otherwise \c if0.
*/
static inline int mbedtls_ct_int_if(mbedtls_ct_condition_t condition, int if1, int if0);
/** Choose between an int value and 0.
*
* Functionally equivalent to:
*
* condition ? if1 : 0.
*
* Functionally equivalent to mbedtls_ct_int_if(condition, if1, 0).
*
* \param condition Condition to test.
* \param if1 Value to use if \p condition == MBEDTLS_CT_TRUE.
*
* \return \c if1 if \p condition == MBEDTLS_CT_TRUE, otherwise 0.
*/
static inline int mbedtls_ct_int_if_else_0(mbedtls_ct_condition_t condition, int if1);
/* ============================================================================
* Block memory operations