tests: Make AES-XTS suite more stack friendly
Remove stack-allocated buffers from the AES-XTS test suites.
This commit is contained in:
parent
21d79cf947
commit
e5c4b07b92
2 changed files with 1454 additions and 1438 deletions
|
@ -153,71 +153,87 @@ exit:
|
|||
|
||||
/* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_XTS */
|
||||
void aes_encrypt_xts( char *hex_key_string, char *hex_data_unit_string,
|
||||
char *hex_src_string, char *hex_dst_string,
|
||||
int data_unit_len, int xts_result )
|
||||
char *hex_src_string, char *hex_dst_string )
|
||||
{
|
||||
unsigned char key_str[100] = { 0, };
|
||||
unsigned char data_unit_str[100] = { 0, };
|
||||
unsigned char src_str[100] = { 0, };
|
||||
unsigned char dst_str[100] = { 0, };
|
||||
unsigned char output[100] = { 0, };
|
||||
enum { AES_BLOCK_SIZE = 16 };
|
||||
unsigned char *data_unit = NULL;
|
||||
unsigned char *key = NULL;
|
||||
unsigned char *src = NULL;
|
||||
unsigned char *dst = NULL;
|
||||
unsigned char *output = NULL;
|
||||
mbedtls_aes_xts_context ctx;
|
||||
int key_len, data_len;
|
||||
size_t key_len, src_len, dst_len, data_unit_len;
|
||||
|
||||
mbedtls_aes_xts_init( &ctx );
|
||||
|
||||
key_len = unhexify( key_str, hex_key_string );
|
||||
unhexify( data_unit_str, hex_data_unit_string );
|
||||
data_len = unhexify( src_str, hex_src_string );
|
||||
TEST_ASSERT( data_len == data_unit_len / 8 );
|
||||
data_unit = unhexify_alloc( hex_data_unit_string, &data_unit_len );
|
||||
TEST_ASSERT( data_unit_len == AES_BLOCK_SIZE );
|
||||
|
||||
mbedtls_aes_xts_setkey_enc( &ctx, key_str, key_len * 8 );
|
||||
key = unhexify_alloc( hex_key_string, &key_len );
|
||||
TEST_ASSERT( key_len % 2 == 0 );
|
||||
|
||||
TEST_ASSERT( mbedtls_aes_crypt_xts( &ctx, MBEDTLS_AES_ENCRYPT, data_len, data_unit_str, src_str, output ) == xts_result );
|
||||
if( xts_result == 0 )
|
||||
{
|
||||
hexify( dst_str, output, data_len );
|
||||
src = unhexify_alloc( hex_src_string, &src_len );
|
||||
dst = unhexify_alloc( hex_dst_string, &dst_len );
|
||||
TEST_ASSERT( src_len == dst_len );
|
||||
|
||||
TEST_ASSERT( strcmp( (char *) dst_str, hex_dst_string ) == 0 );
|
||||
}
|
||||
output = zero_alloc( dst_len );
|
||||
|
||||
TEST_ASSERT( mbedtls_aes_xts_setkey_enc( &ctx, key, key_len * 8 ) == 0 );
|
||||
TEST_ASSERT( mbedtls_aes_crypt_xts( &ctx, MBEDTLS_AES_ENCRYPT, src_len,
|
||||
data_unit, src, output ) == 0 );
|
||||
|
||||
TEST_ASSERT( memcmp( output, dst, dst_len ) == 0 );
|
||||
|
||||
exit:
|
||||
mbedtls_aes_xts_free( &ctx );
|
||||
mbedtls_free( data_unit );
|
||||
mbedtls_free( key );
|
||||
mbedtls_free( src );
|
||||
mbedtls_free( dst );
|
||||
mbedtls_free( output );
|
||||
}
|
||||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_XTS */
|
||||
void aes_decrypt_xts( char *hex_key_string, char *hex_data_unit_string,
|
||||
char *hex_src_string, char *hex_dst_string,
|
||||
int data_unit_len, int xts_result )
|
||||
char *hex_dst_string, char *hex_src_string )
|
||||
{
|
||||
unsigned char key_str[100] = { 0, };
|
||||
unsigned char data_unit_str[100] = { 0, };
|
||||
unsigned char src_str[100] = { 0, };
|
||||
unsigned char dst_str[100] = { 0, };
|
||||
unsigned char output[100] = { 0, };
|
||||
enum { AES_BLOCK_SIZE = 16 };
|
||||
unsigned char *data_unit = NULL;
|
||||
unsigned char *key = NULL;
|
||||
unsigned char *src = NULL;
|
||||
unsigned char *dst = NULL;
|
||||
unsigned char *output = NULL;
|
||||
mbedtls_aes_xts_context ctx;
|
||||
int key_len, data_len;
|
||||
size_t key_len, src_len, dst_len, data_unit_len;
|
||||
|
||||
mbedtls_aes_xts_init( &ctx );
|
||||
|
||||
key_len = unhexify( key_str, hex_key_string );
|
||||
unhexify( data_unit_str, hex_data_unit_string );
|
||||
data_len = unhexify( src_str, hex_src_string );
|
||||
TEST_ASSERT( data_len == data_unit_len / 8 );
|
||||
data_unit = unhexify_alloc( hex_data_unit_string, &data_unit_len );
|
||||
TEST_ASSERT( data_unit_len == AES_BLOCK_SIZE );
|
||||
|
||||
mbedtls_aes_xts_setkey_dec( &ctx, key_str, key_len * 8 );
|
||||
key = unhexify_alloc( hex_key_string, &key_len );
|
||||
TEST_ASSERT( key_len % 2 == 0 );
|
||||
|
||||
TEST_ASSERT( mbedtls_aes_crypt_xts( &ctx, MBEDTLS_AES_DECRYPT, data_len, data_unit_str, src_str, output ) == xts_result );
|
||||
if( xts_result == 0 )
|
||||
{
|
||||
hexify( dst_str, output, data_len );
|
||||
src = unhexify_alloc( hex_src_string, &src_len );
|
||||
dst = unhexify_alloc( hex_dst_string, &dst_len );
|
||||
TEST_ASSERT( src_len == dst_len );
|
||||
|
||||
TEST_ASSERT( strcmp( (char *) dst_str, hex_dst_string ) == 0 );
|
||||
}
|
||||
output = zero_alloc( dst_len );
|
||||
|
||||
TEST_ASSERT( mbedtls_aes_xts_setkey_dec( &ctx, key, key_len * 8 ) == 0 );
|
||||
TEST_ASSERT( mbedtls_aes_crypt_xts( &ctx, MBEDTLS_AES_DECRYPT, src_len,
|
||||
data_unit, src, output ) == 0 );
|
||||
|
||||
TEST_ASSERT( memcmp( output, dst, dst_len ) == 0 );
|
||||
|
||||
exit:
|
||||
mbedtls_aes_xts_free( &ctx );
|
||||
mbedtls_free( data_unit );
|
||||
mbedtls_free( key );
|
||||
mbedtls_free( src );
|
||||
mbedtls_free( dst );
|
||||
mbedtls_free( output );
|
||||
}
|
||||
/* END_CASE */
|
||||
|
||||
|
|
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue