xref: /spdk/include/spdk_internal/nvme.h (revision a93a149c51f6811ff221fdd1dfe40ba0cea96f8c)
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright (c) 2024 Intel Corporation
3  */
4 
5 #ifndef SPDK_INTERNAL_NVME_H
6 #define SPDK_INTERNAL_NVME_H
7 
8 #include "spdk/keyring.h"
9 #include "spdk/nvme.h"
10 #include "spdk/nvmf_spec.h"
11 #include "spdk/stdinc.h"
12 
13 /**
14  * Calculate a response to a DH-HMAC-CHAP challenge.
15  *
16  * \param key DH-HMAC-CHAP key.
17  * \param hash Hash function to use.
18  * \param type Challenge type ("HostHost" for host challenge or "Controller" for controller
19  * challenge).
20  * \param seq Sequence number.
21  * \param tid Transaction ID.
22  * \param scc Secure channel concatenation.
23  * \param nqn1 Host/Subsystem NQN, depending on challenge type (hostnqn for host challenge,
24  * subnqn for controller challenge).
25  * \param nqn2 The other NQN (if nqn1==hostnqn, then nqn2==subnqn).
26  * \param dhkey Diffie-Hellman secret.
27  * \param dhlen Size of `dhkey`.
28  * \param cval Challenge value.  Its size must be large enough to keep a digest generated by `hash`
29  * function (e.g. at least 32B for sha256, 48B for sha384, etc.).
30  * \param rval Response buffer.  Its size must be large enough to keep a digest generated by `hash`
31  * function (e.g. at least 32B for sha256, 48B for sha384, etc.).
32  *
33  * \return 0 on success, negative errno otherwise.
34  */
35 int spdk_nvme_dhchap_calculate(struct spdk_key *key, enum spdk_nvmf_dhchap_hash hash,
36 			       const char *type, uint32_t seq, uint16_t tid, uint8_t scc,
37 			       const char *nqn1, const char *nqn2, const void *dhkey, size_t dhlen,
38 			       const void *cval, void *rval);
39 
40 /** DH-HMAC-CHAP Diffie-Hellman key */
41 struct spdk_nvme_dhchap_dhkey;
42 
43 /**
44  * Generate a Diffie-Hellman key.
45  *
46  * \param dhg Diffie-Hellman group.
47  *
48  * \return Diffie-Hellman key or NULL on failure.
49  */
50 struct spdk_nvme_dhchap_dhkey *spdk_nvme_dhchap_generate_dhkey(enum spdk_nvmf_dhchap_dhgroup dhg);
51 
52 /**
53  * Free a DH key generated with `spdk_nvme_dhchap_generate_dhkey()`.
54  *
55  * \param key DH key.  If NULL, this function is a no-op.
56  */
57 void spdk_nvme_dhchap_dhkey_free(struct spdk_nvme_dhchap_dhkey **key);
58 
59 /**
60  * Get the public part of a DH key.
61  *
62  * \param key DH key.
63  * \param pub Buffer to hold the public key.
64  * \param len Length of the `pub` buffer.  After a successful call to this function, this variable
65  * will hold the length of the public key.
66  *
67  * \return 0 on success or negative errno on failure.
68  */
69 int spdk_nvme_dhchap_dhkey_get_pubkey(struct spdk_nvme_dhchap_dhkey *key, void *pub, size_t *len);
70 
71 /**
72  * Derive a secret from a DH key and peer's public key.
73  *
74  * \param key DH key.
75  * \param peer Peer's public key.
76  * \param peerlen Length of the peer's public key.
77  * \param secret Buffer to hold the secret value.
78  * \param seclen Length of the `secret` buffer.  After a successful call to this function, this
79  * variable will hold the length of the secret value.
80  *
81  * \return 0 on success or negative errno on failure.
82  */
83 int spdk_nvme_dhchap_dhkey_derive_secret(struct spdk_nvme_dhchap_dhkey *key, const void *peer,
84 		size_t peerlen, void *secret, size_t *seclen);
85 
86 #endif /* SPDK_INTERNAL_NVME_H */
87