Fix after PR comments
1. Don't set IV onECB 2. Fix style issues 3. reduce number of tests
This commit is contained in:
parent
7b01244b99
commit
4e64e0b922
5 changed files with 36 additions and 474 deletions
|
@ -237,15 +237,11 @@ int mbedtls_cipher_set_iv( mbedtls_cipher_context_t *ctx,
|
|||
const unsigned char *iv, size_t iv_len )
|
||||
{
|
||||
size_t actual_iv_size;
|
||||
if( NULL == ctx || NULL == ctx->cipher_info ||
|
||||
( NULL == iv && ( ctx->cipher_info->mode != MBEDTLS_MODE_ECB ) ) )
|
||||
if( NULL == ctx || NULL == ctx->cipher_info )
|
||||
return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA );
|
||||
else if( NULL == iv && iv_len != 0 )
|
||||
return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA );
|
||||
|
||||
if ( ctx->cipher_info->mode == MBEDTLS_MODE_ECB )
|
||||
{
|
||||
ctx->iv_size = 0;
|
||||
return ( 0 );
|
||||
}
|
||||
/* avoid buffer overflow in ctx->iv */
|
||||
if( iv_len > MBEDTLS_MAX_IV_LENGTH )
|
||||
return( MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE );
|
||||
|
@ -273,8 +269,11 @@ int mbedtls_cipher_set_iv( mbedtls_cipher_context_t *ctx,
|
|||
}
|
||||
#endif
|
||||
|
||||
memcpy( ctx->iv, iv, actual_iv_size );
|
||||
ctx->iv_size = actual_iv_size;
|
||||
if ( actual_iv_size )
|
||||
{
|
||||
memcpy( ctx->iv, iv, actual_iv_size );
|
||||
ctx->iv_size = actual_iv_size;
|
||||
}
|
||||
|
||||
return( 0 );
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue