[PATCH 32/42] mkfs.ubifs: Correctly use iv lengths in aes-cts mode

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxx>
---
 ubifs-utils/mkfs.ubifs/crypto.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/ubifs-utils/mkfs.ubifs/crypto.c b/ubifs-utils/mkfs.ubifs/crypto.c
index bd3273767a5b..8d113f198bb2 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;
 }
-- 
2.19.1


______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/



[Index of Archives]     [LARTC]     [Bugtraq]     [Yosemite Forum]     [Photo]

  Powered by Linux