[PATCH 02/20] lib/crypto: aes-xctr: Pass counter by value to aes_xctr_arch()

From: Eric Biggers

Date: Mon Sep 21 2026 - 01:16:33 EST


Update the calling convention for aes_xctr_arch() to pass the counter by
value, then do the increment in generic code. This aligns better with
the x86_64 and arm64 assembly code for XCTR, which takes the counter by
value and thus has to be paired with an increment in C code anyway.

Signed-off-by: Eric Biggers <ebiggers@xxxxxxxxxx>
---
lib/crypto/aes.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/lib/crypto/aes.c b/lib/crypto/aes.c
index f1549839b3de..22f096c50242 100644
--- a/lib/crypto/aes.c
+++ b/lib/crypto/aes.c
@@ -1094,7 +1094,7 @@ static bool aes_ctr_arch(u8 *dst, const u8 *src, size_t len,
}
#endif
#ifndef aes_xctr_arch
-static bool aes_xctr_arch(u8 *dst, const u8 *src, size_t len, u64 *ctr,
+static bool aes_xctr_arch(u8 *dst, const u8 *src, size_t len, u64 ctr,
const u8 iv[AES_BLOCK_SIZE],
const struct aes_enckey *key)
{
@@ -1150,8 +1150,10 @@ void aes_xctr(u8 *dst, const u8 *src, size_t len, u64 *ctr,
__le64 aes_input[2];
u8 keystream[AES_BLOCK_SIZE] __aligned(__alignof__(long));

- if (likely(aes_xctr_arch(dst, src, len, ctr, iv, key.enc_key)))
+ if (likely(aes_xctr_arch(dst, src, len, *ctr, iv, key.enc_key))) {
+ *ctr += DIV_ROUND_UP(len, AES_BLOCK_SIZE);
return;
+ }

aes_input[1] = get_unaligned((const __le64 *)&iv[8]);
/* Handle the full blocks. */
--
2.55.0