mirror of
https://github.com/Mbed-TLS/mbedtls.git
synced 2025-04-17 20:42:44 +00:00
Add mbedtls_ct_bool_if and mbedtls_ct_bool_if_else_0
Signed-off-by: Dave Rodgman <dave.rodgman@arm.com>
This commit is contained in:
parent
437500c5b1
commit
143f5f7c68
@ -350,6 +350,14 @@ static inline unsigned mbedtls_ct_uint_if(mbedtls_ct_condition_t condition,
|
|||||||
return (unsigned) mbedtls_ct_if(condition, (mbedtls_ct_uint_t) if1, (mbedtls_ct_uint_t) if0);
|
return (unsigned) mbedtls_ct_if(condition, (mbedtls_ct_uint_t) if1, (mbedtls_ct_uint_t) if0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline mbedtls_ct_condition_t mbedtls_ct_bool_if(mbedtls_ct_condition_t condition,
|
||||||
|
mbedtls_ct_condition_t if1,
|
||||||
|
mbedtls_ct_condition_t if0)
|
||||||
|
{
|
||||||
|
return (mbedtls_ct_condition_t) mbedtls_ct_if(condition, (mbedtls_ct_uint_t) if1,
|
||||||
|
(mbedtls_ct_uint_t) if0);
|
||||||
|
}
|
||||||
|
|
||||||
#if defined(MBEDTLS_BIGNUM_C)
|
#if defined(MBEDTLS_BIGNUM_C)
|
||||||
|
|
||||||
static inline mbedtls_mpi_uint mbedtls_ct_mpi_uint_if(mbedtls_ct_condition_t condition,
|
static inline mbedtls_mpi_uint mbedtls_ct_mpi_uint_if(mbedtls_ct_condition_t condition,
|
||||||
@ -373,6 +381,12 @@ static inline unsigned mbedtls_ct_uint_if_else_0(mbedtls_ct_condition_t conditio
|
|||||||
return (unsigned) (condition & if1);
|
return (unsigned) (condition & if1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline mbedtls_ct_condition_t mbedtls_ct_bool_if_else_0(mbedtls_ct_condition_t condition,
|
||||||
|
mbedtls_ct_condition_t if1)
|
||||||
|
{
|
||||||
|
return (mbedtls_ct_condition_t) (condition & if1);
|
||||||
|
}
|
||||||
|
|
||||||
#if defined(MBEDTLS_BIGNUM_C)
|
#if defined(MBEDTLS_BIGNUM_C)
|
||||||
|
|
||||||
static inline mbedtls_mpi_uint mbedtls_ct_mpi_uint_if_else_0(mbedtls_ct_condition_t condition,
|
static inline mbedtls_mpi_uint mbedtls_ct_mpi_uint_if_else_0(mbedtls_ct_condition_t condition,
|
||||||
|
@ -291,6 +291,22 @@ static inline unsigned mbedtls_ct_uint_if(mbedtls_ct_condition_t condition,
|
|||||||
unsigned if1,
|
unsigned if1,
|
||||||
unsigned if0);
|
unsigned if0);
|
||||||
|
|
||||||
|
/** Choose between two mbedtls_ct_condition_t 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 mbedtls_ct_condition_t mbedtls_ct_bool_if(mbedtls_ct_condition_t condition,
|
||||||
|
mbedtls_ct_condition_t if1,
|
||||||
|
mbedtls_ct_condition_t if0);
|
||||||
|
|
||||||
#if defined(MBEDTLS_BIGNUM_C)
|
#if defined(MBEDTLS_BIGNUM_C)
|
||||||
|
|
||||||
/** Choose between two mbedtls_mpi_uint values.
|
/** Choose between two mbedtls_mpi_uint values.
|
||||||
@ -327,6 +343,23 @@ static inline mbedtls_mpi_uint mbedtls_ct_mpi_uint_if(mbedtls_ct_condition_t con
|
|||||||
*/
|
*/
|
||||||
static inline unsigned mbedtls_ct_uint_if_else_0(mbedtls_ct_condition_t condition, unsigned if1);
|
static inline unsigned mbedtls_ct_uint_if_else_0(mbedtls_ct_condition_t condition, unsigned if1);
|
||||||
|
|
||||||
|
/** Choose between an mbedtls_ct_condition_t and 0.
|
||||||
|
*
|
||||||
|
* Functionally equivalent to:
|
||||||
|
*
|
||||||
|
* condition ? if1 : 0.
|
||||||
|
*
|
||||||
|
* Functionally equivalent to mbedtls_ct_bool_if(condition, if1, 0) but
|
||||||
|
* results in smaller code size.
|
||||||
|
*
|
||||||
|
* \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 mbedtls_ct_condition_t mbedtls_ct_bool_if_else_0(mbedtls_ct_condition_t condition,
|
||||||
|
mbedtls_ct_condition_t if1);
|
||||||
|
|
||||||
/** Choose between a size_t value and 0.
|
/** Choose between a size_t value and 0.
|
||||||
*
|
*
|
||||||
* Functionally equivalent to:
|
* Functionally equivalent to:
|
||||||
|
@ -131,12 +131,15 @@ void mbedtls_ct_if(char *c_str, char *t_str, char *f_str)
|
|||||||
TEST_EQUAL(mbedtls_ct_if(c, t, f), expected);
|
TEST_EQUAL(mbedtls_ct_if(c, t, f), expected);
|
||||||
TEST_EQUAL(mbedtls_ct_size_if(c, t, f), (size_t) expected);
|
TEST_EQUAL(mbedtls_ct_size_if(c, t, f), (size_t) expected);
|
||||||
TEST_EQUAL(mbedtls_ct_uint_if(c, t, f), (unsigned) expected);
|
TEST_EQUAL(mbedtls_ct_uint_if(c, t, f), (unsigned) expected);
|
||||||
|
TEST_EQUAL(mbedtls_ct_bool_if(c, mbedtls_ct_bool(t), mbedtls_ct_bool(f)),
|
||||||
|
mbedtls_ct_bool(expected));
|
||||||
#if defined(MBEDTLS_BIGNUM_C)
|
#if defined(MBEDTLS_BIGNUM_C)
|
||||||
TEST_EQUAL(mbedtls_ct_mpi_uint_if(c, t, f), (mbedtls_mpi_uint) expected);
|
TEST_EQUAL(mbedtls_ct_mpi_uint_if(c, t, f), (mbedtls_mpi_uint) expected);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
TEST_EQUAL(mbedtls_ct_uint_if_else_0(c, t), (unsigned) expected0);
|
TEST_EQUAL(mbedtls_ct_uint_if_else_0(c, t), (unsigned) expected0);
|
||||||
TEST_EQUAL(mbedtls_ct_size_if_else_0(c, (size_t) t), (size_t) expected0);
|
TEST_EQUAL(mbedtls_ct_size_if_else_0(c, (size_t) t), (size_t) expected0);
|
||||||
|
TEST_EQUAL(mbedtls_ct_bool_if_else_0(c, mbedtls_ct_bool(t)), mbedtls_ct_bool(expected0));
|
||||||
#if defined(MBEDTLS_BIGNUM_C)
|
#if defined(MBEDTLS_BIGNUM_C)
|
||||||
TEST_EQUAL(mbedtls_ct_mpi_uint_if_else_0(c, t), (mbedtls_mpi_uint) expected0);
|
TEST_EQUAL(mbedtls_ct_mpi_uint_if_else_0(c, t), (mbedtls_mpi_uint) expected0);
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user