public inbox for linux-crypto@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] crypto: authencesn - Copy high sequence number from src after out-of-place decryption
@ 2026-03-25  9:21 Herbert Xu
  2026-03-25 16:23 ` Linus Torvalds
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Herbert Xu @ 2026-03-25  9:21 UTC (permalink / raw)
  To: Linux Crypto Mailing List
  Cc: Eric Biggers, Linus Torvalds, Taeyang Lee, Jakub Kicinski,
	Paolo Abeni, Greg KH, davem, Brian Pak, Juno Im, Jungwon Lim

When decrypting data that is not in-place (src != dst), there is
no need to save the high-order sequence bits in dst as it could
simply be re-copied from the source.

Reported-by: Taeyang Lee <0wn@theori.io>
Fixes: 104880a6b470 ("crypto: authencesn - Convert to new AEAD interface")
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

diff --git a/crypto/authencesn.c b/crypto/authencesn.c
index 542a978663b9..fae8c1dbf495 100644
--- a/crypto/authencesn.c
+++ b/crypto/authencesn.c
@@ -215,9 +215,12 @@ static int crypto_authenc_esn_decrypt_tail(struct aead_request *req,
 		goto decrypt;
 
 	/* Move high-order bits of sequence number back. */
-	scatterwalk_map_and_copy(tmp, dst, 4, 4, 0);
-	scatterwalk_map_and_copy(tmp + 1, dst, assoclen + cryptlen, 4, 0);
-	scatterwalk_map_and_copy(tmp, dst, 0, 8, 1);
+	if (req->src == dst) {
+		scatterwalk_map_and_copy(tmp, dst, 4, 4, 0);
+		scatterwalk_map_and_copy(tmp + 1, dst, assoclen + cryptlen, 4, 0);
+		scatterwalk_map_and_copy(tmp, dst, 0, 8, 1);
+	} else
+		memcpy_sglist(dst, req->src, 8);
 
 	if (crypto_memneq(ihash, ohash, authsize))
 		return -EBADMSG;
@@ -273,10 +276,12 @@ static int crypto_authenc_esn_decrypt(struct aead_request *req)
 	if (!authsize)
 		goto tail;
 
-	/* Move high-order bits of sequence number to the end. */
 	scatterwalk_map_and_copy(tmp, dst, 0, 8, 0);
 	scatterwalk_map_and_copy(tmp, dst, 4, 4, 1);
-	scatterwalk_map_and_copy(tmp + 1, dst, assoclen + cryptlen, 4, 1);
+	if (req->src == dst) {
+		/* Move high-order bits of sequence number to the end. */
+		scatterwalk_map_and_copy(tmp + 1, dst, assoclen + cryptlen, 4, 1);
+	}
 
 	sg_init_table(areq_ctx->dst, 2);
 	dst = scatterwalk_ffwd(areq_ctx->dst, dst, 4);
-- 
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2026-03-27  6:04 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-25  9:21 [PATCH] crypto: authencesn - Copy high sequence number from src after out-of-place decryption Herbert Xu
2026-03-25 16:23 ` Linus Torvalds
2026-03-26  4:17   ` Herbert Xu
2026-03-26  6:45     ` Herbert Xu
2026-03-26  6:46     ` [PATCH] crypto: authencesn - Use memcpy_from/to_sglist Herbert Xu
2026-03-25 17:59 ` [PATCH] crypto: authencesn - Copy high sequence number from src after out-of-place decryption Taeyang Lee
2026-03-26  6:30   ` [PATCH] crypto: algif_aead - Revert to operating out-of-place Herbert Xu
2026-03-26 17:43     ` Taeyang Lee
2026-03-27  6:04 ` [v2 PATCH] crypto: authencesn - Do not place hiseq at end of dst for out-of-place decryption Herbert Xu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox