Skip to content

Commit bb4bbbb

Browse files
Ron Eldorsimonbutcher
authored andcommitted
Resolve PR review comments
Address review comments: 1. add `mbedtls_cipher_init()` after freeing context, in test code 2. style comments 3. set `ctx->iv_size = 0` in case `IV == NULL && iv_len == 0`
1 parent 6f90ed8 commit bb4bbbb

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

library/cipher.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,9 @@ int mbedtls_cipher_set_iv( mbedtls_cipher_context_t *ctx,
242242
else if( NULL == iv && iv_len != 0 )
243243
return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA );
244244

245+
if( NULL == iv && iv_len == 0 )
246+
ctx->iv_size = 0;
247+
245248
/* avoid buffer overflow in ctx->iv */
246249
if( iv_len > MBEDTLS_MAX_IV_LENGTH )
247250
return( MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE );
@@ -269,7 +272,7 @@ int mbedtls_cipher_set_iv( mbedtls_cipher_context_t *ctx,
269272
}
270273
#endif
271274

272-
if ( actual_iv_size )
275+
if ( actual_iv_size != 0 )
273276
{
274277
memcpy( ctx->iv, iv, actual_iv_size );
275278
ctx->iv_size = actual_iv_size;

tests/suites/test_suite_cipher.function

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ void cipher_special_behaviours( )
106106
mbedtls_cipher_init( &ctx );
107107
memset( input, 0, sizeof( input ) );
108108
memset( output, 0, sizeof( output ) );
109-
#if defined (MBEDTLS_CIPHER_MODE_CBC)
109+
#if defined(MBEDTLS_CIPHER_MODE_CBC)
110110
memset( iv, 0, sizeof( iv ) );
111111

112112
/* Check and get info structures */
@@ -124,6 +124,7 @@ void cipher_special_behaviours( )
124124
== MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA );
125125

126126
mbedtls_cipher_free( &ctx );
127+
mbedtls_cipher_init( &ctx );
127128
#endif /* MBEDTLS_CIPHER_MODE_CBC */
128129
cipher_info = mbedtls_cipher_info_from_type( MBEDTLS_CIPHER_AES_128_ECB );
129130
TEST_ASSERT( NULL != cipher_info );

0 commit comments

Comments
 (0)