Fix memory allocation in ccm tests
The ccm tests were previously relying on unspecified behaviour in the underlying implementation (i.e. that it rejects certain buffer sizes without reading the buffer). Signed-off-by: Dave Rodgman <dave.rodgman@arm.com>
This commit is contained in:
parent
8f24a8bb34
commit
2e680348ad
3 changed files with 7 additions and 2 deletions
|
@ -121,6 +121,7 @@ typedef struct data_tag
|
||||||
TEST_ASSERT( ( expr1 ) == ( expr2 ) )
|
TEST_ASSERT( ( expr1 ) == ( expr2 ) )
|
||||||
|
|
||||||
/** Allocate memory dynamically and fail the test case if this fails.
|
/** Allocate memory dynamically and fail the test case if this fails.
|
||||||
|
* The allocated memory will be filled with zeros.
|
||||||
*
|
*
|
||||||
* You must set \p pointer to \c NULL before calling this macro and
|
* You must set \p pointer to \c NULL before calling this macro and
|
||||||
* put `mbedtls_free( pointer )` in the test's cleanup code.
|
* put `mbedtls_free( pointer )` in the test's cleanup code.
|
||||||
|
|
|
@ -51,6 +51,9 @@ ccm_lengths:65536:13:5:8:MBEDTLS_ERR_CCM_BAD_INPUT
|
||||||
CCM lengths #9 tag length 0
|
CCM lengths #9 tag length 0
|
||||||
ccm_lengths:5:10:5:0:MBEDTLS_ERR_CCM_BAD_INPUT
|
ccm_lengths:5:10:5:0:MBEDTLS_ERR_CCM_BAD_INPUT
|
||||||
|
|
||||||
|
CCM lengths #10 Large AD
|
||||||
|
ccm_lengths:5:10:32768:8:0
|
||||||
|
|
||||||
CCM* fixed tag lengths #1 all OK
|
CCM* fixed tag lengths #1 all OK
|
||||||
ccm_star_lengths:5:10:5:8:0
|
ccm_star_lengths:5:10:5:8:0
|
||||||
|
|
||||||
|
|
|
@ -41,17 +41,17 @@ void ccm_lengths( int msg_len, int iv_len, int add_len, int tag_len, int res )
|
||||||
unsigned char key[16];
|
unsigned char key[16];
|
||||||
unsigned char msg[10];
|
unsigned char msg[10];
|
||||||
unsigned char iv[14];
|
unsigned char iv[14];
|
||||||
unsigned char add[10];
|
unsigned char *add = NULL;
|
||||||
unsigned char out[10];
|
unsigned char out[10];
|
||||||
unsigned char tag[18];
|
unsigned char tag[18];
|
||||||
int decrypt_ret;
|
int decrypt_ret;
|
||||||
|
|
||||||
mbedtls_ccm_init( &ctx );
|
mbedtls_ccm_init( &ctx );
|
||||||
|
|
||||||
|
ASSERT_ALLOC_WEAK( add, add_len );
|
||||||
memset( key, 0, sizeof( key ) );
|
memset( key, 0, sizeof( key ) );
|
||||||
memset( msg, 0, sizeof( msg ) );
|
memset( msg, 0, sizeof( msg ) );
|
||||||
memset( iv, 0, sizeof( iv ) );
|
memset( iv, 0, sizeof( iv ) );
|
||||||
memset( add, 0, sizeof( add ) );
|
|
||||||
memset( out, 0, sizeof( out ) );
|
memset( out, 0, sizeof( out ) );
|
||||||
memset( tag, 0, sizeof( tag ) );
|
memset( tag, 0, sizeof( tag ) );
|
||||||
|
|
||||||
|
@ -70,6 +70,7 @@ void ccm_lengths( int msg_len, int iv_len, int add_len, int tag_len, int res )
|
||||||
TEST_ASSERT( decrypt_ret == res );
|
TEST_ASSERT( decrypt_ret == res );
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
|
mbedtls_free( add );
|
||||||
mbedtls_ccm_free( &ctx );
|
mbedtls_ccm_free( &ctx );
|
||||||
}
|
}
|
||||||
/* END_CASE */
|
/* END_CASE */
|
||||||
|
|
Loading…
Reference in a new issue