The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* [PATCH 0/4] crypto: Add back the lost FIPS key length checks to the  hmac(sha*) algorithms
@ 2026-12-01 18:47 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
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: Thomas Huth @ 2026-12-01 18:47 UTC (permalink / raw)
  To: Herbert Xu, linux-crypto; +Cc: David S. Miller, Eric Biggers, linux-kernel

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(sha*) algorithms were implemented via
libcrypto. Thus add the key length check to the crypto/sha*.c files, too,
to be compliant again with the FIPS requirements.

(I've fixed each file in a separate patch to ease backporting if required)

Thomas Huth (4):
  crypto: Add a wrapper function for checking the HMAC key length in
    FIPS mode
  crypto: Add back the lost FIPS key length check to the hmac(sha1)
    algorithm
  crypto: Add back the lost FIPS key length check to the hmac(sha256)
    algorithm
  crypto: Add back the lost FIPS key length check to the hmac(sha512)
    algorithm

 crypto/hmac.c        | 2 +-
 crypto/sha1.c        | 4 ++++
 crypto/sha256.c      | 7 +++++++
 crypto/sha512.c      | 7 +++++++
 include/linux/fips.h | 9 +++++++++
 5 files changed, 28 insertions(+), 1 deletion(-)

-- 
2.56.1


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 1/4] crypto: Add a wrapper function for checking the HMAC key length in FIPS mode
  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 ` 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
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Thomas Huth @ 2026-12-01 18:47 UTC (permalink / raw)
  To: Herbert Xu, linux-crypto; +Cc: David S. Miller, Eric Biggers, linux-kernel

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@redhat.com>
---
 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


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 2/4] crypto: Add back the lost FIPS key length check to the hmac(sha1) algorithm
  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:47 ` 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
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Thomas Huth @ 2026-12-01 18:47 UTC (permalink / raw)
  To: Herbert Xu, linux-crypto; +Cc: David S. Miller, Eric Biggers, linux-kernel

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@redhat.com>
---
 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


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 3/4] crypto: Add back the lost FIPS key length check to the hmac(sha256) algorithm
  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: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 ` Thomas Huth
  2026-12-01 18:47 ` [PATCH 4/4] crypto: Add back the lost FIPS key length check to the hmac(sha512) algorithm Thomas Huth
  2026-12-01 20:21 ` [PATCH 0/4] crypto: Add back the lost FIPS key length checks to the hmac(sha*) algorithms Eric Biggers
  4 siblings, 0 replies; 6+ messages in thread
From: Thomas Huth @ 2026-12-01 18:47 UTC (permalink / raw)
  To: Herbert Xu, linux-crypto; +Cc: David S. Miller, Eric Biggers, linux-kernel

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(sha256) algorithm was implemented via
libcrypto. Thus add the key length check to the crypto/sha256.c file,
too, to be compliant again with the FIPS requirements.

Fixes: e0cd371691038 ("crypto: sha256 - Wrap library and add HMAC support")
Signed-off-by: Thomas Huth <thuth@redhat.com>
---
 crypto/sha256.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/crypto/sha256.c b/crypto/sha256.c
index fb81defe084c6..a27fc5ca1f92d 100644
--- a/crypto/sha256.c
+++ b/crypto/sha256.c
@@ -10,6 +10,7 @@
  */
 #include <crypto/internal/hash.h>
 #include <crypto/sha2.h>
+#include <linux/fips.h>
 #include <linux/kernel.h>
 #include <linux/module.h>
 
@@ -187,6 +188,9 @@ static int crypto_sha256_import_core(struct shash_desc *desc, const void *in)
 static int crypto_hmac_sha224_setkey(struct crypto_shash *tfm,
 				     const u8 *raw_key, unsigned int keylen)
 {
+	if (fips_hmac_keylen_disallowed(keylen))
+		return -EINVAL;
+
 	hmac_sha224_preparekey(HMAC_SHA224_KEY(tfm), raw_key, keylen);
 	return 0;
 }
@@ -254,6 +258,9 @@ static int crypto_hmac_sha224_import_core(struct shash_desc *desc,
 static int crypto_hmac_sha256_setkey(struct crypto_shash *tfm,
 				     const u8 *raw_key, unsigned int keylen)
 {
+	if (fips_hmac_keylen_disallowed(keylen))
+		return -EINVAL;
+
 	hmac_sha256_preparekey(HMAC_SHA256_KEY(tfm), raw_key, keylen);
 	return 0;
 }
-- 
2.56.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 4/4] crypto: Add back the lost FIPS key length check to the hmac(sha512) algorithm
  2026-12-01 18:47 [PATCH 0/4] crypto: Add back the lost FIPS key length checks to the hmac(sha*) algorithms Thomas Huth
                   ` (2 preceding siblings ...)
  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
  2026-12-01 20:21 ` [PATCH 0/4] crypto: Add back the lost FIPS key length checks to the hmac(sha*) algorithms Eric Biggers
  4 siblings, 0 replies; 6+ messages in thread
From: Thomas Huth @ 2026-12-01 18:47 UTC (permalink / raw)
  To: Herbert Xu, linux-crypto; +Cc: David S. Miller, Eric Biggers, linux-kernel

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


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH 0/4] crypto: Add back the lost FIPS key length checks to the hmac(sha*) algorithms
  2026-12-01 18:47 [PATCH 0/4] crypto: Add back the lost FIPS key length checks to the hmac(sha*) algorithms Thomas Huth
                   ` (3 preceding siblings ...)
  2026-12-01 18:47 ` [PATCH 4/4] crypto: Add back the lost FIPS key length check to the hmac(sha512) algorithm Thomas Huth
@ 2026-12-01 20:21 ` Eric Biggers
  4 siblings, 0 replies; 6+ messages in thread
From: Eric Biggers @ 2026-12-01 20:21 UTC (permalink / raw)
  To: Thomas Huth; +Cc: Herbert Xu, linux-crypto, David S. Miller, linux-kernel

On Tue, Dec 01, 2026 at 07:47:18PM +0100, Thomas Huth wrote:
> 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(sha*) algorithms were implemented via
> libcrypto. Thus add the key length check to the crypto/sha*.c files, too,
> to be compliant again with the FIPS requirements.
> 
> (I've fixed each file in a separate patch to ease backporting if required)
> 
> Thomas Huth (4):
>   crypto: Add a wrapper function for checking the HMAC key length in
>     FIPS mode
>   crypto: Add back the lost FIPS key length check to the hmac(sha1)
>     algorithm
>   crypto: Add back the lost FIPS key length check to the hmac(sha256)
>     algorithm
>   crypto: Add back the lost FIPS key length check to the hmac(sha512)
>     algorithm
> 
>  crypto/hmac.c        | 2 +-
>  crypto/sha1.c        | 4 ++++
>  crypto/sha256.c      | 7 +++++++
>  crypto/sha512.c      | 7 +++++++
>  include/linux/fips.h | 9 +++++++++
>  5 files changed, 28 insertions(+), 1 deletion(-)

Note that many FIPS modules implement HMAC without this check.  Also,
even after this patchset, not all hmac(sha*) implementations in the
kernel do this check (and for s390, this is the first time the check
will have ever been present).  And anytime HMAC is used as an entropy
extractor, like in HKDF, this check looks at the wrong length.

So from a technical perspective, it's hard to evaluate this patchset.
It doesn't help that the commit messages only include vague references
to "FIPS compliance".

That being said, if this patchset is really necessary and sufficient to
make the specific FIPS lab you are using happy (which presumably is the
real reason, that was not explicitly stated in the patchset), I am okay
with it.  At least it's less intrusive than other potential changes.

What is inevitably going to happen, though, is that the Fixes tags are
going to result in this being backported to 6.18.y, where they will
reintroduce the regression where the kernel fails to boot with fips=1
due to the HKDF self-test failure.

And failure to boot is a real issue that people actually care about, as
was quite clear when it happened last time!  (Also, it seems that the
distros that offer fips=1 don't yet have testing in place to detect such
issues preemptively.)

So I would strongly recommend leaving a note in the commit message about
the 6.18.y backporting pitfall.  Otherwise it will likely get backported
without considering that and reintroduce the fips=1 boot failure.

- Eric

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2026-12-01 20:21 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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: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 ` [PATCH 4/4] crypto: Add back the lost FIPS key length check to the hmac(sha512) algorithm Thomas Huth
2026-12-01 20:21 ` [PATCH 0/4] crypto: Add back the lost FIPS key length checks to the hmac(sha*) algorithms Eric Biggers

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox