From: Rosen Penev <rosenp@gmail.com>
To: linux-crypto@vger.kernel.org, Herbert Xu <herbert@gondor.apana.org.au>
Cc: Srujana Challa <schalla@marvell.com>,
Bharat Bhushan <bbhushan2@marvell.com>,
"David S. Miller" <davem@davemloft.net>,
Rosen Penev <rosenp@gmail.com>,
Arnaud Ebalard <arno@natisbad.org>,
Boris Brezillon <bbrezillon@kernel.org>,
Russell King <rmk+kernel@arm.linux.org.uk>,
Romain Perier <romain.perier@free-electrons.com>,
stable@vger.kernel.org
Subject: [PATCH 3/8] crypto: cesa - hash the last full SRAM chunk before the padding
Date: Fri, 27 Nov 2026 20:40:45 -0800 [thread overview]
Message-ID: <20261128044050.722617-4-rosenp@gmail.com> (raw)
In-Reply-To: <20261128044050.722617-1-rosenp@gmail.com>
When a hash is longer than the engine's total length field (0xffff),
mv_cesa_ahash_dma_last_req() pads it by hand. The padding is placed in
SRAM right behind the outstanding data and the two are hashed by one
operation, or, if only part of the padding fits, in two.
If the outstanding data fills the SRAM payload exactly, none of the
padding fits behind it. That case adds no operation for the outstanding
data at all and transfers the padding to the start of the SRAM data
area, overwriting the last payload-sized chunk of the message before it
was hashed. Every message longer than 0xffff bytes whose last chunk ends
exactly at the payload size (1920 bytes with the default 2 KiB SRAM),
for example any one-shot digest of a multiple of 1920 bytes, gets a
wrong digest.
Hash the outstanding data with its own operation first, as was done
before the padding handling was rearranged.
Verified on an Armada 385 (WRT3200ACM) against the software hashes,
with random lengths up to 140000 bytes: about 10 of 40000 SHA1,
SHA256, HMAC-SHA1 and HMAC-SHA256 digests were wrong before, all of
them of that shape, and none of 60000 after.
Fixes: ab270e7055e0 ("crypto: marvell/cesa - rearrange handling for sw padded hashes")
Cc: stable@vger.kernel.org
Signed-off-by: Rosen Penev <rosenp@gmail.com>
---
drivers/crypto/marvell/cesa/hash.c | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/drivers/crypto/marvell/cesa/hash.c b/drivers/crypto/marvell/cesa/hash.c
index d2fe96d865bd..9fd3d5c32312 100644
--- a/drivers/crypto/marvell/cesa/hash.c
+++ b/drivers/crypto/marvell/cesa/hash.c
@@ -607,6 +607,16 @@ mv_cesa_ahash_dma_last_req(struct mv_cesa_tdma_chain *chain,
return op;
padoff += len;
+ } else if (frag_len) {
+ /*
+ * The outstanding data fills the SRAM payload, so none of the
+ * padding fits behind it. Hash that data on its own before the
+ * padding transfer below overwrites it.
+ */
+ op = mv_cesa_dma_add_frag(chain, &creq->op_tmpl, frag_len,
+ flags);
+ if (IS_ERR(op))
+ return op;
}
ret = mv_cesa_dma_add_data_transfer(chain,
--
2.56.1
next prev parent reply other threads:[~2026-11-28 4:40 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20261128044050.722617-1-rosenp@gmail.com>
2026-11-28 4:40 ` [PATCH 1/8] crypto: cesa - clear the IRQ affinity hint before freeing the IRQ Rosen Penev
2026-11-28 4:40 ` [PATCH 2/8] crypto: cesa - do not allow unbinding the device Rosen Penev
2026-11-28 4:40 ` Rosen Penev [this message]
2026-11-28 4:40 ` [PATCH 4/8] crypto: cesa - finish the HMAC outer hash when padding by hand Rosen Penev
2026-11-28 4:40 ` [PATCH 5/8] crypto: cesa - keep the chained IV on the non-TDMA cipher path Rosen Penev
2026-11-28 4:40 ` [PATCH 6/8] crypto: cesa - put the non-TDMA hash padding behind the data Rosen Penev
2026-11-28 4:40 ` [PATCH 7/8] crypto: cesa - do not step empty hash operations on the non-TDMA path Rosen Penev
2026-11-28 4:40 ` [PATCH 8/8] crypto: cesa - finish long hashes " Rosen Penev
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=20261128044050.722617-4-rosenp@gmail.com \
--to=rosenp@gmail.com \
--cc=arno@natisbad.org \
--cc=bbhushan2@marvell.com \
--cc=bbrezillon@kernel.org \
--cc=davem@davemloft.net \
--cc=herbert@gondor.apana.org.au \
--cc=linux-crypto@vger.kernel.org \
--cc=rmk+kernel@arm.linux.org.uk \
--cc=romain.perier@free-electrons.com \
--cc=schalla@marvell.com \
--cc=stable@vger.kernel.org \
/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