diff --git a/library/constant_time.c b/library/constant_time.c index cf1f2b8c9..e8ed08605 100644 --- a/library/constant_time.c +++ b/library/constant_time.c @@ -139,13 +139,13 @@ void mbedtls_ct_memmove_left(void *start, size_t total, size_t offset) j = j % total; // Read a byte - uint8_t b = ((uint8_t*)start)[j]; + uint8_t b = ((uint8_t *) start)[j]; // Set it to zero if it's out of range b = mbedtls_ct_uint_if0(not_dummy, b); // Write the byte to start[i] - ((uint8_t*)start)[i] = b; + ((uint8_t *) start)[i] = b; } } @@ -192,8 +192,8 @@ void mbedtls_ct_memcpy_offset(unsigned char *dest, size_t offsetval; for (offsetval = offset_min; offsetval <= offset_max; offsetval++) { - mbedtls_ct_memcpy_if(mbedtls_ct_bool_eq(offsetval, offset), dest, src + offsetval, NULL, - len); + mbedtls_ct_memcpy_if(mbedtls_ct_bool_eq(offsetval, offset), dest, src + offsetval, NULL, + len); } } diff --git a/library/constant_time_impl.h b/library/constant_time_impl.h index b4b3917cd..44682c049 100644 --- a/library/constant_time_impl.h +++ b/library/constant_time_impl.h @@ -178,12 +178,6 @@ static inline unsigned char mbedtls_ct_uchar_in_range_if(unsigned char low, * Everything below here is trivial wrapper functions */ -static inline mbedtls_ct_condition_t mbedtls_ct_bool_eq(mbedtls_ct_uint_t x, - mbedtls_ct_uint_t y) -{ - return ~mbedtls_ct_bool_ne(x, y); -} - static inline size_t mbedtls_ct_size_if(mbedtls_ct_condition_t condition, size_t if1, size_t if0) @@ -200,8 +194,8 @@ static inline unsigned mbedtls_ct_uint_if(mbedtls_ct_condition_t condition, #if defined(MBEDTLS_BIGNUM_C) -static inline mbedtls_mpi_uint mbedtls_ct_mpi_uint_if(mbedtls_ct_condition_t condition, \ - mbedtls_mpi_uint if1, \ +static inline mbedtls_mpi_uint mbedtls_ct_mpi_uint_if(mbedtls_ct_condition_t condition, + mbedtls_mpi_uint if1, mbedtls_mpi_uint if0) { return (mbedtls_mpi_uint) mbedtls_ct_if(condition, @@ -231,6 +225,12 @@ static inline mbedtls_mpi_uint mbedtls_ct_mpi_uint_if0(mbedtls_ct_condition_t co #endif /* MBEDTLS_BIGNUM_C */ +static inline mbedtls_ct_condition_t mbedtls_ct_bool_eq(mbedtls_ct_uint_t x, + mbedtls_ct_uint_t y) +{ + return ~mbedtls_ct_bool_ne(x, y); +} + static inline mbedtls_ct_condition_t mbedtls_ct_bool_gt(mbedtls_ct_uint_t x, mbedtls_ct_uint_t y) {