[PATCH v7 10/14] nvme-auth: allow to specify the key by key serial

Hannes Reinecke hare at kernel.org
Thu Nov 26 06:12:28 PST 2026


Update nvme_auth_extract_key() to accept a key serial
number in addition to the existing input formats.

Signed-off-by: Hannes Reinecke <hare at kernel.org>
---
 drivers/nvme/common/auth.c | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/drivers/nvme/common/auth.c b/drivers/nvme/common/auth.c
index 15e72fe8868af5698809cd6634a1f1f1da11ca2d..e336c698437dcea4d7ce4c435efda0b9f26eb63d 100644
--- a/drivers/nvme/common/auth.c
+++ b/drivers/nvme/common/auth.c
@@ -148,7 +148,7 @@ EXPORT_SYMBOL_GPL(nvme_auth_hmac_hash_len);
  * @generated: indicate whether a key has been generated
  *
  * Extracts or generates a key from @input.
- * @input can either be a key description or raw key data; in
+ * @input can be a key serial, a key description or raw key data; in
  * the latter case a key is generated from @input and
  * @generated is set to 'true'.
  *
@@ -158,7 +158,18 @@ struct key *nvme_auth_extract_key(const char *input, size_t input_len,
 				  bool *generated)
 {
 	struct key *key;
-
+	unsigned long key_serial;
+	int err;
+
+	/* Check if @input is a key serial */
+	err = kstrtoul(input, 0, &key_serial);
+	if (!err) {
+		key = key_lookup(key_serial);
+		if (!IS_ERR(key)) {
+			*generated = false;
+			return key;
+		}
+	}
 	/* Check if @input is a key description */
 	key = nvme_dhchap_psk_lookup(input);
 	if (!IS_ERR(key)) {

-- 
2.51.0




More information about the Linux-nvme mailing list