Skip to contentSkip to conversation

crypto: x86/aes-xts - simplify loop in xts_crypt_slowpath()

PATCH In review Eric Biggers 2 participants 2 messages Apr 20, 2024 – Apr 26, 2024

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 crypto: x86/aes-xts - simplify loop in xts_crypt_slowpath()

From: Eric Biggers <[email protected]>

Since the total length processed by the loop in xts_crypt_slowpath() is a multiple of AES_BLOCK_SIZE, just round the length down to AES_BLOCK_SIZE even on the last step. This doesn't change behavior, as the last step will process a multiple of AES_BLOCK_SIZE regardless.

---
 arch/x86/crypto/aesni-intel_glue.c | 13 +++++--------
 1 file changed, 5 insertions(+), 8 deletions(-)
arch/x86/crypto/aesni-intel_glue.c +5 -8
index 110b3282a1f2..02a4c0c276df 100644
@@ -933,20 +933,17 @@ xts_crypt_slowpath(struct skcipher_request *req, xts_crypt_func crypt_func)
 	}
 
 	err = skcipher_walk_virt(&walk, req, false);
 
 	while (walk.nbytes) {
-		unsigned int nbytes = walk.nbytes;
-
-		if (nbytes < walk.total)
-			nbytes = round_down(nbytes, AES_BLOCK_SIZE);
-
 		kernel_fpu_begin();
-		(*crypt_func)(&ctx->crypt_ctx, walk.src.virt.addr,
-			      walk.dst.virt.addr, nbytes, req->iv);
+		(*crypt_func)(&ctx->crypt_ctx,
+			      walk.src.virt.addr, walk.dst.virt.addr,
+			      walk.nbytes & ~(AES_BLOCK_SIZE - 1), req->iv);
 		kernel_fpu_end();
-		err = skcipher_walk_done(&walk, walk.nbytes - nbytes);
+		err = skcipher_walk_done(&walk,
+					 walk.nbytes & (AES_BLOCK_SIZE - 1));
 	}
 
 	if (err || !tail)
 		return err;
 

base-commit: 543ea178fbfadeaf79e15766ac989f3351349f02

Signature · 1 line
2.44.0
maintainer
#1 lore raw
Quoted 11 lines · Eric Biggers

From: Eric Biggers <[email protected]>

Since the total length processed by the loop in xts_crypt_slowpath() is a multiple of AES_BLOCK_SIZE, just round the length down to AES_BLOCK_SIZE even on the last step. This doesn't change behavior, as the last step will process a multiple of AES_BLOCK_SIZE regardless.

---
arch/x86/crypto/aesni-intel_glue.c | 13 +++++--------

1 file changed, 5 insertions(+), 8 deletions(-)

Patch applied. Thanks.

Signature · 3 lines
Email: Herbert Xu <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt