From 58c721e89461a2f2d5c2527b4bafcfde02604189 Mon Sep 17 00:00:00 2001 From: Dave Rodgman Date: Sat, 21 Jan 2023 11:00:30 +0000 Subject: [PATCH] Add TEST_CF_SECRET to mbedtls_ct_memcpy_if_eq test Signed-off-by: Dave Rodgman --- .../suites/test_suite_constant_time.function | 25 ++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/tests/suites/test_suite_constant_time.function b/tests/suites/test_suite_constant_time.function index 167962fb4..14dc8ae5c 100644 --- a/tests/suites/test_suite_constant_time.function +++ b/tests/suites/test_suite_constant_time.function @@ -80,7 +80,17 @@ void mbedtls_ct_memcpy_if_eq(int eq, int size, int offset) expected[i] = eq ? 1 : 0xff; } - mbedtls_ct_memcpy_if_eq(result + offset, src, size, eq, 1); + int one, secret_eq; + TEST_CF_SECRET(&one, sizeof(one)); + TEST_CF_SECRET(&secret_eq, sizeof(secret_eq)); + one = 1; + secret_eq = eq; + + mbedtls_ct_memcpy_if_eq(result + offset, src, size, secret_eq, one); + + TEST_CF_PUBLIC(&one, sizeof(one)); + TEST_CF_PUBLIC(&secret_eq, sizeof(secret_eq)); + ASSERT_COMPARE(expected, size, result + offset, size); for (int i = 0; i < size + offset; i++) { @@ -88,9 +98,18 @@ void mbedtls_ct_memcpy_if_eq(int eq, int size, int offset) result[i] = 0xff; expected[i] = eq ? 1 : 0xff; } - mbedtls_ct_memcpy_if_eq(result, src + offset, size, eq, 1); - ASSERT_COMPARE(expected, size, result, size); + TEST_CF_SECRET(&one, sizeof(one)); + TEST_CF_SECRET(&secret_eq, sizeof(secret_eq)); + one = 1; + secret_eq = eq; + + mbedtls_ct_memcpy_if_eq(result, src + offset, size, secret_eq, one); + + TEST_CF_PUBLIC(&one, sizeof(one)); + TEST_CF_PUBLIC(&secret_eq, sizeof(secret_eq)); + + ASSERT_COMPARE(expected, size, result, size); exit: mbedtls_free(src); mbedtls_free(result);