aes: Allow non-zero initialization vector
AES encryption in CBC mode, in most cases, must be used with random initialization vector. Using the same key and initialization vector several times is weak and must be avoided. Added iv parameter to the aes_cbc_encrypt_blocks and aes_cbc_decrypt_blocks functions for passing initialization vector. Command 'aes' now also require the initialization vector parameter. Signed-off-by: Andrey Mozzhuhin <amozzhuhin@yandex.ru>
This commit is contained in:
committed by
Tom Rini
parent
1414e09b4f
commit
af09eba64f
@@ -50,6 +50,7 @@ static void sign_object(u8 *key, u8 *key_schedule, u8 *src, u8 *dst,
|
||||
u32 num_aes_blocks)
|
||||
{
|
||||
u8 tmp_data[AES_KEY_LENGTH];
|
||||
u8 iv[AES_KEY_LENGTH] = {0};
|
||||
u8 left[AES_KEY_LENGTH];
|
||||
u8 k1[AES_KEY_LENGTH];
|
||||
u8 *cbc_chain_data;
|
||||
@@ -61,7 +62,7 @@ static void sign_object(u8 *key, u8 *key_schedule, u8 *src, u8 *dst,
|
||||
for (i = 0; i < AES_KEY_LENGTH; i++)
|
||||
tmp_data[i] = 0;
|
||||
|
||||
aes_cbc_encrypt_blocks(key_schedule, tmp_data, left, 1);
|
||||
aes_cbc_encrypt_blocks(key_schedule, iv, tmp_data, left, 1);
|
||||
|
||||
left_shift_vector(left, k1, sizeof(left));
|
||||
|
||||
@@ -102,6 +103,7 @@ static int encrypt_and_sign(u8 *key, enum security_op oper, u8 *src,
|
||||
{
|
||||
u32 num_aes_blocks;
|
||||
u8 key_schedule[AES_EXPAND_KEY_LENGTH];
|
||||
u8 iv[AES_KEY_LENGTH] = {0};
|
||||
|
||||
debug("encrypt_and_sign: length = %d\n", length);
|
||||
|
||||
@@ -116,7 +118,8 @@ static int encrypt_and_sign(u8 *key, enum security_op oper, u8 *src,
|
||||
if (oper & SECURITY_ENCRYPT) {
|
||||
/* Perform this in place, resulting in src being encrypted. */
|
||||
debug("encrypt_and_sign: begin encryption\n");
|
||||
aes_cbc_encrypt_blocks(key_schedule, src, src, num_aes_blocks);
|
||||
aes_cbc_encrypt_blocks(key_schedule, iv, src, src,
|
||||
num_aes_blocks);
|
||||
debug("encrypt_and_sign: end encryption\n");
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user