Add tests for mbedtls_cipher_crypt API

1. Add tests for 'mbedtls_cipher_crypt()' API
2. Resolves #1091, by ignoring IV when the cipher mode is MBEDTLS_MODE_ECB
This commit is contained in:
Ron Eldor 2017-09-25 17:03:12 +03:00 committed by Simon Butcher
parent 7d728bd70e
commit 7b01244b99
4 changed files with 686 additions and 3 deletions

View file

@ -237,10 +237,15 @@ 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 )
if( NULL == ctx || NULL == ctx->cipher_info ||
( NULL == iv && ( ctx->cipher_info->mode != MBEDTLS_MODE_ECB ) ) )
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 );