Linux kernel mirror (for testing)
git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel
os
linux
1/* SPDX-License-Identifier: GPL-2.0 */
2/*
3 * Copyright (c) 2021 Hannes Reinecke, SUSE Software Solutions
4 */
5
6#ifndef _NVME_AUTH_H
7#define _NVME_AUTH_H
8
9#include <crypto/kpp.h>
10#include <crypto/sha2.h>
11
12struct nvme_dhchap_key {
13 size_t len;
14 u8 hash;
15 u8 key[] __counted_by(len);
16};
17
18u32 nvme_auth_get_seqnum(void);
19const char *nvme_auth_dhgroup_name(u8 dhgroup_id);
20const char *nvme_auth_dhgroup_kpp(u8 dhgroup_id);
21u8 nvme_auth_dhgroup_id(const char *dhgroup_name);
22
23const char *nvme_auth_hmac_name(u8 hmac_id);
24size_t nvme_auth_hmac_hash_len(u8 hmac_id);
25u8 nvme_auth_hmac_id(const char *hmac_name);
26struct nvme_auth_hmac_ctx {
27 u8 hmac_id;
28 union {
29 struct hmac_sha256_ctx sha256;
30 struct hmac_sha384_ctx sha384;
31 struct hmac_sha512_ctx sha512;
32 };
33};
34int nvme_auth_hmac_init(struct nvme_auth_hmac_ctx *hmac, u8 hmac_id,
35 const u8 *key, size_t key_len);
36void nvme_auth_hmac_update(struct nvme_auth_hmac_ctx *hmac, const u8 *data,
37 size_t data_len);
38void nvme_auth_hmac_final(struct nvme_auth_hmac_ctx *hmac, u8 *out);
39
40u32 nvme_auth_key_struct_size(u32 key_len);
41struct nvme_dhchap_key *nvme_auth_extract_key(const char *secret, u8 key_hash);
42void nvme_auth_free_key(struct nvme_dhchap_key *key);
43struct nvme_dhchap_key *nvme_auth_alloc_key(u32 len, u8 hash);
44struct nvme_dhchap_key *nvme_auth_transform_key(
45 const struct nvme_dhchap_key *key, const char *nqn);
46int nvme_auth_parse_key(const char *secret, struct nvme_dhchap_key **ret_key);
47int nvme_auth_augmented_challenge(u8 hmac_id, const u8 *skey, size_t skey_len,
48 const u8 *challenge, u8 *aug, size_t hlen);
49int nvme_auth_gen_privkey(struct crypto_kpp *dh_tfm, u8 dh_gid);
50int nvme_auth_gen_pubkey(struct crypto_kpp *dh_tfm,
51 u8 *host_key, size_t host_key_len);
52int nvme_auth_gen_session_key(struct crypto_kpp *dh_tfm,
53 const u8 *public_key, size_t public_key_len,
54 u8 *sess_key, size_t sess_key_len, u8 hash_id);
55int nvme_auth_generate_psk(u8 hmac_id, const u8 *skey, size_t skey_len,
56 const u8 *c1, const u8 *c2, size_t hash_len,
57 u8 **ret_psk, size_t *ret_len);
58int nvme_auth_generate_digest(u8 hmac_id, const u8 *psk, size_t psk_len,
59 const char *subsysnqn, const char *hostnqn,
60 char **ret_digest);
61int nvme_auth_derive_tls_psk(int hmac_id, const u8 *psk, size_t psk_len,
62 const char *psk_digest, u8 **ret_psk);
63
64#endif /* _NVME_AUTH_H */