[PATCH 2/4] crypto: Add back the lost FIPS key length check to the hmac(sha1) algorithm
From: Thomas Huth
Date: Tue Dec 01 2026 - 13:47:47 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(sha1) algorithm was implemented via
libcrypto. Thus add the key length check to the crypto/sha1.c file, too,
to be compliant again with the FIPS requirements.
Fixes: 8bc79ab67d78e ("crypto: sha1 - Wrap library and add HMAC support")
Signed-off-by: Thomas Huth <thuth@xxxxxxxxxx>
---
crypto/sha1.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/crypto/sha1.c b/crypto/sha1.c
index 4fbf61cf03709..83eb405f011f0 100644
--- a/crypto/sha1.c
+++ b/crypto/sha1.c
@@ -9,6 +9,7 @@
*/
#include <crypto/internal/hash.h>
#include <crypto/sha1.h>
+#include <linux/fips.h>
#include <linux/kernel.h>
#include <linux/module.h>
@@ -122,6 +123,9 @@ static int crypto_sha1_import_core(struct shash_desc *desc, const void *in)
static int crypto_hmac_sha1_setkey(struct crypto_shash *tfm,
const u8 *raw_key, unsigned int keylen)
{
+ if (fips_hmac_keylen_disallowed(keylen))
+ return -EINVAL;
+
hmac_sha1_preparekey(HMAC_SHA1_KEY(tfm), raw_key, keylen);
return 0;
}
--
2.56.1