Skip to content

Commit

Permalink
crypto: atmel-aes - Fix CTR counter overflow when multiple fragments
Browse files Browse the repository at this point in the history
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: 781a08d ("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>
  • Loading branch information
Tudor Ambarus authored and Herbert Xu committed Dec 20, 2019
1 parent 27896af commit 3907ccf
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion drivers/crypto/atmel-aes.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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);

Expand Down

0 comments on commit 3907ccf

Please sign in to comment.