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>
diff --git a/tests/suites/test_suite_constant_time.function b/tests/suites/test_suite_constant_time.function
index ba31c96..ac4dd7a 100644
--- a/tests/suites/test_suite_constant_time.function
+++ b/tests/suites/test_suite_constant_time.function
@@ -92,22 +92,25 @@
/* 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 */