Allow test assertions on constant-flow scalar data
When testing a function that is supposed to be constant-flow, we declare the
inputs as constant-flow secrets with TEST_CF_SECRET. The result of such a
function is itself a constant-flow secret, so it can't be tested with
comparison operators.
In TEST_EQUAL, TEST_LE_U and TEST_LE_S, declare the values to be compared as
public. This way, test code doesn't need to explicitly declare results as
public if they're only used by one of these macros.
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
diff --git a/tests/src/helpers.c b/tests/src/helpers.c
index c310d48..bfd2189 100644
--- a/tests/src/helpers.c
+++ b/tests/src/helpers.c
@@ -15,6 +15,7 @@
* limitations under the License.
*/
+#include <test/constant_flow.h>
#include <test/helpers.h>
#include <test/macros.h>
#include <string.h>
@@ -120,8 +121,12 @@
int mbedtls_test_equal( const char *test, int line_no, const char* filename,
unsigned long long value1, unsigned long long value2 )
{
+ TEST_CF_PUBLIC( &value1, sizeof( value1 ) );
+ TEST_CF_PUBLIC( &value2, sizeof( value2 ) );
+
if( value1 == value2 )
return( 1 );
+
if( mbedtls_test_info.result == MBEDTLS_TEST_RESULT_FAILED )
{
/* We've already recorded the test as having failed. Don't
@@ -143,8 +148,12 @@
int mbedtls_test_le_u( const char *test, int line_no, const char* filename,
unsigned long long value1, unsigned long long value2 )
{
+ TEST_CF_PUBLIC( &value1, sizeof( value1 ) );
+ TEST_CF_PUBLIC( &value2, sizeof( value2 ) );
+
if( value1 <= value2 )
return( 1 );
+
if( mbedtls_test_info.result == MBEDTLS_TEST_RESULT_FAILED )
{
/* We've already recorded the test as having failed. Don't
@@ -166,8 +175,12 @@
int mbedtls_test_le_s( const char *test, int line_no, const char* filename,
long long value1, long long value2 )
{
+ TEST_CF_PUBLIC( &value1, sizeof( value1 ) );
+ TEST_CF_PUBLIC( &value2, sizeof( value2 ) );
+
if( value1 <= value2 )
return( 1 );
+
if( mbedtls_test_info.result == MBEDTLS_TEST_RESULT_FAILED )
{
/* We've already recorded the test as having failed. Don't