Lines Matching full:ctrl
59 int nvmet_setup_dhgroup(struct nvmet_ctrl *ctrl, u8 dhgroup_id) in nvmet_setup_dhgroup() argument
64 pr_debug("%s: ctrl %d selecting dhgroup %d\n", in nvmet_setup_dhgroup()
65 __func__, ctrl->cntlid, dhgroup_id); in nvmet_setup_dhgroup()
67 if (ctrl->dh_tfm) { in nvmet_setup_dhgroup()
68 if (ctrl->dh_gid == dhgroup_id) { in nvmet_setup_dhgroup()
69 pr_debug("%s: ctrl %d reuse existing DH group %d\n", in nvmet_setup_dhgroup()
70 __func__, ctrl->cntlid, dhgroup_id); in nvmet_setup_dhgroup()
73 crypto_free_kpp(ctrl->dh_tfm); in nvmet_setup_dhgroup()
74 ctrl->dh_tfm = NULL; in nvmet_setup_dhgroup()
75 ctrl->dh_gid = 0; in nvmet_setup_dhgroup()
83 pr_debug("%s: ctrl %d invalid DH group %d\n", in nvmet_setup_dhgroup()
84 __func__, ctrl->cntlid, dhgroup_id); in nvmet_setup_dhgroup()
87 ctrl->dh_tfm = crypto_alloc_kpp(dhgroup_kpp, 0, 0); in nvmet_setup_dhgroup()
88 if (IS_ERR(ctrl->dh_tfm)) { in nvmet_setup_dhgroup()
89 pr_debug("%s: ctrl %d failed to setup DH group %d, err %ld\n", in nvmet_setup_dhgroup()
90 __func__, ctrl->cntlid, dhgroup_id, in nvmet_setup_dhgroup()
91 PTR_ERR(ctrl->dh_tfm)); in nvmet_setup_dhgroup()
92 ret = PTR_ERR(ctrl->dh_tfm); in nvmet_setup_dhgroup()
93 ctrl->dh_tfm = NULL; in nvmet_setup_dhgroup()
94 ctrl->dh_gid = 0; in nvmet_setup_dhgroup()
96 ctrl->dh_gid = dhgroup_id; in nvmet_setup_dhgroup()
97 pr_debug("%s: ctrl %d setup DH group %d\n", in nvmet_setup_dhgroup()
98 __func__, ctrl->cntlid, ctrl->dh_gid); in nvmet_setup_dhgroup()
99 ret = nvme_auth_gen_privkey(ctrl->dh_tfm, ctrl->dh_gid); in nvmet_setup_dhgroup()
101 pr_debug("%s: ctrl %d failed to generate private key, err %d\n", in nvmet_setup_dhgroup()
102 __func__, ctrl->cntlid, ret); in nvmet_setup_dhgroup()
103 kfree_sensitive(ctrl->dh_key); in nvmet_setup_dhgroup()
104 ctrl->dh_key = NULL; in nvmet_setup_dhgroup()
107 ctrl->dh_keysize = crypto_kpp_maxsize(ctrl->dh_tfm); in nvmet_setup_dhgroup()
108 kfree_sensitive(ctrl->dh_key); in nvmet_setup_dhgroup()
109 ctrl->dh_key = kzalloc(ctrl->dh_keysize, GFP_KERNEL); in nvmet_setup_dhgroup()
110 if (!ctrl->dh_key) { in nvmet_setup_dhgroup()
111 pr_warn("ctrl %d failed to allocate public key\n", in nvmet_setup_dhgroup()
112 ctrl->cntlid); in nvmet_setup_dhgroup()
115 ret = nvme_auth_gen_pubkey(ctrl->dh_tfm, ctrl->dh_key, in nvmet_setup_dhgroup()
116 ctrl->dh_keysize); in nvmet_setup_dhgroup()
118 pr_warn("ctrl %d failed to generate public key\n", in nvmet_setup_dhgroup()
119 ctrl->cntlid); in nvmet_setup_dhgroup()
120 kfree(ctrl->dh_key); in nvmet_setup_dhgroup()
121 ctrl->dh_key = NULL; in nvmet_setup_dhgroup()
128 int nvmet_setup_auth(struct nvmet_ctrl *ctrl) in nvmet_setup_auth() argument
136 if (nvmet_is_disc_subsys(ctrl->subsys)) in nvmet_setup_auth()
139 if (ctrl->subsys->allow_any_host) in nvmet_setup_auth()
142 list_for_each_entry(p, &ctrl->subsys->hosts, entry) { in nvmet_setup_auth()
144 if (strcmp(nvmet_host_name(p->host), ctrl->hostnqn)) in nvmet_setup_auth()
150 pr_debug("host %s not found\n", ctrl->hostnqn); in nvmet_setup_auth()
155 ret = nvmet_setup_dhgroup(ctrl, host->dhchap_dhgroup_id); in nvmet_setup_auth()
164 if (host->dhchap_hash_id == ctrl->shash_id) { in nvmet_setup_auth()
166 ctrl->shash_id); in nvmet_setup_auth()
174 ctrl->shash_id = host->dhchap_hash_id; in nvmet_setup_auth()
178 nvme_auth_free_key(ctrl->host_key); in nvmet_setup_auth()
179 ctrl->host_key = nvme_auth_extract_key(host->dhchap_secret + 10, in nvmet_setup_auth()
181 if (IS_ERR(ctrl->host_key)) { in nvmet_setup_auth()
182 ret = PTR_ERR(ctrl->host_key); in nvmet_setup_auth()
183 ctrl->host_key = NULL; in nvmet_setup_auth()
187 ctrl->host_key->hash > 0 ? in nvmet_setup_auth()
188 nvme_auth_hmac_name(ctrl->host_key->hash) : "none", in nvmet_setup_auth()
189 (int)ctrl->host_key->len, ctrl->host_key->key); in nvmet_setup_auth()
191 nvme_auth_free_key(ctrl->ctrl_key); in nvmet_setup_auth()
193 ctrl->ctrl_key = NULL; in nvmet_setup_auth()
197 ctrl->ctrl_key = nvme_auth_extract_key(host->dhchap_ctrl_secret + 10, in nvmet_setup_auth()
199 if (IS_ERR(ctrl->ctrl_key)) { in nvmet_setup_auth()
200 ret = PTR_ERR(ctrl->ctrl_key); in nvmet_setup_auth()
201 ctrl->ctrl_key = NULL; in nvmet_setup_auth()
204 pr_debug("%s: using ctrl hash %s key %*ph\n", __func__, in nvmet_setup_auth()
205 ctrl->ctrl_key->hash > 0 ? in nvmet_setup_auth()
206 nvme_auth_hmac_name(ctrl->ctrl_key->hash) : "none", in nvmet_setup_auth()
207 (int)ctrl->ctrl_key->len, ctrl->ctrl_key->key); in nvmet_setup_auth()
211 if (ctrl->host_key) { in nvmet_setup_auth()
212 nvme_auth_free_key(ctrl->host_key); in nvmet_setup_auth()
213 ctrl->host_key = NULL; in nvmet_setup_auth()
215 ctrl->shash_id = 0; in nvmet_setup_auth()
234 void nvmet_destroy_auth(struct nvmet_ctrl *ctrl) in nvmet_destroy_auth() argument
236 ctrl->shash_id = 0; in nvmet_destroy_auth()
238 if (ctrl->dh_tfm) { in nvmet_destroy_auth()
239 crypto_free_kpp(ctrl->dh_tfm); in nvmet_destroy_auth()
240 ctrl->dh_tfm = NULL; in nvmet_destroy_auth()
241 ctrl->dh_gid = 0; in nvmet_destroy_auth()
243 kfree_sensitive(ctrl->dh_key); in nvmet_destroy_auth()
244 ctrl->dh_key = NULL; in nvmet_destroy_auth()
246 if (ctrl->host_key) { in nvmet_destroy_auth()
247 nvme_auth_free_key(ctrl->host_key); in nvmet_destroy_auth()
248 ctrl->host_key = NULL; in nvmet_destroy_auth()
250 if (ctrl->ctrl_key) { in nvmet_destroy_auth()
251 nvme_auth_free_key(ctrl->ctrl_key); in nvmet_destroy_auth()
252 ctrl->ctrl_key = NULL; in nvmet_destroy_auth()
258 if (req->sq->ctrl->host_key && in nvmet_check_auth_status()
269 struct nvmet_ctrl *ctrl = req->sq->ctrl; in nvmet_auth_host_hash() local
275 hash_name = nvme_auth_hmac_name(ctrl->shash_id); in nvmet_auth_host_hash()
277 pr_warn("Hash ID %d invalid\n", ctrl->shash_id); in nvmet_auth_host_hash()
295 host_response = nvme_auth_transform_key(ctrl->host_key, ctrl->hostnqn); in nvmet_auth_host_hash()
302 ctrl->host_key->len); in nvmet_auth_host_hash()
306 if (ctrl->dh_gid != NVME_AUTH_DHGROUP_NULL) { in nvmet_auth_host_hash()
312 ret = nvme_auth_augmented_challenge(ctrl->shash_id, in nvmet_auth_host_hash()
321 pr_debug("ctrl %d qid %d host response seq %u transaction %d\n", in nvmet_auth_host_hash()
322 ctrl->cntlid, req->sq->qid, req->sq->dhchap_s1, in nvmet_auth_host_hash()
353 ret = crypto_shash_update(shash, ctrl->hostnqn, strlen(ctrl->hostnqn)); in nvmet_auth_host_hash()
359 ret = crypto_shash_update(shash, ctrl->subsysnqn, in nvmet_auth_host_hash()
360 strlen(ctrl->subsysnqn)); in nvmet_auth_host_hash()
381 struct nvmet_ctrl *ctrl = req->sq->ctrl; in nvmet_auth_ctrl_hash() local
387 hash_name = nvme_auth_hmac_name(ctrl->shash_id); in nvmet_auth_ctrl_hash()
389 pr_warn("Hash ID %d invalid\n", ctrl->shash_id); in nvmet_auth_ctrl_hash()
407 ctrl_response = nvme_auth_transform_key(ctrl->ctrl_key, in nvmet_auth_ctrl_hash()
408 ctrl->subsysnqn); in nvmet_auth_ctrl_hash()
415 ctrl->ctrl_key->len); in nvmet_auth_ctrl_hash()
419 if (ctrl->dh_gid != NVME_AUTH_DHGROUP_NULL) { in nvmet_auth_ctrl_hash()
425 ret = nvme_auth_augmented_challenge(ctrl->shash_id, in nvmet_auth_ctrl_hash()
463 ret = crypto_shash_update(shash, ctrl->subsysnqn, in nvmet_auth_ctrl_hash()
464 strlen(ctrl->subsysnqn)); in nvmet_auth_ctrl_hash()
470 ret = crypto_shash_update(shash, ctrl->hostnqn, strlen(ctrl->hostnqn)); in nvmet_auth_ctrl_hash()
489 struct nvmet_ctrl *ctrl = req->sq->ctrl; in nvmet_auth_ctrl_exponential() local
492 if (!ctrl->dh_key) { in nvmet_auth_ctrl_exponential()
493 pr_warn("ctrl %d no DH public key!\n", ctrl->cntlid); in nvmet_auth_ctrl_exponential()
496 if (buf_size != ctrl->dh_keysize) { in nvmet_auth_ctrl_exponential()
497 pr_warn("ctrl %d DH public key size mismatch, need %zu is %d\n", in nvmet_auth_ctrl_exponential()
498 ctrl->cntlid, ctrl->dh_keysize, buf_size); in nvmet_auth_ctrl_exponential()
501 memcpy(buf, ctrl->dh_key, buf_size); in nvmet_auth_ctrl_exponential()
502 pr_debug("%s: ctrl %d public key %*ph\n", __func__, in nvmet_auth_ctrl_exponential()
503 ctrl->cntlid, (int)buf_size, buf); in nvmet_auth_ctrl_exponential()
512 struct nvmet_ctrl *ctrl = req->sq->ctrl; in nvmet_auth_ctrl_sesskey() local
515 req->sq->dhchap_skey_len = ctrl->dh_keysize; in nvmet_auth_ctrl_sesskey()
519 ret = nvme_auth_gen_shared_secret(ctrl->dh_tfm, in nvmet_auth_ctrl_sesskey()