Add test for unaligned buffers
@@ -18,10 +18,10 @@ void mbedtls_xor( int len )
{
size_t n = (size_t) len;
unsigned char *a = NULL, *b = NULL, *r1 = NULL, *r2 = NULL;
- ASSERT_ALLOC( a, n );
- ASSERT_ALLOC( b, n );
- ASSERT_ALLOC( r1, n );
- ASSERT_ALLOC( r2, n );
+ ASSERT_ALLOC( a, n + 1 );
+ ASSERT_ALLOC( b, n + 1 );
+ ASSERT_ALLOC( r1, n + 1 );
+ ASSERT_ALLOC( r2, n + 1 );
/* Test non-overlapping */
fill_arrays( a, b, r1, r2, n );
@@ -67,6 +67,15 @@ 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++ )
+ {
+ r1[i + 1] = a[i + 1] ^ b[i + 1];
+ }
+ 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 );
