tests: Get rid of mbedtls_test_unhexify() in unit test code

In test functions calling mbedtls_test_unhexify(), change the
type of the associated parameters from `char*` to `data_t`.

That way the `unhexify` operation is done by the test
framework and not by the unit test code.

Use for the new parameters of type data_t the name of the
local variable that used to store the `unhexify` version of
the `char*` parameter.

Signed-off-by: Ronald Cron <ronald.cron@arm.com>
This commit is contained in:
Ronald Cron 2020-06-25 09:03:34 +02:00
parent 1d5ef2919b
commit 14a5645cbf
12 changed files with 239 additions and 498 deletions

View file

@ -313,52 +313,39 @@ exit:
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_OFB */
void aes_encrypt_ofb( int fragment_size, char *hex_key_string,
char *hex_iv_string, char *hex_src_string,
char *hex_expected_output_string )
void aes_encrypt_ofb( int fragment_size, data_t *key_str,
data_t *iv_str, data_t *src_str,
char *expected_output_string)
{
unsigned char key_str[32];
unsigned char iv_str[16];
unsigned char src_str[64];
unsigned char output[32];
unsigned char output_string[65];
mbedtls_aes_context ctx;
size_t iv_offset = 0;
int in_buffer_len;
unsigned char* src_str_next;
int key_len;
memset( key_str, 0x00, sizeof( key_str ) );
memset( iv_str, 0x00, sizeof( iv_str ) );
memset( src_str, 0x00, sizeof( src_str ) );
memset( output, 0x00, sizeof( output ) );
memset( output_string, 0x00, sizeof( output_string ) );
mbedtls_aes_init( &ctx );
TEST_ASSERT( (size_t)fragment_size < sizeof( output ) );
TEST_ASSERT( strlen( hex_key_string ) <= ( 32 * 2 ) );
TEST_ASSERT( strlen( hex_iv_string ) <= ( 16 * 2 ) );
TEST_ASSERT( strlen( hex_src_string ) <= ( 64 * 2 ) );
TEST_ASSERT( strlen( hex_expected_output_string ) <= ( 64 * 2 ) );
key_len = mbedtls_test_unhexify( key_str, hex_key_string );
mbedtls_test_unhexify( iv_str, hex_iv_string );
in_buffer_len = mbedtls_test_unhexify( src_str, hex_src_string );
TEST_ASSERT( mbedtls_aes_setkey_enc( &ctx, key_str, key_len * 8 ) == 0 );
src_str_next = src_str;
TEST_ASSERT( mbedtls_aes_setkey_enc( &ctx, key_str->x,
key_str->len * 8 ) == 0 );
in_buffer_len = src_str->len;
src_str_next = src_str->x;
while( in_buffer_len > 0 )
{
TEST_ASSERT( mbedtls_aes_crypt_ofb( &ctx, fragment_size, &iv_offset,
iv_str, src_str_next, output ) == 0 );
iv_str->x, src_str_next, output ) == 0 );
mbedtls_test_hexify( output_string, output, fragment_size );
TEST_ASSERT( strncmp( (char *) output_string, hex_expected_output_string,
TEST_ASSERT( strncmp( (char *) output_string, expected_output_string,
( 2 * fragment_size ) ) == 0 );
in_buffer_len -= fragment_size;
hex_expected_output_string += ( fragment_size * 2 );
expected_output_string += ( fragment_size * 2 );
src_str_next += fragment_size;
if( in_buffer_len < fragment_size )