summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTudor Ambarus <tudor.ambarus@microchip.com>2019-12-13 14:45:44 +0000
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2020-02-11 04:37:30 -0800
commit518878447abb1e9923a29e1fdeedb29ad8640457 (patch)
tree4ac10cd2dc361868e2c5ff5b338c53e6f08779e1
parentabd0966ee0a650ad56d3ae2b2a1e42a33a0f82bc (diff)
crypto: atmel-aes - Fix CTR counter overflow when multiple fragments
[ Upstream commit 3907ccfaec5d9965e306729936fc732c94d2c1e7 ] The CTR transfer works in fragments of data of maximum 1 MByte because of the 16 bit CTR counter embedded in the IP. Fix the CTR counter overflow handling for messages larger than 1 MByte. Reported-by: Dan Carpenter <dan.carpenter@oracle.com> Fixes: 781a08d9740a ("crypto: atmel-aes - Fix counter overflow in CTR mode") Signed-off-by: Tudor Ambarus <tudor.ambarus@microchip.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au> Signed-off-by: Sasha Levin <sashal@kernel.org>
-rw-r--r--drivers/crypto/atmel-aes.c8
1 files changed, 7 insertions, 1 deletions
diff --git a/drivers/crypto/atmel-aes.c b/drivers/crypto/atmel-aes.c
index ea9dcd7ce799..b4dee726b253 100644
--- a/drivers/crypto/atmel-aes.c
+++ b/drivers/crypto/atmel-aes.c
@@ -121,7 +121,7 @@ struct atmel_aes_ctr_ctx {
size_t offset;
struct scatterlist src[2];
struct scatterlist dst[2];
- u16 blocks;
+ u32 blocks;
};
struct atmel_aes_gcm_ctx {
@@ -528,6 +528,12 @@ static void atmel_aes_ctr_update_req_iv(struct atmel_aes_dev *dd)
unsigned int ivsize = crypto_skcipher_ivsize(skcipher);
int i;
+ /*
+ * The CTR transfer works in fragments of data of maximum 1 MByte
+ * because of the 16 bit CTR counter embedded in the IP. When reaching
+ * here, ctx->blocks contains the number of blocks of the last fragment
+ * processed, there is no need to explicit cast it to u16.
+ */
for (i = 0; i < ctx->blocks; i++)
crypto_inc((u8 *)ctx->iv, AES_BLOCK_SIZE);