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

@ -9,43 +9,36 @@
*/
/* BEGIN_CASE */
void test_hkdf( int md_alg, char *hex_ikm_string, char *hex_salt_string,
char *hex_info_string, char *hex_expected_okm_string )
void test_hkdf( int md_alg, data_t *ikm, data_t *salt, data_t *info,
data_t *expected_okm )
{
int ret;
size_t ikm_len, salt_len, info_len, expected_okm_len;
unsigned char ikm[128] = { '\0' };
unsigned char salt[128] = { '\0' };
unsigned char info[128] = { '\0' };
unsigned char expected_okm[128] = { '\0' };
unsigned char okm[128] = { '\0' };
/*
* okm_string is the ASCII string representation of okm,
* so its size is twice the size of okm, and an extra null-termination.
* okm_string and expected_okm_string are the ASCII string representations
* of km and expected_okm, so their size should be twice the size of
* okm and expected_okm, and an extra null-termination.
*/
unsigned char okm_string[257] = { '\0' };
unsigned char expected_okm_string[257] = { '\0' };
const mbedtls_md_info_t *md = mbedtls_md_info_from_type( md_alg );
TEST_ASSERT( md != NULL );
ikm_len = mbedtls_test_unhexify( ikm, hex_ikm_string );
salt_len = mbedtls_test_unhexify( salt, hex_salt_string );
info_len = mbedtls_test_unhexify( info, hex_info_string );
expected_okm_len = mbedtls_test_unhexify( expected_okm,
hex_expected_okm_string );
TEST_ASSERT( expected_okm->len <= sizeof( okm ) );
TEST_ASSERT( expected_okm_len <= sizeof( okm ) );
ret = mbedtls_hkdf( md, salt, salt_len, ikm, ikm_len, info, info_len, okm,
expected_okm_len);
ret = mbedtls_hkdf( md, salt->x, salt->len, ikm->x, ikm->len,
info->x, info->len, okm, expected_okm->len );
TEST_ASSERT( ret == 0 );
/*
* Run mbedtls_test_hexify on it so that it looks nicer if the assertion
* fails.
* Run mbedtls_test_hexify on okm and expected_okm so that it looks nicer
* if the assertion fails.
*/
mbedtls_test_hexify( okm_string, okm, expected_okm_len );
TEST_ASSERT( !strcmp( (char *)okm_string, hex_expected_okm_string ) );
mbedtls_test_hexify( okm_string, okm, expected_okm->len );
mbedtls_test_hexify( expected_okm_string,
expected_okm->x, expected_okm->len );
TEST_ASSERT( !strcmp( (char *)okm_string, (char *)expected_okm_string ) );
}
/* END_CASE */