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
This commit is contained in:
Aorimn 2016-01-31 12:30:55 +01:00 committed by Jaeden Amero
parent 75e3661ebe
commit fb67fae83a
3 changed files with 3675 additions and 0 deletions

View File

@ -48,6 +48,7 @@ add_test_suite(aes aes.ecb)
add_test_suite(aes aes.cbc)
add_test_suite(aes aes.cfb)
add_test_suite(aes aes.rest)
add_test_suite(aes aes.xex)
add_test_suite(arc4)
add_test_suite(aria)
add_test_suite(asn1write)

View File

@ -151,6 +151,80 @@ exit:
}
/* 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 )

File diff suppressed because it is too large Load Diff