From: scott_gzh@163.com
To: herbert@gondor.apana.org.au, davem@davemloft.net
Cc: linux-crypto@vger.kernel.org, Scott GUO <scottzhguo@tencent.com>
Subject: [PATCH 2/2] authencesn: Refactor inplace-decryption with sglist shift helper
Date: Fri, 15 May 2026 16:36:45 +0800 [thread overview]
Message-ID: <20260515083645.4024574-3-scott_gzh@163.com> (raw)
In-Reply-To: <20260515083645.4024574-1-scott_gzh@163.com>
From: Scott GUO <scottzhguo@tencent.com>
By using shift helpers, we shift assoc data and crypt data in-place
, avoid writing the ICV tag part during decryption.
This patch also merge the code for in-place and non-in-place
decryption together once again.
Fixes: e02494114ebf ("crypto: authencesn - Do not place hiseq at end of dst for out-of-place decryption")
Signed-off-by: GUO Zihua <scottzhguo@tencent.com>
---
crypto/authencesn.c | 38 ++++++++++++--------------------------
1 file changed, 12 insertions(+), 26 deletions(-)
diff --git a/crypto/authencesn.c b/crypto/authencesn.c
index 522df41365d8..a81003a69a18 100644
--- a/crypto/authencesn.c
+++ b/crypto/authencesn.c
@@ -210,18 +210,14 @@ static int crypto_authenc_esn_decrypt_tail(struct aead_request *req,
struct scatterlist *src = req->src;
struct scatterlist *dst = req->dst;
u8 *ihash = ohash + crypto_ahash_digestsize(auth);
- u32 tmp[2];
+ u32 tmp;
if (!authsize)
goto decrypt;
- if (src == dst) {
- /* 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);
- } else
- memcpy_sglist(dst, src, assoclen);
+ memcpy_from_sglist(&tmp, dst, assoclen + cryptlen - 4, 4);
+ sglist_shift_right(dst, 8, 4, assoclen + cryptlen - 8);
+ memcpy_to_sglist(dst, 4, &tmp, 4);
if (crypto_memneq(ihash, ohash, authsize))
return -EBADMSG;
@@ -264,7 +260,7 @@ static int crypto_authenc_esn_decrypt(struct aead_request *req)
u8 *ihash = ohash + crypto_ahash_digestsize(auth);
struct scatterlist *src = req->src;
struct scatterlist *dst = req->dst;
- u32 tmp[2];
+ u32 tmp;
int err;
if (assoclen < 8)
@@ -274,24 +270,14 @@ static int crypto_authenc_esn_decrypt(struct aead_request *req)
goto tail;
cryptlen -= authsize;
- scatterwalk_map_and_copy(ihash, req->src, assoclen + cryptlen,
- authsize, 0);
+ memcpy_from_sglist(ihash, req->src, assoclen + cryptlen, authsize);
- /* Move high-order bits of sequence number to the end. */
- scatterwalk_map_and_copy(tmp, src, 0, 8, 0);
- if (src == dst) {
- scatterwalk_map_and_copy(tmp, dst, 4, 4, 1);
- scatterwalk_map_and_copy(tmp + 1, dst, assoclen + cryptlen, 4, 1);
- dst = scatterwalk_ffwd(areq_ctx->dst, dst, 4);
- } else {
- scatterwalk_map_and_copy(tmp, dst, 0, 4, 1);
- scatterwalk_map_and_copy(tmp + 1, dst, assoclen + cryptlen - 4, 4, 1);
-
- src = scatterwalk_ffwd(areq_ctx->src, src, 8);
- dst = scatterwalk_ffwd(areq_ctx->dst, dst, 4);
- memcpy_sglist(dst, src, assoclen + cryptlen - 8);
- dst = req->dst;
- }
+ memcpy_from_sglist(&tmp, src, 4, 4);
+ if (src != dst)
+ memcpy_sglist(dst, src, assoclen + cryptlen);
+
+ sglist_shift_left(dst, 4, 8, assoclen + cryptlen - 8);
+ memcpy_to_sglist(dst, assoclen + cryptlen - 4, &tmp, 4);
ahash_request_set_tfm(ahreq, auth);
ahash_request_set_crypt(ahreq, dst, ohash, assoclen + cryptlen);
--
2.41.3
next prev parent reply other threads:[~2026-05-15 8:38 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-15 8:36 [PATCH 0/2] authencesn: Refactor in-place decryption scott_gzh
2026-05-15 8:36 ` [PATCH 1/2] scatterlist: Introduce sglist_shift_{left,right} helpers scott_gzh
2026-05-15 8:36 ` scott_gzh [this message]
2026-05-15 10:41 ` [PATCH 0/2] authencesn: Refactor in-place decryption Scott Guo
2026-05-15 11:01 ` Scott Guo
2026-05-18 2:33 ` Herbert Xu
2026-05-18 2:55 ` Scott Guo
2026-05-18 3:17 ` Herbert Xu
2026-05-18 6:48 ` Scott Guo
2026-05-18 8:21 ` Herbert Xu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260515083645.4024574-3-scott_gzh@163.com \
--to=scott_gzh@163.com \
--cc=davem@davemloft.net \
--cc=herbert@gondor.apana.org.au \
--cc=linux-crypto@vger.kernel.org \
--cc=scottzhguo@tencent.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox