Linux cryptographic layer development
 help / color / mirror / Atom feed
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, stable@vger.kernel.org
Subject: [PATCH v2 1/4] crypto: fips - Add a wrapper function for checking the HMAC key length
Date: Thu,  3 Dec 2026 10:33:13 +0100	[thread overview]
Message-ID: <20261203093316.97847-2-thuth@redhat.com> (raw)
In-Reply-To: <20261203093316.97847-1-thuth@redhat.com>

We are going to need this check in multiple locations. To avoid having
to update each location separately if the FIPS requirements change,
introduce a common helper function first..

Cc: stable@vger.kernel.org # 6.19+, prerequisite for the following patches
Signed-off-by: Thomas Huth <thuth@redhat.com>
---
 Note: Please don't backport this patch to any kernel before 6.19, see:
 https://lore.kernel.org/linux-crypto/20261201202148.GA501764@google.com/

 crypto/hmac.c        | 4 ++--
 include/linux/fips.h | 7 +++++++
 2 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/crypto/hmac.c b/crypto/hmac.c
index 807e08b252c55..bfa5225a79990 100644
--- a/crypto/hmac.c
+++ b/crypto/hmac.c
@@ -45,7 +45,7 @@ static int hmac_setkey(struct crypto_shash *parent,
 	SHASH_DESC_ON_STACK(shash, hash);
 	int err, i;
 
-	if (fips_enabled && (keylen < 112 / 8))
+	if (fips_hmac_keylen_disallowed(keylen))
 		return -EINVAL;
 
 	shash->tfm = hash;
@@ -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..17e7ae747c485 100644
--- a/include/linux/fips.h
+++ b/include/linux/fips.h
@@ -2,6 +2,8 @@
 #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;
@@ -15,4 +17,9 @@ static inline void fips_fail_notify(void) {}
 
 #endif
 
+static inline bool fips_hmac_keylen_disallowed(unsigned int keylen)
+{
+	return fips_enabled && keylen < 112 / 8;
+}
+
 #endif
-- 
2.56.1


  reply	other threads:[~2026-12-03  9:33 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-03  9:33 [PATCH v2 0/4] crypto: fips - Add back the lost key length checks to the hmac(sha*) algorithms Thomas Huth
2026-12-03  9:33 ` Thomas Huth [this message]
2026-12-03  9:33 ` [PATCH v2 2/4] crypto: fips - Add back the lost key length check to the hmac(sha1) algorithm Thomas Huth
2026-12-03  9:50   ` sashiko-bot
2026-12-03  9:33 ` [PATCH v2 3/4] crypto: fips - Add back the lost key length check to the hmac(sha256) algorithm Thomas Huth
2026-12-03  9:33 ` [PATCH v2 4/4] crypto: fips - Add back the lost key length check to the hmac(sha512) algorithm Thomas Huth

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=20261203093316.97847-2-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 \
    --cc=stable@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox