[PATCH 1/4] crypto: Add a wrapper function for checking the HMAC key length in FIPS mode
From: Thomas Huth
Date: Tue Dec 01 2026 - 13:47:40 EST
We are going to need this check in multiple locations. To avoid that
we have to update each location in the future in case of changes in
the FIPS requirements, let's introduce a proper wrapper function for
this check first.
Signed-off-by: Thomas Huth <thuth@xxxxxxxxxx>
---
crypto/hmac.c | 2 +-
include/linux/fips.h | 9 +++++++++
2 files changed, 10 insertions(+), 1 deletion(-)
diff --git a/crypto/hmac.c b/crypto/hmac.c
index 807e08b252c55..53ed48deb4b5a 100644
--- a/crypto/hmac.c
+++ b/crypto/hmac.c
@@ -246,7 +246,7 @@ static int hmac_setkey_ahash(struct crypto_ahash *parent,
u8 *ipad = &tctx->pads[0];
int err, i;
- if (fips_enabled && (keylen < 112 / 8))
+ if (fips_hmac_keylen_disallowed(keylen))
return -EINVAL;
ahash_request_set_callback(req, 0, NULL, NULL);
diff --git a/include/linux/fips.h b/include/linux/fips.h
index c6961e932fef3..75b9ed6ec49be 100644
--- a/include/linux/fips.h
+++ b/include/linux/fips.h
@@ -2,17 +2,26 @@
#ifndef _FIPS_H
#define _FIPS_H
+#include <linux/types.h>
+
#ifdef CONFIG_CRYPTO_FIPS
extern int fips_enabled;
extern struct atomic_notifier_head fips_fail_notif_chain;
void fips_fail_notify(void);
+static inline bool fips_hmac_keylen_disallowed(unsigned int keylen)
+{
+ return fips_enabled && keylen < 112 / 8;
+}
+
#else
#define fips_enabled 0
static inline void fips_fail_notify(void) {}
+#define fips_hmac_keylen_disallowed(x) false
+
#endif
#endif
--
2.56.1