tests: aes.ofb: Prepare to char* to data_t* type change

In preparation of changing the type of some parameters
of aes_encrypt_ofb() from `char *` to `data_t` to get rid
of the calls to mbedtls_test_unhexify():

- Change the name of parameters and local variables to
  clarify which ones are related to the outputs of the
  library functions under test and which ones are
  related to the expected values of those outputs.

- Add assertion on fragment_size parameter

Signed-off-by: Ronald Cron <ronald.cron@arm.com>
This commit is contained in:
Ronald Cron 2020-06-25 13:57:05 +02:00
Родитель 7370185ae3
Коммит df02eb00e0
1 изменённых файлов: 8 добавлений и 7 удалений

Просмотреть файл

@ -329,13 +329,13 @@ exit:
/* 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_dst_string )
char *hex_expected_output_string )
{
unsigned char key_str[32];
unsigned char iv_str[16];
unsigned char src_str[64];
unsigned char dst_str[64];
unsigned char output[32];
unsigned char output_string[65];
mbedtls_aes_context ctx;
size_t iv_offset = 0;
int in_buffer_len;
@ -345,14 +345,15 @@ void aes_encrypt_ofb( int fragment_size, char *hex_key_string,
memset( key_str, 0x00, sizeof( key_str ) );
memset( iv_str, 0x00, sizeof( iv_str ) );
memset( src_str, 0x00, sizeof( src_str ) );
memset( dst_str, 0x00, sizeof( dst_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_dst_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 );
@ -366,12 +367,12 @@ void aes_encrypt_ofb( int fragment_size, char *hex_key_string,
TEST_ASSERT( mbedtls_aes_crypt_ofb( &ctx, fragment_size, &iv_offset,
iv_str, src_str_next, output ) == 0 );
mbedtls_test_hexify( dst_str, output, fragment_size );
TEST_ASSERT( strncmp( (char *) dst_str, hex_dst_string,
mbedtls_test_hexify( output_string, output, fragment_size );
TEST_ASSERT( strncmp( (char *) output_string, hex_expected_output_string,
( 2 * fragment_size ) ) == 0 );
in_buffer_len -= fragment_size;
hex_dst_string += ( fragment_size * 2 );
hex_expected_output_string += ( fragment_size * 2 );
src_str_next += fragment_size;
if( in_buffer_len < fragment_size )