Improve tests for mbedtls_ct_uchar_in_range_if

Remove tests from base64. Improve coverage in constant_time
tests.

Signed-off-by: Dave Rodgman <dave.rodgman@arm.com>
This commit is contained in:
Dave Rodgman 2023-05-18 11:23:59 +01:00
parent 585f7f776d
commit 1e8b6ac09c
4 changed files with 151 additions and 73 deletions

View file

@ -1,27 +1,3 @@
mask_of_range empty (1..0)
mask_of_range:1:0
mask_of_range empty (255..0)
mask_of_range:255:0
mask_of_range empty (42..7)
mask_of_range:42:7
mask_of_range 0..0
mask_of_range:0:0
mask_of_range 42..42
mask_of_range:42:42
mask_of_range 255..255
mask_of_range:255:255
mask_of_range 0..255
mask_of_range:0:255
mask_of_range 'A'..'Z'
mask_of_range:65:90
enc_char (all digits)
enc_chars:

View file

@ -15,26 +15,6 @@ static const char base64_digits[] =
* END_DEPENDENCIES
*/
/* BEGIN_CASE */
void mask_of_range(int low_arg, int high_arg)
{
unsigned char low = low_arg, high = high_arg;
unsigned c;
for (c = 0; c <= 0xff; c++) {
mbedtls_test_set_step(c);
TEST_CF_SECRET(&c, sizeof(c));
unsigned char m = mbedtls_ct_uchar_in_range_if(low, high, c, 0xff);
TEST_CF_PUBLIC(&c, sizeof(c));
TEST_CF_PUBLIC(&m, sizeof(m));
if (low <= c && c <= high) {
TEST_EQUAL(m, 0xff);
} else {
TEST_EQUAL(m, 0);
}
}
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_TEST_HOOKS */
void enc_chars()
{

View file

@ -283,29 +283,149 @@ mbedtls_ct_bool_xxx:"256":"138"
mbedtls_ct_bool_xxx 6 6
mbedtls_ct_bool_xxx:"0x6":"0x6"
mbedtls_ct_uchar_in_range_if 0 0 0 0
mbedtls_ct_uchar_in_range_if:0:0:0:0
mbedtls_ct_uchar_in_range_if 0 0 0
mbedtls_ct_uchar_in_range_if:0:0:0
mbedtls_ct_uchar_in_range_if 0 100 2 2
mbedtls_ct_uchar_in_range_if:0:100:2:2
mbedtls_ct_uchar_in_range_if 0 0 100
mbedtls_ct_uchar_in_range_if:0:0:100
mbedtls_ct_uchar_in_range_if 0 100 2 0
mbedtls_ct_uchar_in_range_if:0:100:2:0
mbedtls_ct_uchar_in_range_if 0 0 255
mbedtls_ct_uchar_in_range_if:0:0:255
mbedtls_ct_uchar_in_range_if 0 100 200 2
mbedtls_ct_uchar_in_range_if:0:100:200:2
mbedtls_ct_uchar_in_range_if 0 65 0
mbedtls_ct_uchar_in_range_if:0:65:0
mbedtls_ct_uchar_in_range_if 0 255 0 2
mbedtls_ct_uchar_in_range_if:0:255:0:2
mbedtls_ct_uchar_in_range_if 0 65 100
mbedtls_ct_uchar_in_range_if:0:65:100
mbedtls_ct_uchar_in_range_if 0 255 100 2
mbedtls_ct_uchar_in_range_if:0:255:100:2
mbedtls_ct_uchar_in_range_if 0 65 255
mbedtls_ct_uchar_in_range_if:0:65:255
mbedtls_ct_uchar_in_range_if 0 255 255 2
mbedtls_ct_uchar_in_range_if:0:255:255:2
mbedtls_ct_uchar_in_range_if 0 90 0
mbedtls_ct_uchar_in_range_if:0:90:0
mbedtls_ct_uchar_in_range_if 255 255 255 255
mbedtls_ct_uchar_in_range_if:255:255:255:255
mbedtls_ct_uchar_in_range_if 0 90 100
mbedtls_ct_uchar_in_range_if:0:90:100
mbedtls_ct_uchar_in_range_if 0 90 255
mbedtls_ct_uchar_in_range_if:0:90:255
mbedtls_ct_uchar_in_range_if 0 255 0
mbedtls_ct_uchar_in_range_if:0:255:0
mbedtls_ct_uchar_in_range_if 0 255 100
mbedtls_ct_uchar_in_range_if:0:255:100
mbedtls_ct_uchar_in_range_if 0 255 255
mbedtls_ct_uchar_in_range_if:0:255:255
mbedtls_ct_uchar_in_range_if 65 0 0
mbedtls_ct_uchar_in_range_if:65:0:0
mbedtls_ct_uchar_in_range_if 65 0 100
mbedtls_ct_uchar_in_range_if:65:0:100
mbedtls_ct_uchar_in_range_if 65 0 255
mbedtls_ct_uchar_in_range_if:65:0:255
mbedtls_ct_uchar_in_range_if 65 65 0
mbedtls_ct_uchar_in_range_if:65:65:0
mbedtls_ct_uchar_in_range_if 65 65 100
mbedtls_ct_uchar_in_range_if:65:65:100
mbedtls_ct_uchar_in_range_if 65 65 255
mbedtls_ct_uchar_in_range_if:65:65:255
mbedtls_ct_uchar_in_range_if 65 90 0
mbedtls_ct_uchar_in_range_if:65:90:0
mbedtls_ct_uchar_in_range_if 65 90 100
mbedtls_ct_uchar_in_range_if:65:90:100
mbedtls_ct_uchar_in_range_if 65 90 255
mbedtls_ct_uchar_in_range_if:65:90:255
mbedtls_ct_uchar_in_range_if 65 255 0
mbedtls_ct_uchar_in_range_if:65:255:0
mbedtls_ct_uchar_in_range_if 65 255 100
mbedtls_ct_uchar_in_range_if:65:255:100
mbedtls_ct_uchar_in_range_if 65 255 255
mbedtls_ct_uchar_in_range_if:65:255:255
mbedtls_ct_uchar_in_range_if 90 0 0
mbedtls_ct_uchar_in_range_if:90:0:0
mbedtls_ct_uchar_in_range_if 90 0 100
mbedtls_ct_uchar_in_range_if:90:0:100
mbedtls_ct_uchar_in_range_if 90 0 255
mbedtls_ct_uchar_in_range_if:90:0:255
mbedtls_ct_uchar_in_range_if 90 65 0
mbedtls_ct_uchar_in_range_if:90:65:0
mbedtls_ct_uchar_in_range_if 90 65 100
mbedtls_ct_uchar_in_range_if:90:65:100
mbedtls_ct_uchar_in_range_if 90 65 255
mbedtls_ct_uchar_in_range_if:90:65:255
mbedtls_ct_uchar_in_range_if 90 90 0
mbedtls_ct_uchar_in_range_if:90:90:0
mbedtls_ct_uchar_in_range_if 90 90 100
mbedtls_ct_uchar_in_range_if:90:90:100
mbedtls_ct_uchar_in_range_if 90 90 255
mbedtls_ct_uchar_in_range_if:90:90:255
mbedtls_ct_uchar_in_range_if 90 255 0
mbedtls_ct_uchar_in_range_if:90:255:0
mbedtls_ct_uchar_in_range_if 90 255 100
mbedtls_ct_uchar_in_range_if:90:255:100
mbedtls_ct_uchar_in_range_if 90 255 255
mbedtls_ct_uchar_in_range_if:90:255:255
mbedtls_ct_uchar_in_range_if 255 0 0
mbedtls_ct_uchar_in_range_if:255:0:0
mbedtls_ct_uchar_in_range_if 255 0 100
mbedtls_ct_uchar_in_range_if:255:0:100
mbedtls_ct_uchar_in_range_if 255 0 255
mbedtls_ct_uchar_in_range_if:255:0:255
mbedtls_ct_uchar_in_range_if 255 65 0
mbedtls_ct_uchar_in_range_if:255:65:0
mbedtls_ct_uchar_in_range_if 255 65 100
mbedtls_ct_uchar_in_range_if:255:65:100
mbedtls_ct_uchar_in_range_if 255 65 255
mbedtls_ct_uchar_in_range_if:255:65:255
mbedtls_ct_uchar_in_range_if 255 90 0
mbedtls_ct_uchar_in_range_if:255:90:0
mbedtls_ct_uchar_in_range_if 255 90 100
mbedtls_ct_uchar_in_range_if:255:90:100
mbedtls_ct_uchar_in_range_if 255 90 255
mbedtls_ct_uchar_in_range_if:255:90:255
mbedtls_ct_uchar_in_range_if 255 255 0
mbedtls_ct_uchar_in_range_if:255:255:0
mbedtls_ct_uchar_in_range_if 255 255 100
mbedtls_ct_uchar_in_range_if:255:255:100
mbedtls_ct_uchar_in_range_if 255 255 255
mbedtls_ct_uchar_in_range_if:255:255:255
mbedtls_ct_if 0x0 0x0 0x0
mbedtls_ct_if:"0x0":"0x0":"0x0"
@ -579,4 +699,3 @@ mbedtls_ct_memmove_left:16:15
mbedtls_ct_memmove_left 16 16
mbedtls_ct_memmove_left:16:16

View file

@ -92,22 +92,25 @@ void mbedtls_ct_bool_xxx(char *x_str, char *y_str)
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_BASE64_C */
void mbedtls_ct_uchar_in_range_if(int li, int hi, int xi, int ti)
void mbedtls_ct_uchar_in_range_if(int li, int hi, int ti)
{
unsigned char l = li, h = hi, x = xi, t = ti;
unsigned char expected = (x >= l) && (x <= h) ? t : 0;
unsigned char l = li, h = hi, t = ti;
TEST_CF_SECRET(&x, sizeof(x));
TEST_CF_SECRET(&l, sizeof(l));
TEST_CF_SECRET(&h, sizeof(h));
TEST_CF_SECRET(&t, sizeof(t));
for (unsigned x = 0; x <= 255; x++) {
unsigned char expected = (x >= l) && (x <= h) ? t : 0;
TEST_EQUAL(mbedtls_ct_uchar_in_range_if(l, h, x, t), expected);
TEST_CF_SECRET(&x, sizeof(x));
TEST_CF_SECRET(&l, sizeof(l));
TEST_CF_SECRET(&h, sizeof(h));
TEST_CF_SECRET(&t, sizeof(t));
TEST_CF_PUBLIC(&x, sizeof(x));
TEST_CF_PUBLIC(&l, sizeof(l));
TEST_CF_PUBLIC(&h, sizeof(h));
TEST_CF_PUBLIC(&t, sizeof(t));
TEST_EQUAL(mbedtls_ct_uchar_in_range_if(l, h, (unsigned char) x, t), expected);
TEST_CF_PUBLIC(&x, sizeof(x));
TEST_CF_PUBLIC(&l, sizeof(l));
TEST_CF_PUBLIC(&h, sizeof(h));
TEST_CF_PUBLIC(&t, sizeof(t));
}
}
/* END_CASE */