drivers/nvme/common/auth.c
Source file repositories/reference/linux-study-clean/drivers/nvme/common/auth.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/nvme/common/auth.c- Extension
.c- Size
- 21411 bytes
- Lines
- 783
- Domain
- Representative Device Path
- Bucket
- PCIe NVMe Storage Path
- Inferred role
- Representative Device Path: exported/initcall integration point
- Status
- integration implementation candidate
Why This File Exists
Part of the selected hardware vertical slice: PCI discovery, driver binding, NVMe queues, block requests, DMA, interrupts, and completion.
- Part of the selected hardware vertical slice: PCI discovery, driver binding, NVMe queues, block requests, DMA, interrupts, and completion.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/module.hlinux/crc32.hlinux/base64.hlinux/prandom.hlinux/scatterlist.hlinux/unaligned.hcrypto/dh.hcrypto/sha2.hlinux/nvme.hlinux/nvme-auth.h
Detected Declarations
function nvme_auth_get_seqnumfunction nvme_auth_dhgroup_idfunction nvme_auth_hmac_idfunction nvme_auth_hmac_hash_lenfunction nvme_auth_key_struct_sizefunction nvme_auth_free_keyfunction nvme_auth_hmac_finalfunction nvme_auth_hmac_updatefunction nvme_auth_hmac_finalfunction nvme_auth_hmacfunction nvme_auth_hashfunction nvme_auth_augmented_challengefunction nvme_auth_gen_privkeyfunction nvme_auth_gen_pubkeyfunction nvme_auth_gen_session_keyfunction nvme_auth_parse_keyfunction Hfunction nvme_auth_generate_digestfunction digestexport nvme_auth_get_seqnumexport nvme_auth_dhgroup_nameexport nvme_auth_dhgroup_kppexport nvme_auth_dhgroup_idexport nvme_auth_hmac_nameexport nvme_auth_hmac_idexport nvme_auth_hmac_hash_lenexport nvme_auth_key_struct_sizeexport nvme_auth_extract_keyexport nvme_auth_alloc_keyexport nvme_auth_free_keyexport nvme_auth_hmac_initexport nvme_auth_hmac_updateexport nvme_auth_hmac_finalexport nvme_auth_transform_keyexport nvme_auth_augmented_challengeexport nvme_auth_gen_privkeyexport nvme_auth_gen_pubkeyexport nvme_auth_gen_session_keyexport nvme_auth_parse_keyexport nvme_auth_generate_pskexport nvme_auth_generate_digestexport nvme_auth_derive_tls_psk
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (c) 2020 Hannes Reinecke, SUSE Linux
*/
#include <linux/module.h>
#include <linux/crc32.h>
#include <linux/base64.h>
#include <linux/prandom.h>
#include <linux/scatterlist.h>
#include <linux/unaligned.h>
#include <crypto/dh.h>
#include <crypto/sha2.h>
#include <linux/nvme.h>
#include <linux/nvme-auth.h>
static u32 nvme_dhchap_seqnum;
static DEFINE_MUTEX(nvme_dhchap_mutex);
u32 nvme_auth_get_seqnum(void)
{
u32 seqnum;
mutex_lock(&nvme_dhchap_mutex);
if (!nvme_dhchap_seqnum)
nvme_dhchap_seqnum = get_random_u32();
else {
nvme_dhchap_seqnum++;
if (!nvme_dhchap_seqnum)
nvme_dhchap_seqnum++;
}
seqnum = nvme_dhchap_seqnum;
mutex_unlock(&nvme_dhchap_mutex);
return seqnum;
}
EXPORT_SYMBOL_GPL(nvme_auth_get_seqnum);
static const struct nvme_auth_dhgroup_map {
char name[16];
char kpp[16];
} dhgroup_map[] = {
[NVME_AUTH_DHGROUP_NULL] = {
.name = "null", .kpp = "null" },
[NVME_AUTH_DHGROUP_2048] = {
.name = "ffdhe2048", .kpp = "ffdhe2048(dh)" },
[NVME_AUTH_DHGROUP_3072] = {
.name = "ffdhe3072", .kpp = "ffdhe3072(dh)" },
[NVME_AUTH_DHGROUP_4096] = {
.name = "ffdhe4096", .kpp = "ffdhe4096(dh)" },
[NVME_AUTH_DHGROUP_6144] = {
.name = "ffdhe6144", .kpp = "ffdhe6144(dh)" },
[NVME_AUTH_DHGROUP_8192] = {
.name = "ffdhe8192", .kpp = "ffdhe8192(dh)" },
};
const char *nvme_auth_dhgroup_name(u8 dhgroup_id)
{
if (dhgroup_id >= ARRAY_SIZE(dhgroup_map))
return NULL;
return dhgroup_map[dhgroup_id].name;
}
EXPORT_SYMBOL_GPL(nvme_auth_dhgroup_name);
const char *nvme_auth_dhgroup_kpp(u8 dhgroup_id)
{
if (dhgroup_id >= ARRAY_SIZE(dhgroup_map))
return NULL;
return dhgroup_map[dhgroup_id].kpp;
}
EXPORT_SYMBOL_GPL(nvme_auth_dhgroup_kpp);
u8 nvme_auth_dhgroup_id(const char *dhgroup_name)
{
int i;
if (!dhgroup_name || !strlen(dhgroup_name))
return NVME_AUTH_DHGROUP_INVALID;
for (i = 0; i < ARRAY_SIZE(dhgroup_map); i++) {
if (!strlen(dhgroup_map[i].name))
continue;
if (!strncmp(dhgroup_map[i].name, dhgroup_name,
strlen(dhgroup_map[i].name)))
return i;
}
return NVME_AUTH_DHGROUP_INVALID;
}
EXPORT_SYMBOL_GPL(nvme_auth_dhgroup_id);
static const struct nvme_dhchap_hash_map {
int len;
Annotation
- Immediate include surface: `linux/module.h`, `linux/crc32.h`, `linux/base64.h`, `linux/prandom.h`, `linux/scatterlist.h`, `linux/unaligned.h`, `crypto/dh.h`, `crypto/sha2.h`.
- Detected declarations: `function nvme_auth_get_seqnum`, `function nvme_auth_dhgroup_id`, `function nvme_auth_hmac_id`, `function nvme_auth_hmac_hash_len`, `function nvme_auth_key_struct_size`, `function nvme_auth_free_key`, `function nvme_auth_hmac_final`, `function nvme_auth_hmac_update`, `function nvme_auth_hmac_final`, `function nvme_auth_hmac`.
- Atlas domain: Representative Device Path / PCIe NVMe Storage Path.
- Implementation status: integration implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.