summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Weinberger <richard@nod.at>2018-10-18 16:37:08 +0200
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2018-11-01 12:41:25 +0100
commitd9421785a18fdfae0ada62ecbfcbbdd28c4e0fde (patch)
tree70e579f451da488a9969b0d565dfec7c21a97e14
parent82e9055c49a6bceff3e32757cb4c0f10f46468ae (diff)
mkfs.ubifs: Correctly use iv lengths in aes-cts mode
The key length can be very long, for example in xts mode. So we have to use the right sizes for block and iv lengths. Signed-off-by: Richard Weinberger <richard@nod.at> Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
-rw-r--r--ubifs-utils/mkfs.ubifs/crypto.c12
1 files changed, 6 insertions, 6 deletions
diff --git a/ubifs-utils/mkfs.ubifs/crypto.c b/ubifs-utils/mkfs.ubifs/crypto.c
index bd32737..8d113f1 100644
--- a/ubifs-utils/mkfs.ubifs/crypto.c
+++ b/ubifs-utils/mkfs.ubifs/crypto.c
@@ -207,32 +207,32 @@ static ssize_t encrypt_cbc_cts(const void *plaintext, size_t size,
memset(iv, 0, ivsize);
- diff = size % key_len;
+ diff = size % ivsize;
if (diff) {
- padded_size = size - diff + key_len;
+ padded_size = size - diff + ivsize;
padded = size > 256 ? malloc(padded_size) : alloca(padded_size);
memcpy(padded, plaintext, size);
memset(padded + size, 0, padded_size - size);
ret = do_encrypt(cipher, padded, padded_size, key, key_len,
- iv, sizeof(iv), ciphertext);
+ iv, ivsize, ciphertext);
if (size > 256)
free(padded);
} else {
ret = do_encrypt(cipher, plaintext, size, key, key_len,
- iv, sizeof(iv), ciphertext);
+ iv, ivsize, ciphertext);
}
if (ret < 0)
return ret;
- count = ret / key_len;
+ count = ret / ivsize;
if (count > 1)
- block_swap(ciphertext, count - 2, count - 1, key_len);
+ block_swap(ciphertext, count - 2, count - 1, ivsize);
return size;
}