summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Biggers <ebiggers@kernel.org>2026-03-01 23:59:39 -0800
committerKeith Busch <kbusch@kernel.org>2026-03-27 07:35:00 -0700
commit9100a28c8bb4270744942cf834efcd80f1acda7d (patch)
tree832e5b2cd3358cd448a9909415690ecaf1c1879f
parent67807fbaf12719fca46a622d759484652b79c7c3 (diff)
nvme-auth: add NVME_AUTH_MAX_DIGEST_SIZE constant
Define a NVME_AUTH_MAX_DIGEST_SIZE constant and use it in the appropriate places. Acked-by: Ard Biesheuvel <ardb@kernel.org> Acked-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Hannes Reinecke <hare@suse.de> Signed-off-by: Eric Biggers <ebiggers@kernel.org> Signed-off-by: Keith Busch <kbusch@kernel.org>
-rw-r--r--drivers/nvme/common/auth.c6
-rw-r--r--drivers/nvme/host/auth.c6
-rw-r--r--include/linux/nvme.h5
3 files changed, 10 insertions, 7 deletions
diff --git a/drivers/nvme/common/auth.c b/drivers/nvme/common/auth.c
index e07e7d4bf8b6..78d751481fe3 100644
--- a/drivers/nvme/common/auth.c
+++ b/drivers/nvme/common/auth.c
@@ -15,8 +15,6 @@
#include <linux/nvme.h>
#include <linux/nvme-auth.h>
-#define HKDF_MAX_HASHLEN 64
-
static u32 nvme_dhchap_seqnum;
static DEFINE_MUTEX(nvme_dhchap_mutex);
@@ -769,7 +767,7 @@ int nvme_auth_derive_tls_psk(int hmac_id, u8 *psk, size_t psk_len,
struct crypto_shash *hmac_tfm;
const char *hmac_name;
const char *label = "nvme-tls-psk";
- static const char default_salt[HKDF_MAX_HASHLEN];
+ static const char default_salt[NVME_AUTH_MAX_DIGEST_SIZE];
size_t prk_len;
const char *ctx;
unsigned char *prk, *tls_key;
@@ -798,7 +796,7 @@ int nvme_auth_derive_tls_psk(int hmac_id, u8 *psk, size_t psk_len,
goto out_free_shash;
}
- if (WARN_ON(prk_len > HKDF_MAX_HASHLEN)) {
+ if (WARN_ON(prk_len > NVME_AUTH_MAX_DIGEST_SIZE)) {
ret = -EINVAL;
goto out_free_prk;
}
diff --git a/drivers/nvme/host/auth.c b/drivers/nvme/host/auth.c
index 405e7c03b1cf..301c858b7c57 100644
--- a/drivers/nvme/host/auth.c
+++ b/drivers/nvme/host/auth.c
@@ -38,9 +38,9 @@ struct nvme_dhchap_queue_context {
u8 hash_id;
u8 sc_c;
size_t hash_len;
- u8 c1[64];
- u8 c2[64];
- u8 response[64];
+ u8 c1[NVME_AUTH_MAX_DIGEST_SIZE];
+ u8 c2[NVME_AUTH_MAX_DIGEST_SIZE];
+ u8 response[NVME_AUTH_MAX_DIGEST_SIZE];
u8 *ctrl_key;
u8 *host_key;
u8 *sess_key;
diff --git a/include/linux/nvme.h b/include/linux/nvme.h
index 655d194f8e72..edfebbce6745 100644
--- a/include/linux/nvme.h
+++ b/include/linux/nvme.h
@@ -1837,6 +1837,11 @@ enum {
NVME_AUTH_HASH_INVALID = 0xff,
};
+/* Maximum digest size for any NVME_AUTH_HASH_* value */
+enum {
+ NVME_AUTH_MAX_DIGEST_SIZE = 64,
+};
+
/* Defined Diffie-Hellman group identifiers for DH-HMAC-CHAP authentication */
enum {
NVME_AUTH_DHGROUP_NULL = 0x00,