From: Thomas Huth <thuth@redhat.com>
To: Herbert Xu <herbert@gondor.apana.org.au>, linux-crypto@vger.kernel.org
Cc: "David S. Miller" <davem@davemloft.net>,
Eric Biggers <ebiggers@kernel.org>,
linux-kernel@vger.kernel.org
Subject: [PATCH 4/4] crypto: Add back the lost FIPS key length check to the hmac(sha512) algorithm
Date: Tue, 1 Dec 2026 19:47:22 +0100 [thread overview]
Message-ID: <20261201184722.887139-5-thuth@redhat.com> (raw)
In-Reply-To: <20261201184722.887139-1-thuth@redhat.com>
The generic code in hmac_setkey() in crypto/hmac.c correctly rejects
keys with less than 112 bits in FIPS-compliance mode. However, this
check got lost when the hmac(sha512) algorithm was implemented via
libcrypto. Thus add the key length check to the crypto/sh512.c file,
too, to be compliant again with the FIPS requirements.
Fixes: 469acaa12502e ("crypto: sha512 - Replace sha512_generic with wrapper around SHA-512 library")
Signed-off-by: Thomas Huth <thuth@redhat.com>
---
crypto/sha512.c | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/crypto/sha512.c b/crypto/sha512.c
index d320fe53913fa..4551f4bd31830 100644
--- a/crypto/sha512.c
+++ b/crypto/sha512.c
@@ -9,6 +9,7 @@
*/
#include <crypto/internal/hash.h>
#include <crypto/sha2.h>
+#include <linux/fips.h>
#include <linux/kernel.h>
#include <linux/module.h>
@@ -193,6 +194,9 @@ static int crypto_sha512_import_core(struct shash_desc *desc, const void *in)
static int crypto_hmac_sha384_setkey(struct crypto_shash *tfm,
const u8 *raw_key, unsigned int keylen)
{
+ if (fips_hmac_keylen_disallowed(keylen))
+ return -EINVAL;
+
hmac_sha384_preparekey(HMAC_SHA384_KEY(tfm), raw_key, keylen);
return 0;
}
@@ -260,6 +264,9 @@ static int crypto_hmac_sha384_import_core(struct shash_desc *desc,
static int crypto_hmac_sha512_setkey(struct crypto_shash *tfm,
const u8 *raw_key, unsigned int keylen)
{
+ if (fips_hmac_keylen_disallowed(keylen))
+ return -EINVAL;
+
hmac_sha512_preparekey(HMAC_SHA512_KEY(tfm), raw_key, keylen);
return 0;
}
--
2.56.1
next prev parent reply other threads:[~2026-12-01 18:47 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-01 18:47 [PATCH 0/4] crypto: Add back the lost FIPS key length checks to the hmac(sha*) algorithms Thomas Huth
2026-12-01 18:47 ` [PATCH 1/4] crypto: Add a wrapper function for checking the HMAC key length in FIPS mode Thomas Huth
2026-12-01 18:52 ` sashiko-bot
2026-12-01 19:07 ` Thomas Huth
2026-12-01 18:47 ` [PATCH 2/4] crypto: Add back the lost FIPS key length check to the hmac(sha1) algorithm Thomas Huth
2026-12-01 18:47 ` [PATCH 3/4] crypto: Add back the lost FIPS key length check to the hmac(sha256) algorithm Thomas Huth
2026-12-01 18:47 ` Thomas Huth [this message]
2026-12-01 20:21 ` [PATCH 0/4] crypto: Add back the lost FIPS key length checks to the hmac(sha*) algorithms Eric Biggers
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=20261201184722.887139-5-thuth@redhat.com \
--to=thuth@redhat.com \
--cc=davem@davemloft.net \
--cc=ebiggers@kernel.org \
--cc=herbert@gondor.apana.org.au \
--cc=linux-crypto@vger.kernel.org \
--cc=linux-kernel@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.