Skip to contentSkip to conversation

crypto/hkdf: Skip tests with keys too short in FIPS mode

RFC PATCH In review Li Tian 2 participants 4 messages Dec 5, 2025 – Dec 17, 2025 Crypto API

lore
Share & tools
lore

Li Tian

author
#0 lore raw

RFC PATCH 1/1 crypto/hkdf: Skip tests with keys too short in FIPS mode

FIPS mode mandates the keys to _setkey should be longer than 14 bytes. It's up to the callers to not use keys too short.

---
 crypto/hkdf.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
crypto/hkdf.c +7 -1
index 82d1b32ca6ce..73d318f3f677 100644
@@ -10,6 +10,7 @@
 #include <crypto/internal/hash.h>
 #include <crypto/sha2.h>
 #include <crypto/hkdf.h>
+#include <linux/fips.h>
 #include <linux/module.h>
 
 /*
@@ -462,7 +463,12 @@ static const struct hkdf_testvec hkdf_sha512_tv[] = {
 };
 
 static int hkdf_test(const char *shash, const struct hkdf_testvec *tv)
-{	struct crypto_shash *tfm = NULL;
+{
+	/* Skip the tests with keys too short in FIPS mode */
+	if (fips_enabled && (tv->salt_size < 112 / 8))
+		return 0;
+
+	struct crypto_shash *tfm = NULL;
 	u8 *prk = NULL, *okm = NULL;
 	unsigned int prk_size;
 	const char *driver;
Signature · 1 line
2.50.0
#1 lore raw
Quoted 21 lines · Li Tian

FIPS mode mandates the keys to _setkey should be longer than 14 bytes. It's up to the callers to not use keys too short.

---
 crypto/hkdf.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
crypto/hkdf.c +1 -0
index 82d1b32ca6ce..73d318f3f677 100644
@@ -10,6 +10,7 @@
 #include <crypto/internal/hash.h>
 #include <crypto/sha2.h>
 #include <crypto/hkdf.h>
+#include <linux/fips.h>
 #include <linux/module.h>
 
 /*

crypto/hkdf.c static const struct hkdf_testvec hkdf_sha512_tv[] = { · line 470

Quoted 9 lines
crypto/hkdf.c +5 -1
@@ -462,7 +463,12 @@ static const struct hkdf_testvec hkdf_sha512_tv[] = {
 };
 
 static int hkdf_test(const char *shash, const struct hkdf_testvec *tv)
-{	struct crypto_shash *tfm = NULL;
+{
+	/* Skip the tests with keys too short in FIPS mode */
+	if (fips_enabled && (tv->salt_size < 112 / 8))
+		return 0;
+

As I've explained before, in HKDF the secret is in the input keying material, not the salt.

What problem are you trying to solve?

- Eric

author
#2 lore raw
Quoted 1 line · Eric Biggers

What problem are you trying to solve?

Eric, as you've said "keylen < 14 check in the new version in crypto/sha256.c." was forgotten.
IMHO, it deserves recovery in terms of FIPS. And by the time the check is restored, the hkdf_test
cases failure will likely surface again. Hence the skipping in this proposal.

Li Tian

#3 lore raw
Quoted 10 lines · Li Tian
Quoted 1 line · Eric Biggers

What problem are you trying to solve?

Eric, as you've said "keylen < 14 check in the new version in crypto/sha256.c." was forgotten.
IMHO, it deserves recovery in terms of FIPS. And by the time the check is restored, the hkdf_test
cases failure will likely surface again. Hence the skipping in this proposal.

Li Tian

Sure, but there's no reason to consider this patch unless the incorrect and problematic keylen check is added back in.

- Eric