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`
diff --git a/library/cipher.c b/library/cipher.c
index da55206..d7acf34 100644
--- a/library/cipher.c
+++ b/library/cipher.c
@@ -242,6 +242,9 @@
else if( NULL == iv && iv_len != 0 )
return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA );
+ if( NULL == iv && iv_len == 0 )
+ ctx->iv_size = 0;
+
/* avoid buffer overflow in ctx->iv */
if( iv_len > MBEDTLS_MAX_IV_LENGTH )
return( MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE );
@@ -269,7 +272,7 @@
}
#endif
- if ( actual_iv_size )
+ if ( actual_iv_size != 0 )
{
memcpy( ctx->iv, iv, actual_iv_size );
ctx->iv_size = actual_iv_size;