[PATCH v2 0/4] crypto: fips - Add back the lost key length checks to the hmac(sha*) algorithms

From: Thomas Huth

Date: Thu Dec 03 2026 - 04:33:32 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(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@xxxxxxxxxx/

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