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>
diff --git a/tests/suites/test_suite_nist_kw.function b/tests/suites/test_suite_nist_kw.function
index 15370b2..6a81052 100644
--- a/tests/suites/test_suite_nist_kw.function
+++ b/tests/suites/test_suite_nist_kw.function
@@ -242,42 +242,31 @@
/* END_CASE */
/* BEGIN_CASE */
-void mbedtls_nist_kw_wrap( int cipher_id, int mode,
- char *key_hex, char *msg_hex,
- char *expected_result_hex )
+void mbedtls_nist_kw_wrap( int cipher_id, int mode, data_t *key, data_t *msg,
+ data_t *expected_result )
{
- 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, result_len, expected_result_len, i, padlen;
+ size_t result_len, i, padlen;
mbedtls_nist_kw_init( &ctx );
- memset( key, 0x00, sizeof( key ) );
- memset( msg, 0x00, sizeof( msg ) );
memset( result, '+', sizeof( result ) );
- key_len = mbedtls_test_unhexify( key, key_hex );
- msg_len = mbedtls_test_unhexify( msg, msg_hex );
- 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_ASSERT( mbedtls_nist_kw_setkey( &ctx, cipher_id,
+ key->x, key->len * 8, 1 ) == 0 );
/* Test with input == output */
- TEST_ASSERT( mbedtls_nist_kw_wrap( &ctx, mode, msg, msg_len,
+ TEST_ASSERT( mbedtls_nist_kw_wrap( &ctx, mode, msg->x, msg->len,
result, &result_len, sizeof( result ) ) == 0 );
- TEST_ASSERT( result_len == expected_result_len );
+ TEST_ASSERT( result_len == expected_result->len );
- TEST_ASSERT( memcmp( expected_result, result, expected_result_len ) == 0 );
+ TEST_ASSERT( memcmp( expected_result->x, result, result_len ) == 0 );
- padlen = ( msg_len % 8 != 0 ) ? 8 - (msg_len % 8 ) : 0;
+ padlen = ( msg->len % 8 != 0 ) ? 8 - (msg->len % 8 ) : 0;
/* Check that the function didn't write beyond the end of the buffer. */
- for( i = msg_len + 8 + padlen; i < sizeof( result ); i++ )
+ for( i = msg->len + 8 + padlen; i < sizeof( result ); i++ )
{
TEST_ASSERT( result[i] == '+' );
}
@@ -288,39 +277,27 @@
/* END_CASE */
/* BEGIN_CASE */
-void mbedtls_nist_kw_unwrap( int cipher_id, int mode,
- char *key_hex, char *msg_hex,
- char *expected_result_hex, int expected_ret )
+void mbedtls_nist_kw_unwrap( int cipher_id, int mode, data_t *key, data_t *msg,
+ data_t *expected_result, 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, result_len, expected_result_len, i;
+ size_t result_len, i;
mbedtls_nist_kw_init( &ctx );
- memset( key, 0x00, sizeof( key ) );
- memset( msg, 0x00, sizeof( msg ) );
memset( result, '+', sizeof( result ) );
- memset( expected_result, 0x00, sizeof( expected_result ) );
- key_len = mbedtls_test_unhexify( key, key_hex );
- msg_len = mbedtls_test_unhexify( msg, msg_hex );
- 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_ASSERT( mbedtls_nist_kw_setkey( &ctx, cipher_id,
+ key->x, key->len * 8, 0 ) == 0 );
/* Test with input == output */
- TEST_ASSERT( mbedtls_nist_kw_unwrap( &ctx, mode, msg, msg_len,
+ TEST_ASSERT( mbedtls_nist_kw_unwrap( &ctx, mode, msg->x, msg->len,
result, &result_len, sizeof( result ) ) == expected_ret );
if( expected_ret == 0 )
{
- TEST_ASSERT( result_len == expected_result_len );
- TEST_ASSERT( memcmp( expected_result, result, expected_result_len ) == 0 );
+ TEST_ASSERT( result_len == expected_result->len );
+ TEST_ASSERT( memcmp( expected_result->x, result, result_len ) == 0 );
}
else
{
@@ -328,7 +305,7 @@
}
/* Check that the function didn't write beyond the end of the buffer. */
- for( i = msg_len - 8; i < sizeof( result ); i++ )
+ for( i = msg->len - 8; i < sizeof( result ); i++ )
{
TEST_ASSERT( result[i] == '+' );
}