]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
nvme-auth: add NVME_AUTH_MAX_DIGEST_SIZE constant
authorEric Biggers <ebiggers@kernel.org>
Mon, 2 Mar 2026 07:59:39 +0000 (23:59 -0800)
committerKeith Busch <kbusch@kernel.org>
Fri, 27 Mar 2026 14:35:00 +0000 (07:35 -0700)
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>
drivers/nvme/common/auth.c
drivers/nvme/host/auth.c
include/linux/nvme.h

index e07e7d4bf8b687bfb831e63ac299eba66f9356af..78d751481fe31c4845eb05dce41c2f4edfc1d29f 100644 (file)
@@ -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;
        }
index 405e7c03b1cfe027a85e4e5e85937e412e2b5a31..301c858b7c5771cb9dab63855b8abcdf13a043ec 100644 (file)
@@ -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;
index 655d194f8e722c3400ac00f76841e1af0281f38f..edfebbce6745338eb938166b50502a861f358a99 100644 (file)
@@ -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,