[PATCH 4/4] crypto: Add back the lost FIPS key length check to the hmac(sha512) algorithm

From: Thomas Huth

Date: Tue Dec 01 2026 - 13:47:58 EST


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@xxxxxxxxxx>
---
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