tests: Replace "TEST_ASSERT(!memcmp ...)" by ASSERT_COMPARE

The usage of "!memcmp()" is at least not recommended
and better to use the macro dedicated for buffer
comparisons.

Signed-off-by: Ronald Cron <ronald.cron@arm.com>
This commit is contained in:
Ronald Cron 2020-07-30 14:18:02 +02:00
parent a123614699
commit d8902b6e3d
4 changed files with 34 additions and 26 deletions

View file

@ -226,8 +226,8 @@ void aria_encrypt_ecb( data_t *key_str, data_t *src_str,
output + i ) == 0 ); output + i ) == 0 );
} }
TEST_ASSERT( !memcmp( output, ASSERT_COMPARE( output, expected_output->len,
expected_output->x, expected_output->len) ); expected_output->x, expected_output->len );
} }
exit: exit:
@ -256,8 +256,8 @@ void aria_decrypt_ecb( data_t *key_str, data_t *src_str,
output + i ) == 0 ); output + i ) == 0 );
} }
TEST_ASSERT( !memcmp( output, ASSERT_COMPARE( output, expected_output->len,
expected_output->x, expected_output->len) ); expected_output->x, expected_output->len );
} }
exit: exit:
@ -282,8 +282,8 @@ void aria_encrypt_cbc( data_t *key_str, data_t *iv_str,
output ) == cbc_result ); output ) == cbc_result );
if( cbc_result == 0 ) if( cbc_result == 0 )
{ {
TEST_ASSERT( !memcmp( output, ASSERT_COMPARE( output, expected_output->len,
expected_output->x, expected_output->len) ); expected_output->x, expected_output->len );
} }
exit: exit:
@ -308,8 +308,8 @@ void aria_decrypt_cbc( data_t *key_str, data_t *iv_str,
output ) == cbc_result ); output ) == cbc_result );
if( cbc_result == 0 ) if( cbc_result == 0 )
{ {
TEST_ASSERT( !memcmp( output, ASSERT_COMPARE( output, expected_output->len,
expected_output->x, expected_output->len) ); expected_output->x, expected_output->len );
} }
exit: exit:
@ -335,7 +335,8 @@ void aria_encrypt_cfb128( data_t *key_str, data_t *iv_str,
iv_str->x, src_str->x, output ) iv_str->x, src_str->x, output )
== result ); == result );
TEST_ASSERT( !memcmp( output, expected_output->x, expected_output->len) ); ASSERT_COMPARE( output, expected_output->len,
expected_output->x, expected_output->len );
exit: exit:
mbedtls_aria_free( &ctx ); mbedtls_aria_free( &ctx );
@ -360,7 +361,8 @@ void aria_decrypt_cfb128( data_t *key_str, data_t *iv_str,
iv_str->x, src_str->x, output ) iv_str->x, src_str->x, output )
== result ); == result );
TEST_ASSERT( !memcmp( output, expected_output->x, expected_output->len) ); ASSERT_COMPARE( output, expected_output->len,
expected_output->x, expected_output->len );
exit: exit:
mbedtls_aria_free( &ctx ); mbedtls_aria_free( &ctx );
@ -385,7 +387,8 @@ void aria_encrypt_ctr( data_t *key_str, data_t *iv_str,
iv_str->x, blk, src_str->x, output ) iv_str->x, blk, src_str->x, output )
== result ); == result );
TEST_ASSERT( !memcmp( output, expected_output->x, expected_output->len) ); ASSERT_COMPARE( output, expected_output->len,
expected_output->x, expected_output->len );
exit: exit:
mbedtls_aria_free( &ctx ); mbedtls_aria_free( &ctx );
@ -410,7 +413,8 @@ void aria_decrypt_ctr( data_t *key_str, data_t *iv_str,
iv_str->x, blk, src_str->x, output ) iv_str->x, blk, src_str->x, output )
== result ); == result );
TEST_ASSERT( !memcmp( output, expected_output->x, expected_output->len) ); ASSERT_COMPARE( output, expected_output->len,
expected_output->x, expected_output->len );
exit: exit:
mbedtls_aria_free( &ctx ); mbedtls_aria_free( &ctx );

View file

@ -28,8 +28,8 @@ void chacha20_crypt( data_t *key_str,
*/ */
TEST_ASSERT( mbedtls_chacha20_crypt( key_str->x, nonce_str->x, counter, src_str->len, src_str->x, output ) == 0 ); TEST_ASSERT( mbedtls_chacha20_crypt( key_str->x, nonce_str->x, counter, src_str->len, src_str->x, output ) == 0 );
TEST_ASSERT( !memcmp( output, expected_output_str->x, ASSERT_COMPARE( output, expected_output_str->len,
expected_output_str->len ) ); expected_output_str->x, expected_output_str->len );
/* /*
* Test the streaming API * Test the streaming API
@ -43,8 +43,8 @@ void chacha20_crypt( data_t *key_str,
memset( output, 0x00, sizeof( output ) ); memset( output, 0x00, sizeof( output ) );
TEST_ASSERT( mbedtls_chacha20_update( &ctx, src_str->len, src_str->x, output ) == 0 ); TEST_ASSERT( mbedtls_chacha20_update( &ctx, src_str->len, src_str->x, output ) == 0 );
TEST_ASSERT( !memcmp( output, expected_output_str->x, ASSERT_COMPARE( output, expected_output_str->len,
expected_output_str->len ) ); expected_output_str->x, expected_output_str->len );
/* /*
* Test the streaming API again, piecewise * Test the streaming API again, piecewise
@ -59,8 +59,8 @@ void chacha20_crypt( data_t *key_str,
TEST_ASSERT( mbedtls_chacha20_update( &ctx, src_str->len - 1, TEST_ASSERT( mbedtls_chacha20_update( &ctx, src_str->len - 1,
src_str->x + 1, output + 1 ) == 0 ); src_str->x + 1, output + 1 ) == 0 );
TEST_ASSERT( !memcmp( output, expected_output_str->x, ASSERT_COMPARE( output, expected_output_str->len,
expected_output_str->len ) ); expected_output_str->x, expected_output_str->len );
mbedtls_chacha20_free( &ctx ); mbedtls_chacha20_free( &ctx );
} }

View file

@ -24,7 +24,8 @@ void test_hkdf( int md_alg, data_t *ikm, data_t *salt, data_t *info,
info->x, info->len, okm, expected_okm->len ); info->x, info->len, okm, expected_okm->len );
TEST_ASSERT( ret == 0 ); TEST_ASSERT( ret == 0 );
TEST_ASSERT( !memcmp( okm, expected_okm->x, expected_okm->len ) ); ASSERT_COMPARE( okm , expected_okm->len,
expected_okm->x, expected_okm->len );
} }
/* END_CASE */ /* END_CASE */
@ -48,12 +49,11 @@ void test_hkdf_extract( int md_alg, char *hex_ikm_string,
ikm = mbedtls_test_unhexify_alloc( hex_ikm_string, &ikm_len ); ikm = mbedtls_test_unhexify_alloc( hex_ikm_string, &ikm_len );
salt = mbedtls_test_unhexify_alloc( hex_salt_string, &salt_len ); salt = mbedtls_test_unhexify_alloc( hex_salt_string, &salt_len );
prk = mbedtls_test_unhexify_alloc( hex_prk_string, &prk_len ); prk = mbedtls_test_unhexify_alloc( hex_prk_string, &prk_len );
TEST_ASSERT( prk_len == output_prk_len );
ret = mbedtls_hkdf_extract( md, salt, salt_len, ikm, ikm_len, output_prk ); ret = mbedtls_hkdf_extract( md, salt, salt_len, ikm, ikm_len, output_prk );
TEST_ASSERT( ret == 0 ); TEST_ASSERT( ret == 0 );
TEST_ASSERT( !memcmp( output_prk, prk, prk_len ) ); ASSERT_COMPARE( output_prk, output_prk_len, prk, prk_len );
exit: exit:
mbedtls_free(ikm); mbedtls_free(ikm);
@ -89,7 +89,7 @@ void test_hkdf_expand( int md_alg, char *hex_info_string,
ret = mbedtls_hkdf_expand( md, prk, prk_len, info, info_len, ret = mbedtls_hkdf_expand( md, prk, prk_len, info, info_len,
output_okm, OKM_LEN ); output_okm, OKM_LEN );
TEST_ASSERT( ret == 0 ); TEST_ASSERT( ret == 0 );
TEST_ASSERT( !memcmp( output_okm, okm, okm_len ) ); ASSERT_COMPARE( output_okm, okm_len, okm, okm_len );
exit: exit:
mbedtls_free(info); mbedtls_free(info);

View file

@ -22,7 +22,8 @@ void mbedtls_poly1305( data_t *key, data_t *expected_mac, data_t *src_str )
TEST_ASSERT( mbedtls_poly1305_mac( key->x, src_str->x, TEST_ASSERT( mbedtls_poly1305_mac( key->x, src_str->x,
src_str->len, mac ) == 0 ); src_str->len, mac ) == 0 );
TEST_ASSERT( !memcmp( mac, expected_mac->x, expected_mac->len ) ); ASSERT_COMPARE( mac, expected_mac->len,
expected_mac->x, expected_mac->len );
/* /*
* Test the streaming API * Test the streaming API
@ -35,7 +36,8 @@ void mbedtls_poly1305( data_t *key, data_t *expected_mac, data_t *src_str )
TEST_ASSERT( mbedtls_poly1305_finish( &ctx, mac ) == 0 ); TEST_ASSERT( mbedtls_poly1305_finish( &ctx, mac ) == 0 );
TEST_ASSERT( !memcmp( mac, expected_mac->x, expected_mac->len ) ); ASSERT_COMPARE( mac, expected_mac->len,
expected_mac->x, expected_mac->len );
/* /*
* Test the streaming API again, piecewise * Test the streaming API again, piecewise
@ -52,7 +54,8 @@ void mbedtls_poly1305( data_t *key, data_t *expected_mac, data_t *src_str )
TEST_ASSERT( mbedtls_poly1305_finish( &ctx, mac ) == 0 ); TEST_ASSERT( mbedtls_poly1305_finish( &ctx, mac ) == 0 );
TEST_ASSERT( !memcmp( mac, expected_mac->x, expected_mac->len ) ); ASSERT_COMPARE( mac, expected_mac->len,
expected_mac->x, expected_mac->len );
} }
/* /*
@ -68,7 +71,8 @@ void mbedtls_poly1305( data_t *key, data_t *expected_mac, data_t *src_str )
TEST_ASSERT( mbedtls_poly1305_finish( &ctx, mac ) == 0 ); TEST_ASSERT( mbedtls_poly1305_finish( &ctx, mac ) == 0 );
TEST_ASSERT( !memcmp( mac, expected_mac->x, expected_mac->len ) ); ASSERT_COMPARE( mac, expected_mac->len,
expected_mac->x, expected_mac->len );
} }
mbedtls_poly1305_free( &ctx ); mbedtls_poly1305_free( &ctx );