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.
diff --git a/library/cipher.c b/library/cipher.c
index d90abe1..a5f6e11 100644
--- a/library/cipher.c
+++ b/library/cipher.c
@@ -399,19 +399,18 @@
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;
}
diff --git a/library/cipher_wrap.c b/library/cipher_wrap.c
index 5c98100..ebe60cf 100644
--- a/library/cipher_wrap.c
+++ b/library/cipher_wrap.c
@@ -150,6 +150,7 @@
128,
"AES-128-CBC",
16,
+ 0,
16,
&aes_info
};
@@ -160,6 +161,7 @@
192,
"AES-192-CBC",
16,
+ 0,
16,
&aes_info
};
@@ -170,6 +172,7 @@
256,
"AES-256-CBC",
16,
+ 0,
16,
&aes_info
};
@@ -181,6 +184,7 @@
128,
"AES-128-CFB128",
16,
+ 0,
16,
&aes_info
};
@@ -191,6 +195,7 @@
192,
"AES-192-CFB128",
16,
+ 0,
16,
&aes_info
};
@@ -201,6 +206,7 @@
256,
"AES-256-CFB128",
16,
+ 0,
16,
&aes_info
};
@@ -213,6 +219,7 @@
128,
"AES-128-CTR",
16,
+ 0,
16,
&aes_info
};
@@ -223,6 +230,7 @@
192,
"AES-192-CTR",
16,
+ 0,
16,
&aes_info
};
@@ -233,6 +241,7 @@
256,
"AES-256-CTR",
16,
+ 0,
16,
&aes_info
};
@@ -271,7 +280,8 @@
POLARSSL_MODE_GCM,
128,
"AES-128-GCM",
- 0,
+ 12,
+ 1,
16,
&gcm_aes_info
};
@@ -281,7 +291,8 @@
POLARSSL_MODE_GCM,
256,
"AES-256-GCM",
- 0,
+ 12,
+ 1,
16,
&gcm_aes_info
};
@@ -373,6 +384,7 @@
128,
"CAMELLIA-128-CBC",
16,
+ 0,
16,
&camellia_info
};
@@ -383,6 +395,7 @@
192,
"CAMELLIA-192-CBC",
16,
+ 0,
16,
&camellia_info
};
@@ -393,6 +406,7 @@
256,
"CAMELLIA-256-CBC",
16,
+ 0,
16,
&camellia_info
};
@@ -404,6 +418,7 @@
128,
"CAMELLIA-128-CFB128",
16,
+ 0,
16,
&camellia_info
};
@@ -414,6 +429,7 @@
192,
"CAMELLIA-192-CFB128",
16,
+ 0,
16,
&camellia_info
};
@@ -424,6 +440,7 @@
256,
"CAMELLIA-256-CFB128",
16,
+ 0,
16,
&camellia_info
};
@@ -436,6 +453,7 @@
128,
"CAMELLIA-128-CTR",
16,
+ 0,
16,
&camellia_info
};
@@ -446,6 +464,7 @@
192,
"CAMELLIA-192-CTR",
16,
+ 0,
16,
&camellia_info
};
@@ -456,6 +475,7 @@
256,
"CAMELLIA-256-CTR",
16,
+ 0,
16,
&camellia_info
};
@@ -581,6 +601,7 @@
POLARSSL_KEY_LENGTH_DES,
"DES-CBC",
8,
+ 0,
8,
&des_info
};
@@ -603,6 +624,7 @@
POLARSSL_KEY_LENGTH_DES_EDE,
"DES-EDE-CBC",
8,
+ 0,
8,
&des_ede_info
};
@@ -625,6 +647,7 @@
POLARSSL_KEY_LENGTH_DES_EDE3,
"DES-EDE3-CBC",
8,
+ 0,
8,
&des_ede3_info
};
@@ -709,6 +732,7 @@
128,
"BLOWFISH-CBC",
8,
+ 0,
8,
&blowfish_info
};
@@ -720,6 +744,7 @@
128,
"BLOWFISH-CFB64",
8,
+ 0,
8,
&blowfish_info
};
@@ -732,6 +757,7 @@
128,
"BLOWFISH-CTR",
8,
+ 0,
8,
&blowfish_info
};
@@ -781,6 +807,7 @@
128,
"ARC4-128",
0,
+ 0,
1,
&arc4_base_info
};
@@ -834,6 +861,7 @@
0,
"NULL",
0,
+ 0,
1,
&null_base_info
};
diff --git a/library/pkcs12.c b/library/pkcs12.c
index 3634ce1..cc59d68 100644
--- a/library/pkcs12.c
+++ b/library/pkcs12.c
@@ -184,10 +184,10 @@
if( ( ret = cipher_setkey( &cipher_ctx, key, keylen, mode ) ) != 0 )
goto exit;
- if( ( ret = cipher_set_iv( &cipher_ctx, iv, 0 ) ) != 0 )
+ if( ( ret = cipher_set_iv( &cipher_ctx, iv, cipher_info->iv_size ) ) != 0 )
goto exit;
- if( ( ret = cipher_reset( &cipher_ctx, iv, 0 ) ) != 0 )
+ if( ( ret = cipher_reset( &cipher_ctx, NULL, 0 ) ) != 0 )
goto exit;
if( ( ret = cipher_update( &cipher_ctx, data, len,
diff --git a/library/pkcs5.c b/library/pkcs5.c
index 6582fd0..10adbb4 100644
--- a/library/pkcs5.c
+++ b/library/pkcs5.c
@@ -187,7 +187,7 @@
if( ( ret = cipher_setkey( &cipher_ctx, key, keylen, mode ) ) != 0 )
goto exit;
- if( ( ret = cipher_set_iv( &cipher_ctx, iv, 0 ) ) != 0 )
+ if( ( ret = cipher_set_iv( &cipher_ctx, iv, enc_scheme_params.len ) ) != 0 )
goto exit;
if( ( ret = cipher_reset( &cipher_ctx, NULL, 0 ) ) != 0 )