Skip to content

Commit

Permalink
Dynamically allocate iv in dec_empty_buf tests
Browse files Browse the repository at this point in the history
Signed-off-by: Andrzej Kurek <[email protected]>
  • Loading branch information
Andrzej Kurek authored and Andrzej Kurek committed Jan 14, 2022
1 parent 72f0905 commit 4739eab
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions tests/suites/test_suite_cipher.function
Original file line number Diff line number Diff line change
Expand Up @@ -533,8 +533,9 @@ void dec_empty_buf( int cipher,
int expected_finish_ret )
{
unsigned char key[32];
unsigned char iv[16];
size_t iv_len = sizeof(iv);

unsigned char *iv = NULL;
size_t iv_len = 16;

mbedtls_cipher_context_t ctx_dec;
const mbedtls_cipher_info_t *cipher_info;
Expand All @@ -545,7 +546,6 @@ void dec_empty_buf( int cipher,
size_t outlen = 0;

memset( key, 0, 32 );
memset( iv , 0, 16 );

mbedtls_cipher_init( &ctx_dec );

Expand All @@ -560,6 +560,9 @@ void dec_empty_buf( int cipher,
cipher_info->type == MBEDTLS_CIPHER_CHACHA20_POLY1305 )
iv_len = 12;

ASSERT_ALLOC( iv, iv_len );
memset( iv , 0, iv_len );

TEST_ASSERT( sizeof(key) * 8 >= cipher_info->key_bitlen );

TEST_ASSERT( 0 == mbedtls_cipher_setup( &ctx_dec, cipher_info ) );
Expand Down Expand Up @@ -598,6 +601,7 @@ void dec_empty_buf( int cipher,
TEST_ASSERT( 0 == outlen );

exit:
mbedtls_free( iv );
mbedtls_cipher_free( &ctx_dec );
}
/* END_CASE */
Expand Down

0 comments on commit 4739eab

Please sign in to comment.