1
0
mirror of https://github.com/Mbed-TLS/mbedtls.git synced 2025-07-30 22:43:08 +03:00

Fix iv_len interface.

cipher_info->iv_size == 0 is no longer ambiguous, and
cipher_get_iv_size() always returns something useful to generate an IV.
This commit is contained in:
Manuel Pégourié-Gonnard
2013-09-03 13:25:52 +02:00
parent 9c853b910c
commit a235b5b5bd
5 changed files with 49 additions and 19 deletions

View File

@ -399,19 +399,18 @@ int cipher_setkey( cipher_context_t *ctx, const unsigned char *key,
int cipher_set_iv( cipher_context_t *ctx,
const unsigned char *iv, size_t iv_len )
{
size_t fixed_iv_size;
size_t actual_iv_size;
if( NULL == ctx || NULL == ctx->cipher_info || NULL == iv )
return POLARSSL_ERR_CIPHER_BAD_INPUT_DATA;
fixed_iv_size = cipher_get_iv_size( ctx );
if( ctx->cipher_info->accepts_variable_iv_size )
actual_iv_size = iv_len;
else
actual_iv_size = ctx->cipher_info->iv_size;
/* 0 means variable size (or no IV): use given len */
if( fixed_iv_size == 0 )
fixed_iv_size = iv_len;
memcpy( ctx->iv, iv, fixed_iv_size );
ctx->iv_size = fixed_iv_size;
memcpy( ctx->iv, iv, actual_iv_size );
ctx->iv_size = actual_iv_size;
return 0;
}