Add AES-XEX tests cases
The test cases come from the XTS test vectors given by the CAVP initiative
from NIST (see [1]).
As mentioned in a previous commit, XEX is a simpler case of XTS.
Therefore, to construct the test_suite_aes.xex.data file, extraction of
the XEX-possible cases has been done on the given test vectors.
All of the extracted test vectors pass the tests on a Linux x86_64 machine.
[1] http://csrc.nist.gov/groups/STM/cavp/documents/aes/XTSTestVectors.zip
diff --git a/tests/suites/test_suite_aes.function b/tests/suites/test_suite_aes.function
index f1e9033..947976a 100644
--- a/tests/suites/test_suite_aes.function
+++ b/tests/suites/test_suite_aes.function
@@ -151,6 +151,80 @@
}
/* END_CASE */
+/* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_XEX */
+void aes_encrypt_xex( char *hex_key_string, char *hex_iv_string,
+ char *hex_src_string, char *hex_dst_string,
+ int xex_result )
+{
+ unsigned char key_str[100] = { 0, };
+ unsigned char iv_str[100] = { 0, };
+ unsigned char src_str[100] = { 0, };
+ unsigned char dst_str[100] = { 0, };
+ unsigned char output[100] = { 0, };
+ mbedtls_aes_context crypt_ctx, tweak_ctx;
+ int key_len, data_len;
+
+ mbedtls_aes_init( &crypt_ctx );
+ mbedtls_aes_init( &tweak_ctx );
+
+ key_len = unhexify( key_str, hex_key_string );
+ unhexify( iv_str, hex_iv_string );
+ data_len = unhexify( src_str, hex_src_string );
+
+ mbedtls_aes_setkey_enc( &crypt_ctx, key_str, ( key_len * 8 ) / 2 );
+ mbedtls_aes_setkey_enc( &tweak_ctx, key_str + key_len / 2, ( key_len * 8 ) / 2 );
+
+ TEST_ASSERT( mbedtls_aes_crypt_xex( &crypt_ctx, &tweak_ctx, MBEDTLS_AES_ENCRYPT, data_len, iv_str, src_str, output ) == xex_result );
+ if( xex_result == 0 )
+ {
+ hexify( dst_str, output, data_len );
+
+ TEST_ASSERT( strcmp( (char *) dst_str, hex_dst_string ) == 0 );
+ }
+
+exit:
+ mbedtls_aes_free( &crypt_ctx );
+ mbedtls_aes_free( &tweak_ctx );
+}
+/* END_CASE */
+
+/* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_XEX */
+void aes_decrypt_xex( char *hex_key_string, char *hex_iv_string,
+ char *hex_src_string, char *hex_dst_string,
+ int xex_result )
+{
+ unsigned char key_str[100] = { 0, };
+ unsigned char iv_str[100] = { 0, };
+ unsigned char src_str[100] = { 0, };
+ unsigned char dst_str[100] = { 0, };
+ unsigned char output[100] = { 0, };
+ mbedtls_aes_context crypt_ctx, tweak_ctx;
+ int key_len, data_len;
+
+ mbedtls_aes_init( &crypt_ctx );
+ mbedtls_aes_init( &tweak_ctx );
+
+ key_len = unhexify( key_str, hex_key_string );
+ unhexify( iv_str, hex_iv_string );
+ data_len = unhexify( src_str, hex_src_string );
+
+ mbedtls_aes_setkey_dec( &crypt_ctx, key_str, ( key_len * 8 ) / 2 );
+ mbedtls_aes_setkey_enc( &tweak_ctx, key_str + key_len / 2, ( key_len * 8 ) / 2 );
+
+ TEST_ASSERT( mbedtls_aes_crypt_xex( &crypt_ctx, &tweak_ctx, MBEDTLS_AES_DECRYPT, data_len, iv_str, src_str, output ) == xex_result );
+ if( xex_result == 0 )
+ {
+ hexify( dst_str, output, data_len );
+
+ TEST_ASSERT( strcmp( (char *) dst_str, hex_dst_string ) == 0 );
+ }
+
+exit:
+ mbedtls_aes_free( &crypt_ctx );
+ mbedtls_aes_free( &tweak_ctx );
+}
+/* END_CASE */
+
/* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CFB */
void aes_encrypt_cfb128( char *hex_key_string, char *hex_iv_string,
char *hex_src_string, char *hex_dst_string )