Re: [PATCH v4 2/8] crypto: qce - Fix HMAC self-test failures for empty messages

From: Herbert Xu

Date: Fri Jul 03 2026 - 05:28:27 EST


On Mon, Jun 22, 2026 at 03:18:10PM +0200, Bartosz Golaszewski wrote:
> BAM DMA cannot process zero-length transfers. For plain hashes this is
> handled by returning the precomputed hash of the empty message
> (tmpl->hash_zero), but for keyed HMAC the result depends on the key and
> cannot be a constant. As a result, hmac(sha256) produced an incorrect
> digest for an empty message and the crypto self-tests failed.
>
> Allocate a software fallback ahash for the HMAC transforms and use it to
> compute the digest whenever the message is empty (in both the .final()
> and .digest() paths). The fallback is allocated in a dedicated cra_init
> for the HMAC algorithms and is excluded from matching the crypto engine's
> own algorithm to avoid recursion. It is kept keyed in sync with the
> hardware transform in .setkey().
>
> Cc: stable@xxxxxxxxxxxxxxx
> Fixes: ec8f5d8f6f76 ("crypto: qce - Qualcomm crypto engine driver")
> Tested-by: Kuldeep Singh <kuldeep.singh@xxxxxxxxxxxxxxxx>
> Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@xxxxxxxxxxxxxxxx>
> ---
> drivers/crypto/qce/sha.c | 84 +++++++++++++++++++++++++++++++++++++++++++++++-
> drivers/crypto/qce/sha.h | 1 +
> 2 files changed, 84 insertions(+), 1 deletion(-)

There is no need to allocate fallbacks anymore because the Crypto
API now does it unconditionally.

Please see aspeed for an example on how to use the fallback.

Cheers,
--
Email: Herbert Xu <herbert@xxxxxxxxxxxxxxxxxxx>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt