Test for all alignment combinations
@@ -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 );
+ /* Test non-word-aligned buffers, for all combinations of alignedness */
+ for ( int i = 0; i < 7; i++ )
+ {
+ 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 + 1] = a[i + 1] ^ b[i + 1];
+ 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 );
