From: <Tudor.Ambarus@microchip.com>
To: <herbert@gondor.apana.org.au>, <dan.carpenter@oracle.com>
Cc: alexandre.belloni@bootlin.com, Tudor.Ambarus@microchip.com,
Ludovic.Desroches@microchip.com, linux-crypto@vger.kernel.org,
linux-arm-kernel@lists.infradead.org
Subject: [PATCH] crypto: atmel-aes - Fix CTR counter overflow when multiple fragments
Date: Fri, 13 Dec 2019 14:45:44 +0000 [thread overview]
Message-ID: <20191213144529.9613-1-tudor.ambarus@microchip.com> (raw)
In-Reply-To: <20191213123800.dsnxfh4tja2q5kbv@kili.mountain>
From: Tudor Ambarus <tudor.ambarus@microchip.com>
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>
---
Thanks, Dan.
drivers/crypto/atmel-aes.c | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/drivers/crypto/atmel-aes.c b/drivers/crypto/atmel-aes.c
index 245d45f93b61..b001fdcd9d95 100644
--- a/drivers/crypto/atmel-aes.c
+++ b/drivers/crypto/atmel-aes.c
@@ -120,7 +120,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 {
@@ -527,6 +527,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);
--
2.20.1
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
next parent reply other threads:[~2019-12-13 22:25 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20191213123800.dsnxfh4tja2q5kbv@kili.mountain>
2019-12-13 14:45 ` Tudor.Ambarus [this message]
2019-12-20 7:08 ` [PATCH] crypto: atmel-aes - Fix CTR counter overflow when multiple fragments Herbert Xu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20191213144529.9613-1-tudor.ambarus@microchip.com \
--to=tudor.ambarus@microchip.com \
--cc=Ludovic.Desroches@microchip.com \
--cc=alexandre.belloni@bootlin.com \
--cc=dan.carpenter@oracle.com \
--cc=herbert@gondor.apana.org.au \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-crypto@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).