Fix test functions and data after moving hexify/unhexify out
- Separate string and hex parameter as unhexify is moved out of the function. It's input should only be hex.
- Fix test mbedtls_ccm_encrypt_and_tag that grows input message buffer with tag
- Add missing expected length parameter in ECP TLS tests
- Add deleted TEST_ASSERT and mbedtls calls that got removed in script based code generation
diff --git a/tests/suites/test_suite_ccm.function b/tests/suites/test_suite_ccm.function
index c845f44..5dbc837 100644
--- a/tests/suites/test_suite_ccm.function
+++ b/tests/suites/test_suite_ccm.function
@@ -125,9 +125,12 @@
{
mbedtls_ccm_context ctx;
size_t tag_len;
+ uint8_t * msg_n_tag = (uint8_t *)malloc( result_len + 2 );
mbedtls_ccm_init( &ctx );
+ memset( msg_n_tag, 0, result_len + 2 );
+ memcpy( msg_n_tag, msg, msg_len );
tag_len = result_len - msg_len;
@@ -135,15 +138,16 @@
/* Test with input == output */
TEST_ASSERT( mbedtls_ccm_encrypt_and_tag( &ctx, msg_len, iv, iv_len, add, add_len,
- msg, msg, msg + msg_len, tag_len ) == 0 );
+ msg_n_tag, msg_n_tag, msg_n_tag + msg_len, tag_len ) == 0 );
- TEST_ASSERT( memcmp( msg, result, result_len ) == 0 );
+ TEST_ASSERT( memcmp( msg_n_tag, result, result_len ) == 0 );
/* Check we didn't write past the end */
- TEST_ASSERT( msg[result_len] == 0 && msg[result_len + 1] == 0 );
+ TEST_ASSERT( msg_n_tag[result_len] == 0 && msg_n_tag[result_len + 1] == 0 );
exit:
mbedtls_ccm_free( &ctx );
+ free( msg_n_tag );
}
/* END_CASE */
@@ -152,7 +156,8 @@
uint8_t * msg, uint32_t msg_len, uint8_t * iv,
uint32_t iv_len, uint8_t * add,
uint32_t add_len, int tag_len,
- uint8_t * result, uint32_t result_len )
+ char * result, uint8_t * hex_msg,
+ uint32_t hex_msg_len )
{
unsigned char tag[16];
mbedtls_ccm_context ctx;
@@ -165,10 +170,9 @@
msg_len -= tag_len;
memcpy( tag, msg + msg_len, tag_len );
- if( strcmp( "FAIL", (char *)result ) == 0 )
+ if( strcmp( "FAIL", result ) == 0 )
{
ret = MBEDTLS_ERR_CCM_AUTH_FAILED;
- result_len = -1;
}
else
{
@@ -183,7 +187,7 @@
if( ret == 0 )
{
- TEST_ASSERT( memcmp( msg, result, result_len ) == 0 );
+ TEST_ASSERT( memcmp( msg, hex_msg, hex_msg_len ) == 0 );
}
else
{