tests: nist_kw: Prepare to char* to data_t* type change

In preparation of changing the type of some parameters
of mbedtls_nist_kw_wrap/unwrap() 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.

Signed-off-by: Ronald Cron <ronald.cron@arm.com>
This commit is contained in:
Ronald Cron 2020-06-25 13:33:29 +02:00
parent 7e8f1af0a6
commit afbe3ee87c

View file

@ -244,14 +244,14 @@ exit:
/* BEGIN_CASE */
void mbedtls_nist_kw_wrap( int cipher_id, int mode,
char *key_hex, char *msg_hex,
char *result_hex )
char *expected_result_hex )
{
unsigned char key[32];
unsigned char msg[512];
unsigned char result[528];
unsigned char expected_result[528];
mbedtls_nist_kw_context ctx;
size_t key_len, msg_len, output_len, result_len, i, padlen;
size_t key_len, msg_len, result_len, expected_result_len, i, padlen;
mbedtls_nist_kw_init( &ctx );
@ -261,19 +261,19 @@ void mbedtls_nist_kw_wrap( int cipher_id, int mode,
key_len = mbedtls_test_unhexify( key, key_hex );
msg_len = mbedtls_test_unhexify( msg, msg_hex );
result_len = mbedtls_test_unhexify( expected_result, result_hex );
output_len = sizeof( result );
expected_result_len = mbedtls_test_unhexify( expected_result, expected_result_hex );
result_len = sizeof( result );
TEST_ASSERT( mbedtls_nist_kw_setkey( &ctx, cipher_id, key, key_len * 8, 1 )
== 0 );
/* Test with input == output */
TEST_ASSERT( mbedtls_nist_kw_wrap( &ctx, mode, msg, msg_len,
result, &output_len, sizeof( result ) ) == 0 );
result, &result_len, sizeof( result ) ) == 0 );
TEST_ASSERT( output_len == result_len );
TEST_ASSERT( result_len == expected_result_len );
TEST_ASSERT( memcmp( expected_result, result, result_len ) == 0 );
TEST_ASSERT( memcmp( expected_result, result, expected_result_len ) == 0 );
padlen = ( msg_len % 8 != 0 ) ? 8 - (msg_len % 8 ) : 0;
/* Check that the function didn't write beyond the end of the buffer. */
@ -290,14 +290,14 @@ exit:
/* BEGIN_CASE */
void mbedtls_nist_kw_unwrap( int cipher_id, int mode,
char *key_hex, char *msg_hex,
char *result_hex, int expected_ret )
char *expected_result_hex, int expected_ret )
{
unsigned char key[32];
unsigned char msg[528];
unsigned char result[528];
unsigned char expected_result[528];
mbedtls_nist_kw_context ctx;
size_t key_len, msg_len, output_len, result_len, i;
size_t key_len, msg_len, result_len, expected_result_len, i;
mbedtls_nist_kw_init( &ctx );
@ -308,23 +308,23 @@ void mbedtls_nist_kw_unwrap( int cipher_id, int mode,
key_len = mbedtls_test_unhexify( key, key_hex );
msg_len = mbedtls_test_unhexify( msg, msg_hex );
result_len = mbedtls_test_unhexify( expected_result, result_hex );
output_len = sizeof( result );
expected_result_len = mbedtls_test_unhexify( expected_result, expected_result_hex );
result_len = sizeof( result );
TEST_ASSERT( mbedtls_nist_kw_setkey( &ctx, cipher_id, key, key_len * 8, 0 )
== 0 );
/* Test with input == output */
TEST_ASSERT( mbedtls_nist_kw_unwrap( &ctx, mode, msg, msg_len,
result, &output_len, sizeof( result ) ) == expected_ret );
result, &result_len, sizeof( result ) ) == expected_ret );
if( expected_ret == 0 )
{
TEST_ASSERT( output_len == result_len );
TEST_ASSERT( memcmp( expected_result, result, result_len ) == 0 );
TEST_ASSERT( result_len == expected_result_len );
TEST_ASSERT( memcmp( expected_result, result, expected_result_len ) == 0 );
}
else
{
TEST_ASSERT( output_len == 0 );
TEST_ASSERT( result_len == 0 );
}
/* Check that the function didn't write beyond the end of the buffer. */