Skip to content

Commit 3907ccf

Browse files
ambarusherbertx
authored andcommitted
crypto: atmel-aes - Fix CTR counter overflow when multiple fragments
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 <[email protected]> Fixes: 781a08d ("crypto: atmel-aes - Fix counter overflow in CTR mode") Signed-off-by: Tudor Ambarus <[email protected]> Signed-off-by: Herbert Xu <[email protected]>
1 parent 27896af commit 3907ccf

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

drivers/crypto/atmel-aes.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ struct atmel_aes_ctr_ctx {
120120
size_t offset;
121121
struct scatterlist src[2];
122122
struct scatterlist dst[2];
123-
u16 blocks;
123+
u32 blocks;
124124
};
125125

126126
struct atmel_aes_gcm_ctx {
@@ -527,6 +527,12 @@ static void atmel_aes_ctr_update_req_iv(struct atmel_aes_dev *dd)
527527
unsigned int ivsize = crypto_skcipher_ivsize(skcipher);
528528
int i;
529529

530+
/*
531+
* The CTR transfer works in fragments of data of maximum 1 MByte
532+
* because of the 16 bit CTR counter embedded in the IP. When reaching
533+
* here, ctx->blocks contains the number of blocks of the last fragment
534+
* processed, there is no need to explicit cast it to u16.
535+
*/
530536
for (i = 0; i < ctx->blocks; i++)
531537
crypto_inc((u8 *)ctx->iv, AES_BLOCK_SIZE);
532538

0 commit comments

Comments
 (0)