From 15531bc6d2e3c5e68229cd38baf59f382d238c89 Mon Sep 17 00:00:00 2001 From: Dave Rodgman Date: Wed, 23 Nov 2022 16:11:04 +0000 Subject: [PATCH] Test for all alignment combinations Signed-off-by: Dave Rodgman --- tests/suites/test_suite_common.function | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/tests/suites/test_suite_common.function b/tests/suites/test_suite_common.function index 8412e60f3b..6c0d4afc4d 100644 --- a/tests/suites/test_suite_common.function +++ b/tests/suites/test_suite_common.function @@ -68,14 +68,19 @@ void mbedtls_xor( int len ) mbedtls_xor( r2, r2, r2, n ); ASSERT_COMPARE( r1, n, r2, n ); - /* Test non-word-aligned buffers */ - fill_arrays( a + 1, b + 1, r1 + 1, r2 + 1, n ); - for ( size_t i = 0; i < n; i++ ) + /* Test non-word-aligned buffers, for all combinations of alignedness */ + for ( int i = 0; i < 7; i++ ) { - r1[i + 1] = a[i + 1] ^ b[i + 1]; + int r_off = i & 1, a_off = (i & 2) >> 1, b_off = (i & 4) >> 2; + fill_arrays( a, b, r1, r2, n + 1 ); + + for ( size_t i = 0; i < n; i++ ) + { + r1[i + r_off] = a[i + a_off] ^ b[i + b_off]; + } + mbedtls_xor( r2 + r_off, a + a_off, b + b_off, n ); + ASSERT_COMPARE( r1 + r_off, n, r2 + r_off, n ); } - mbedtls_xor( r2 + 1, a + 1, b + 1, n ); - ASSERT_COMPARE( r1 + 1, n, r2 + 1, n ); exit: if ( a != NULL ) mbedtls_free( a ); if ( a != NULL ) mbedtls_free( b );