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
This commit is contained in:
Azim Khan 2017-05-31 20:46:35 +01:00 committed by Mohammad Azim Khan
parent 5e7f8df800
commit 46c9b1f196
18 changed files with 795 additions and 790 deletions

View file

@ -125,9 +125,12 @@ void mbedtls_ccm_encrypt_and_tag( int cipher_id, uint8_t * key,
{
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 @@ void mbedtls_ccm_encrypt_and_tag( int cipher_id, uint8_t * key,
/* 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 @@ void mbedtls_ccm_auth_decrypt( int cipher_id, uint8_t * key, uint32_t key_len,
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 @@ void mbedtls_ccm_auth_decrypt( int cipher_id, uint8_t * key, uint32_t key_len,
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 @@ void mbedtls_ccm_auth_decrypt( int cipher_id, uint8_t * key, uint32_t key_len,
if( ret == 0 )
{
TEST_ASSERT( memcmp( msg, result, result_len ) == 0 );
TEST_ASSERT( memcmp( msg, hex_msg, hex_msg_len ) == 0 );
}
else
{