Improve testing for mbedtls_ct_int_if
Signed-off-by: Dave Rodgman <dave.rodgman@arm.com>
This commit is contained in:
parent
f81b2a14f2
commit
f1915f623d
1 changed files with 12 additions and 4 deletions
|
@ -130,10 +130,12 @@ void mbedtls_ct_if(char *c_str, char *t_str, char *f_str)
|
|||
* check t and f before making them negative.
|
||||
*/
|
||||
#define ABS_INT_MIN (UINT_MAX - ((unsigned int) (INT_MIN)) + 1U)
|
||||
int t_neg = t <= ABS_INT_MIN ? -((int) t) : INT_MIN;
|
||||
int f_neg = f <= ABS_INT_MIN ? -((int) f) : INT_MIN;
|
||||
int t_neg = (t <= ABS_INT_MIN) && (t <= INT_MAX) ? -((int) t) : INT_MIN;
|
||||
int f_neg = (f <= ABS_INT_MIN) && (t <= INT_MAX) ? -((int) f) : INT_MIN;
|
||||
int expected0_neg = c ? t_neg : 0;
|
||||
int expected_neg = c ? t_neg : f_neg;
|
||||
int t_fits_in_int = t <= INT_MAX;
|
||||
int f_fits_in_int = f <= INT_MAX;
|
||||
|
||||
TEST_CF_SECRET(&c, sizeof(c));
|
||||
TEST_CF_SECRET(&t, sizeof(t));
|
||||
|
@ -157,8 +159,14 @@ void mbedtls_ct_if(char *c_str, char *t_str, char *f_str)
|
|||
TEST_EQUAL(mbedtls_ct_mpi_uint_if_else_0(c, t), (mbedtls_mpi_uint) expected0);
|
||||
#endif
|
||||
|
||||
TEST_EQUAL(mbedtls_ct_error_if_else_0(c, t_neg), expected0_neg);
|
||||
TEST_EQUAL(mbedtls_ct_error_if(c, t_neg, f_neg), expected_neg);
|
||||
if (t_fits_in_int) {
|
||||
TEST_EQUAL(mbedtls_ct_int_if_else_0(c, (int) t), (int) expected0);
|
||||
if (f_fits_in_int) {
|
||||
TEST_EQUAL(mbedtls_ct_int_if(c, (int) t, (int) f), (int) expected);
|
||||
}
|
||||
}
|
||||
TEST_EQUAL(mbedtls_ct_int_if_else_0(c, t_neg), expected0_neg);
|
||||
TEST_EQUAL(mbedtls_ct_int_if(c, t_neg, f_neg), expected_neg);
|
||||
|
||||
TEST_CF_PUBLIC(&c, sizeof(c));
|
||||
TEST_CF_PUBLIC(&t, sizeof(t));
|
||||
|
|
Loading…
Reference in a new issue