* [PATCH v2 0/4] crypto: fips - Add back the lost key length checks to the hmac(sha*) algorithms
@ 2026-12-03 9:33 Thomas Huth
2026-12-03 9:33 ` [PATCH v2 1/4] crypto: fips - Add a wrapper function for checking the HMAC key length Thomas Huth
` (4 more replies)
0 siblings, 5 replies; 6+ messages in thread
From: Thomas Huth @ 2026-12-03 9:33 UTC (permalink / raw)
To: Herbert Xu, linux-crypto
Cc: David S. Miller, Eric Biggers, linux-kernel, stable
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
the crypto library.
We noticed this behavioral change after backporting the corresponding
commits to an older kernel branch: One of our downstream tests checks
whether setting key length with less than 112 bits works in fips_enabled
mode, and this test started failing. Thus let's restore the same behavior
from kernel v6.16 and earlier by adding the key length check to the
crypto/sha*.c files, too.
Note: Please don't backport these patches to any kernel before 6.19, see:
https://lore.kernel.org/linux-crypto/20261201202148.GA501764@google.com/
v2:
- Moved the helper in the first patch out of the #ifdef and removed
superfluous macro
- Reworked patch descriptions and added notes to not backport this
to the 6.18 stable trees
Thomas Huth (4):
crypto: fips - Add a wrapper function for checking the HMAC key length
crypto: fips - Add back the lost key length check to the hmac(sha1)
algorithm
crypto: fips - Add back the lost key length check to the hmac(sha256)
algorithm
crypto: fips - Add back the lost key length check to the hmac(sha512)
algorithm
crypto/hmac.c | 4 ++--
crypto/sha1.c | 4 ++++
crypto/sha256.c | 7 +++++++
crypto/sha512.c | 7 +++++++
include/linux/fips.h | 7 +++++++
5 files changed, 27 insertions(+), 2 deletions(-)
--
2.56.1
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH v2 1/4] crypto: fips - Add a wrapper function for checking the HMAC key length
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
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
` (3 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: Thomas Huth @ 2026-12-03 9:33 UTC (permalink / raw)
To: Herbert Xu, linux-crypto
Cc: David S. Miller, Eric Biggers, linux-kernel, stable
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
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH v2 2/4] crypto: fips - Add back the lost key length check to the hmac(sha1) algorithm
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 ` [PATCH v2 1/4] crypto: fips - Add a wrapper function for checking the HMAC key length Thomas Huth
@ 2026-12-03 9:33 ` Thomas Huth
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
` (2 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: Thomas Huth @ 2026-12-03 9:33 UTC (permalink / raw)
To: Herbert Xu, linux-crypto
Cc: David S. Miller, Eric Biggers, linux-kernel, stable
The generic code in hmac_setkey() in crypto/hmac.c rejects keys with
less than 112 bits in FIPS-compliance mode. However, this check got
lost when the hmac(sha1) algorithm was implemented via the crypto
library. Let's restore the same behavior from kernel v6.16 and earlier
by adding the key length check to the crypto/sha1.c file, too.
Cc: stable@vger.kernel.org # 6.19+, see https://lore.kernel.org/all/20261201202148.GA501764@google.com/
Fixes: 8bc79ab67d78e ("crypto: sha1 - Wrap library and add HMAC support")
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/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 v2 3/4] crypto: fips - Add back the lost key length check to the hmac(sha256) algorithm
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 ` [PATCH v2 1/4] crypto: fips - Add a wrapper function for checking the HMAC key length Thomas Huth
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:33 ` 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
2026-12-03 20:25 ` [PATCH v2 0/4] crypto: fips - Add back the lost key length checks to the hmac(sha*) algorithms Eric Biggers
4 siblings, 0 replies; 6+ messages in thread
From: Thomas Huth @ 2026-12-03 9:33 UTC (permalink / raw)
To: Herbert Xu, linux-crypto
Cc: David S. Miller, Eric Biggers, linux-kernel, stable
The generic code in hmac_setkey() in crypto/hmac.c rejects keys with
less than 112 bits in FIPS-compliance mode. However, this check got
lost when the hmac(sha224) and hmac(sha256) algorithms were implemented
via the crypto library. Let's restore the same behavior from kernel v6.16
and earlier by adding the key length check to the crypto/sha256.c file,
too.
Cc: stable@vger.kernel.org # 6.19+, see https://lore.kernel.org/all/20261201202148.GA501764@google.com/
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 v2 4/4] crypto: fips - Add back the lost key length check to the hmac(sha512) algorithm
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
` (2 preceding siblings ...)
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 ` Thomas Huth
2026-12-03 20:25 ` [PATCH v2 0/4] crypto: fips - Add back the lost key length checks to the hmac(sha*) algorithms Eric Biggers
4 siblings, 0 replies; 6+ messages in thread
From: Thomas Huth @ 2026-12-03 9:33 UTC (permalink / raw)
To: Herbert Xu, linux-crypto
Cc: David S. Miller, Eric Biggers, linux-kernel, stable
The generic code in hmac_setkey() in crypto/hmac.c rejects keys with
less than 112 bits in FIPS-compliance mode. However, this check got
lost when the hmac(sha384) and hmac(sha512) algorithms were implemented
via the crypto library. Let's restore the same behavior from kernel v6.16
and earlier by adding the key length check to the crypto/sha512.c file,
too.
Cc: stable@vger.kernel.org # 6.19+, see https://lore.kernel.org/all/20261201202148.GA501764@google.com/
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 v2 0/4] crypto: fips - Add back the lost key length checks to the hmac(sha*) algorithms
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
` (3 preceding siblings ...)
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
@ 2026-12-03 20:25 ` Eric Biggers
4 siblings, 0 replies; 6+ messages in thread
From: Eric Biggers @ 2026-12-03 20:25 UTC (permalink / raw)
To: Thomas Huth
Cc: Herbert Xu, linux-crypto, David S. Miller, linux-kernel, stable
On Thu, Dec 03, 2026 at 10:33:12AM +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
> the crypto library.
>
> We noticed this behavioral change after backporting the corresponding
> commits to an older kernel branch: One of our downstream tests checks
> whether setting key length with less than 112 bits works in fips_enabled
> mode, and this test started failing. Thus let's restore the same behavior
> from kernel v6.16 and earlier by adding the key length check to the
> crypto/sha*.c files, too.
>
> Note: Please don't backport these patches to any kernel before 6.19, see:
> https://lore.kernel.org/linux-crypto/20261201202148.GA501764@google.com/
>
> v2:
> - Moved the helper in the first patch out of the #ifdef and removed
> superfluous macro
> - Reworked patch descriptions and added notes to not backport this
> to the 6.18 stable trees
>
> Thomas Huth (4):
> crypto: fips - Add a wrapper function for checking the HMAC key length
> crypto: fips - Add back the lost key length check to the hmac(sha1)
> algorithm
> crypto: fips - Add back the lost key length check to the hmac(sha256)
> algorithm
> crypto: fips - Add back the lost key length check to the hmac(sha512)
> algorithm
Acked-by: Eric Biggers <ebiggers@kernel.org>
- Eric
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2026-12-03 20:25 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 ` [PATCH v2 1/4] crypto: fips - Add a wrapper function for checking the HMAC key length Thomas Huth
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: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
2026-12-03 20:25 ` [PATCH v2 0/4] crypto: fips - Add back the lost 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