Lines Matching full:data

77 static void eap_pwd_state(struct eap_pwd_data *data, int state)  in eap_pwd_state()  argument
80 eap_pwd_state_txt(data->state), eap_pwd_state_txt(state)); in eap_pwd_state()
81 data->state = state; in eap_pwd_state()
87 struct eap_pwd_data *data; in eap_pwd_init() local
96 data = os_zalloc(sizeof(*data)); in eap_pwd_init()
97 if (data == NULL) in eap_pwd_init()
100 data->group_num = sm->cfg->pwd_group; in eap_pwd_init()
102 data->group_num); in eap_pwd_init()
103 data->state = PWD_ID_Req; in eap_pwd_init()
105 data->id_server = (u8 *) os_strdup("server"); in eap_pwd_init()
106 if (data->id_server) in eap_pwd_init()
107 data->id_server_len = os_strlen((char *) data->id_server); in eap_pwd_init()
109 data->password = os_malloc(sm->user->password_len); in eap_pwd_init()
110 if (data->password == NULL) { in eap_pwd_init()
113 bin_clear_free(data->id_server, data->id_server_len); in eap_pwd_init()
114 os_free(data); in eap_pwd_init()
117 data->password_len = sm->user->password_len; in eap_pwd_init()
118 os_memcpy(data->password, sm->user->password, data->password_len); in eap_pwd_init()
119 data->password_hash = sm->user->password_hash; in eap_pwd_init()
121 data->salt_len = sm->user->salt_len; in eap_pwd_init()
122 if (data->salt_len) { in eap_pwd_init()
123 data->salt = os_memdup(sm->user->salt, sm->user->salt_len); in eap_pwd_init()
124 if (!data->salt) { in eap_pwd_init()
127 bin_clear_free(data->id_server, data->id_server_len); in eap_pwd_init()
128 bin_clear_free(data->password, data->password_len); in eap_pwd_init()
129 os_free(data); in eap_pwd_init()
134 data->in_frag_pos = data->out_frag_pos = 0; in eap_pwd_init()
135 data->inbuf = data->outbuf = NULL; in eap_pwd_init()
137 data->mtu = sm->cfg->fragment_size > 0 ? sm->cfg->fragment_size : 1020; in eap_pwd_init()
139 return data; in eap_pwd_init()
145 struct eap_pwd_data *data = priv; in eap_pwd_reset() local
147 crypto_bignum_deinit(data->private_value, 1); in eap_pwd_reset()
148 crypto_bignum_deinit(data->peer_scalar, 1); in eap_pwd_reset()
149 crypto_bignum_deinit(data->my_scalar, 1); in eap_pwd_reset()
150 crypto_bignum_deinit(data->k, 1); in eap_pwd_reset()
151 crypto_ec_point_deinit(data->my_element, 1); in eap_pwd_reset()
152 crypto_ec_point_deinit(data->peer_element, 1); in eap_pwd_reset()
153 bin_clear_free(data->id_peer, data->id_peer_len); in eap_pwd_reset()
154 bin_clear_free(data->id_server, data->id_server_len); in eap_pwd_reset()
155 bin_clear_free(data->password, data->password_len); in eap_pwd_reset()
156 bin_clear_free(data->salt, data->salt_len); in eap_pwd_reset()
157 if (data->grp) { in eap_pwd_reset()
158 crypto_ec_deinit(data->grp->group); in eap_pwd_reset()
159 crypto_ec_point_deinit(data->grp->pwe, 1); in eap_pwd_reset()
160 os_free(data->grp); in eap_pwd_reset()
162 wpabuf_free(data->inbuf); in eap_pwd_reset()
163 wpabuf_free(data->outbuf); in eap_pwd_reset()
164 bin_clear_free(data, sizeof(*data)); in eap_pwd_reset()
168 static void eap_pwd_build_id_req(struct eap_sm *sm, struct eap_pwd_data *data, in eap_pwd_build_id_req() argument
175 if (data->out_frag_pos) in eap_pwd_build_id_req()
178 data->outbuf = wpabuf_alloc(sizeof(struct eap_pwd_id) + in eap_pwd_build_id_req()
179 data->id_server_len); in eap_pwd_build_id_req()
180 if (data->outbuf == NULL) { in eap_pwd_build_id_req()
181 eap_pwd_state(data, FAILURE); in eap_pwd_build_id_req()
185 if (os_get_random((u8 *) &data->token, sizeof(data->token)) < 0) { in eap_pwd_build_id_req()
186 wpabuf_free(data->outbuf); in eap_pwd_build_id_req()
187 data->outbuf = NULL; in eap_pwd_build_id_req()
188 eap_pwd_state(data, FAILURE); in eap_pwd_build_id_req()
193 data->password, data->password_len); in eap_pwd_build_id_req()
194 if (data->salt_len) in eap_pwd_build_id_req()
196 data->salt, data->salt_len); in eap_pwd_build_id_req()
202 if (data->salt_len) { in eap_pwd_build_id_req()
203 switch (data->password_len) { in eap_pwd_build_id_req()
205 data->password_prep = EAP_PWD_PREP_SSHA1; in eap_pwd_build_id_req()
208 data->password_prep = EAP_PWD_PREP_SSHA256; in eap_pwd_build_id_req()
211 data->password_prep = EAP_PWD_PREP_SSHA512; in eap_pwd_build_id_req()
216 (int) data->password_len); in eap_pwd_build_id_req()
217 eap_pwd_state(data, FAILURE); in eap_pwd_build_id_req()
222 data->password_prep = data->password_hash ? EAP_PWD_PREP_MS : in eap_pwd_build_id_req()
226 wpabuf_put_be16(data->outbuf, data->group_num); in eap_pwd_build_id_req()
227 wpabuf_put_u8(data->outbuf, EAP_PWD_DEFAULT_RAND_FUNC); in eap_pwd_build_id_req()
228 wpabuf_put_u8(data->outbuf, EAP_PWD_DEFAULT_PRF); in eap_pwd_build_id_req()
229 wpabuf_put_data(data->outbuf, &data->token, sizeof(data->token)); in eap_pwd_build_id_req()
230 wpabuf_put_u8(data->outbuf, data->password_prep); in eap_pwd_build_id_req()
231 wpabuf_put_data(data->outbuf, data->id_server, data->id_server_len); in eap_pwd_build_id_req()
236 struct eap_pwd_data *data, u8 id) in eap_pwd_build_commit_req() argument
247 if (data->out_frag_pos) in eap_pwd_build_commit_req()
250 prime_len = crypto_ec_prime_len(data->grp->group); in eap_pwd_build_commit_req()
251 order_len = crypto_ec_order_len(data->grp->group); in eap_pwd_build_commit_req()
253 data->private_value = crypto_bignum_init(); in eap_pwd_build_commit_req()
254 data->my_element = crypto_ec_point_init(data->grp->group); in eap_pwd_build_commit_req()
255 data->my_scalar = crypto_bignum_init(); in eap_pwd_build_commit_req()
257 if (!data->private_value || !data->my_element || !data->my_scalar || in eap_pwd_build_commit_req()
264 if (eap_pwd_get_rand_mask(data->grp, data->private_value, mask, in eap_pwd_build_commit_req()
265 data->my_scalar) < 0) in eap_pwd_build_commit_req()
268 if (crypto_ec_point_mul(data->grp->group, data->grp->pwe, mask, in eap_pwd_build_commit_req()
269 data->my_element) < 0) { in eap_pwd_build_commit_req()
272 eap_pwd_state(data, FAILURE); in eap_pwd_build_commit_req()
276 if (crypto_ec_point_invert(data->grp->group, data->my_element) < 0) { in eap_pwd_build_commit_req()
282 data->outbuf = wpabuf_alloc(2 * prime_len + order_len + in eap_pwd_build_commit_req()
283 (data->salt ? 1 + data->salt_len : 0)); in eap_pwd_build_commit_req()
284 if (data->outbuf == NULL) in eap_pwd_build_commit_req()
288 if (data->salt_len) { in eap_pwd_build_commit_req()
289 wpabuf_put_u8(data->outbuf, data->salt_len); in eap_pwd_build_commit_req()
290 wpabuf_put_data(data->outbuf, data->salt, data->salt_len); in eap_pwd_build_commit_req()
294 element = wpabuf_put(data->outbuf, 2 * prime_len); in eap_pwd_build_commit_req()
295 scalar = wpabuf_put(data->outbuf, order_len); in eap_pwd_build_commit_req()
296 if (crypto_bignum_to_bin(data->my_scalar, scalar, order_len, in eap_pwd_build_commit_req()
300 if (crypto_ec_point_to_bin(data->grp->group, data->my_element, element, in eap_pwd_build_commit_req()
309 if (data->outbuf == NULL) in eap_pwd_build_commit_req()
310 eap_pwd_state(data, FAILURE); in eap_pwd_build_commit_req()
315 struct eap_pwd_data *data, u8 id) in eap_pwd_build_confirm_req() argument
327 if (data->out_frag_pos) in eap_pwd_build_confirm_req()
330 prime_len = crypto_ec_prime_len(data->grp->group); in eap_pwd_build_confirm_req()
331 order_len = crypto_ec_order_len(data->grp->group); in eap_pwd_build_confirm_req()
355 if (crypto_bignum_to_bin(data->k, cruft, prime_len, prime_len) < 0) in eap_pwd_build_confirm_req()
361 if (crypto_ec_point_to_bin(data->grp->group, data->my_element, cruft, in eap_pwd_build_confirm_req()
370 if (crypto_bignum_to_bin(data->my_scalar, cruft, order_len, in eap_pwd_build_confirm_req()
377 if (crypto_ec_point_to_bin(data->grp->group, data->peer_element, cruft, in eap_pwd_build_confirm_req()
386 if (crypto_bignum_to_bin(data->peer_scalar, cruft, order_len, in eap_pwd_build_confirm_req()
393 grp = htons(data->group_num); in eap_pwd_build_confirm_req()
407 os_memcpy(data->my_confirm, conf, SHA256_MAC_LEN); in eap_pwd_build_confirm_req()
409 data->outbuf = wpabuf_alloc(SHA256_MAC_LEN); in eap_pwd_build_confirm_req()
410 if (data->outbuf == NULL) in eap_pwd_build_confirm_req()
413 wpabuf_put_data(data->outbuf, conf, SHA256_MAC_LEN); in eap_pwd_build_confirm_req()
417 if (data->outbuf == NULL) in eap_pwd_build_confirm_req()
418 eap_pwd_state(data, FAILURE); in eap_pwd_build_confirm_req()
426 struct eap_pwd_data *data = priv; in eap_pwd_build_req() local
436 if (data->in_frag_pos) { in eap_pwd_build_req()
441 eap_pwd_state(data, FAILURE); in eap_pwd_build_req()
444 switch (data->state) { in eap_pwd_build_req()
455 eap_pwd_state(data, FAILURE); /* just to be sure */ in eap_pwd_build_req()
463 * build the data portion of a request in eap_pwd_build_req()
465 switch (data->state) { in eap_pwd_build_req()
467 eap_pwd_build_id_req(sm, data, id); in eap_pwd_build_req()
471 eap_pwd_build_commit_req(sm, data, id); in eap_pwd_build_req()
475 eap_pwd_build_confirm_req(sm, data, id); in eap_pwd_build_req()
480 data->state); in eap_pwd_build_req()
481 eap_pwd_state(data, FAILURE); in eap_pwd_build_req()
486 if (data->state == FAILURE) in eap_pwd_build_req()
490 * determine whether that data needs to be fragmented in eap_pwd_build_req()
492 len = wpabuf_len(data->outbuf) - data->out_frag_pos; in eap_pwd_build_req()
493 if ((len + EAP_PWD_HDR_SIZE) > data->mtu) { in eap_pwd_build_req()
494 len = data->mtu - EAP_PWD_HDR_SIZE; in eap_pwd_build_req()
500 if (data->out_frag_pos == 0) { in eap_pwd_build_req()
502 totlen = wpabuf_len(data->outbuf) + in eap_pwd_build_req()
513 * alloc an eap request and populate it with the data in eap_pwd_build_req()
520 eap_pwd_state(data, FAILURE); in eap_pwd_build_req()
528 buf = wpabuf_head_u8(data->outbuf); in eap_pwd_build_req()
529 wpabuf_put_data(req, buf + data->out_frag_pos, len); in eap_pwd_build_req()
530 data->out_frag_pos += len; in eap_pwd_build_req()
532 * either not fragged or last fragment, either way free up the data in eap_pwd_build_req()
534 if (data->out_frag_pos >= wpabuf_len(data->outbuf)) { in eap_pwd_build_req()
535 wpabuf_free(data->outbuf); in eap_pwd_build_req()
536 data->outbuf = NULL; in eap_pwd_build_req()
537 data->out_frag_pos = 0; in eap_pwd_build_req()
547 struct eap_pwd_data *data = priv; in eap_pwd_check() local
560 if (data->state == PWD_ID_Req && in eap_pwd_check()
564 if (data->state == PWD_Commit_Req && in eap_pwd_check()
568 if (data->state == PWD_Confirm_Req && in eap_pwd_check()
573 *pos, data->state); in eap_pwd_check()
580 struct eap_pwd_data *data, in eap_pwd_process_id_resp() argument
595 if ((data->group_num != be_to_host16(id->group_num)) || in eap_pwd_process_id_resp()
597 (os_memcmp(id->token, (u8 *)&data->token, sizeof(data->token))) || in eap_pwd_process_id_resp()
599 (id->prep != data->password_prep)) { in eap_pwd_process_id_resp()
601 eap_pwd_state(data, FAILURE); in eap_pwd_process_id_resp()
604 if (data->id_peer || data->grp) { in eap_pwd_process_id_resp()
605 wpa_printf(MSG_INFO, "EAP-pwd: data was already allocated"); in eap_pwd_process_id_resp()
608 data->id_peer = os_malloc(payload_len - sizeof(struct eap_pwd_id)); in eap_pwd_process_id_resp()
609 if (data->id_peer == NULL) { in eap_pwd_process_id_resp()
613 data->id_peer_len = payload_len - sizeof(struct eap_pwd_id); in eap_pwd_process_id_resp()
614 os_memcpy(data->id_peer, id->identity, data->id_peer_len); in eap_pwd_process_id_resp()
616 data->id_peer, data->id_peer_len); in eap_pwd_process_id_resp()
618 data->grp = get_eap_pwd_group(data->group_num); in eap_pwd_process_id_resp()
619 if (data->grp == NULL) { in eap_pwd_process_id_resp()
630 if (data->password_prep == EAP_PWD_PREP_MS) { in eap_pwd_process_id_resp()
631 res = hash_nt_password_hash(data->password, pwhashhash); in eap_pwd_process_id_resp()
637 password = data->password; in eap_pwd_process_id_resp()
638 password_len = data->password_len; in eap_pwd_process_id_resp()
641 res = compute_password_element(data->grp, data->group_num, in eap_pwd_process_id_resp()
643 data->id_server, data->id_server_len, in eap_pwd_process_id_resp()
644 data->id_peer, data->id_peer_len, in eap_pwd_process_id_resp()
645 (u8 *) &data->token); in eap_pwd_process_id_resp()
653 (int) crypto_ec_prime_len_bits(data->grp->group)); in eap_pwd_process_id_resp()
655 eap_pwd_state(data, PWD_Commit_Req); in eap_pwd_process_id_resp()
660 eap_pwd_process_commit_resp(struct eap_sm *sm, struct eap_pwd_data *data, in eap_pwd_process_commit_resp() argument
670 prime_len = crypto_ec_prime_len(data->grp->group); in eap_pwd_process_commit_resp()
671 order_len = crypto_ec_order_len(data->grp->group); in eap_pwd_process_commit_resp()
681 data->k = crypto_bignum_init(); in eap_pwd_process_commit_resp()
682 K = crypto_ec_point_init(data->grp->group); in eap_pwd_process_commit_resp()
683 if (!data->k || !K) { in eap_pwd_process_commit_resp()
684 wpa_printf(MSG_INFO, "EAP-PWD (server): peer data allocation " in eap_pwd_process_commit_resp()
691 data->peer_element = eap_pwd_get_element(data->grp, ptr); in eap_pwd_process_commit_resp()
692 if (!data->peer_element) { in eap_pwd_process_commit_resp()
698 data->peer_scalar = eap_pwd_get_scalar(data->grp, ptr); in eap_pwd_process_commit_resp()
699 if (!data->peer_scalar) { in eap_pwd_process_commit_resp()
700 wpa_printf(MSG_INFO, "EAP-PWD (server): peer data allocation " in eap_pwd_process_commit_resp()
706 if (crypto_bignum_cmp(data->my_scalar, data->peer_scalar) == 0 || in eap_pwd_process_commit_resp()
707 crypto_ec_point_cmp(data->grp->group, data->my_element, in eap_pwd_process_commit_resp()
708 data->peer_element) == 0) { in eap_pwd_process_commit_resp()
715 if ((crypto_ec_point_mul(data->grp->group, data->grp->pwe, in eap_pwd_process_commit_resp()
716 data->peer_scalar, K) < 0) || in eap_pwd_process_commit_resp()
717 (crypto_ec_point_add(data->grp->group, K, data->peer_element, in eap_pwd_process_commit_resp()
719 (crypto_ec_point_mul(data->grp->group, K, data->private_value, in eap_pwd_process_commit_resp()
732 if (crypto_ec_point_is_at_infinity(data->grp->group, K)) { in eap_pwd_process_commit_resp()
737 if (crypto_ec_point_x(data->grp->group, K, data->k)) { in eap_pwd_process_commit_resp()
748 eap_pwd_state(data, PWD_Confirm_Req); in eap_pwd_process_commit_resp()
750 eap_pwd_state(data, FAILURE); in eap_pwd_process_commit_resp()
755 eap_pwd_process_confirm_resp(struct eap_sm *sm, struct eap_pwd_data *data, in eap_pwd_process_confirm_resp() argument
764 prime_len = crypto_ec_prime_len(data->grp->group); in eap_pwd_process_confirm_resp()
765 order_len = crypto_ec_order_len(data->grp->group); in eap_pwd_process_confirm_resp()
775 grp = htons(data->group_num); in eap_pwd_process_confirm_resp()
799 if (crypto_bignum_to_bin(data->k, cruft, prime_len, prime_len) < 0) in eap_pwd_process_confirm_resp()
805 if (crypto_ec_point_to_bin(data->grp->group, data->peer_element, cruft, in eap_pwd_process_confirm_resp()
814 if (crypto_bignum_to_bin(data->peer_scalar, cruft, order_len, in eap_pwd_process_confirm_resp()
821 if (crypto_ec_point_to_bin(data->grp->group, data->my_element, cruft, in eap_pwd_process_confirm_resp()
830 if (crypto_bignum_to_bin(data->my_scalar, cruft, order_len, in eap_pwd_process_confirm_resp()
851 if (compute_keys(data->grp, data->k, in eap_pwd_process_confirm_resp()
852 data->peer_scalar, data->my_scalar, conf, in eap_pwd_process_confirm_resp()
853 data->my_confirm, &cs, data->msk, data->emsk, in eap_pwd_process_confirm_resp()
854 data->session_id) < 0) in eap_pwd_process_confirm_resp()
855 eap_pwd_state(data, FAILURE); in eap_pwd_process_confirm_resp()
857 eap_pwd_state(data, SUCCESS); in eap_pwd_process_confirm_resp()
868 struct eap_pwd_data *data = priv; in eap_pwd_process() local
887 * if we're fragmenting then this should be an ACK with no data, in eap_pwd_process()
890 if (data->out_frag_pos) { in eap_pwd_process()
915 if (data->inbuf) { in eap_pwd_process()
920 data->inbuf = wpabuf_alloc(tot_len); in eap_pwd_process()
921 if (data->inbuf == NULL) { in eap_pwd_process()
926 data->in_frag_pos = 0; in eap_pwd_process()
933 if (EAP_PWD_GET_MORE_BIT(lm_exch) || data->in_frag_pos) { in eap_pwd_process()
934 if (!data->inbuf) { in eap_pwd_process()
937 eap_pwd_state(data, FAILURE); in eap_pwd_process()
940 if ((data->in_frag_pos + len) > wpabuf_size(data->inbuf)) { in eap_pwd_process()
943 (int) data->in_frag_pos, (int) len, in eap_pwd_process()
944 (int) wpabuf_size(data->inbuf)); in eap_pwd_process()
945 eap_pwd_state(data, FAILURE); in eap_pwd_process()
948 wpabuf_put_data(data->inbuf, pos, len); in eap_pwd_process()
949 data->in_frag_pos += len; in eap_pwd_process()
960 if (data->in_frag_pos && data->inbuf) { in eap_pwd_process()
961 pos = wpabuf_head_u8(data->inbuf); in eap_pwd_process()
962 len = data->in_frag_pos; in eap_pwd_process()
968 eap_pwd_process_id_resp(sm, data, pos, len); in eap_pwd_process()
971 eap_pwd_process_commit_resp(sm, data, pos, len); in eap_pwd_process()
974 eap_pwd_process_confirm_resp(sm, data, pos, len); in eap_pwd_process()
981 if (data->in_frag_pos) { in eap_pwd_process()
982 wpabuf_free(data->inbuf); in eap_pwd_process()
983 data->inbuf = NULL; in eap_pwd_process()
984 data->in_frag_pos = 0; in eap_pwd_process()
991 struct eap_pwd_data *data = priv; in eap_pwd_getkey() local
994 if (data->state != SUCCESS) in eap_pwd_getkey()
997 key = os_memdup(data->msk, EAP_MSK_LEN); in eap_pwd_getkey()
1009 struct eap_pwd_data *data = priv; in eap_pwd_get_emsk() local
1012 if (data->state != SUCCESS) in eap_pwd_get_emsk()
1015 key = os_memdup(data->emsk, EAP_EMSK_LEN); in eap_pwd_get_emsk()
1027 struct eap_pwd_data *data = priv; in eap_pwd_is_success() local
1028 return data->state == SUCCESS; in eap_pwd_is_success()
1034 struct eap_pwd_data *data = priv; in eap_pwd_is_done() local
1035 return (data->state == SUCCESS) || (data->state == FAILURE); in eap_pwd_is_done()
1041 struct eap_pwd_data *data = priv; in eap_pwd_get_session_id() local
1044 if (data->state != SUCCESS) in eap_pwd_get_session_id()
1047 id = os_memdup(data->session_id, 1 + SHA256_MAC_LEN); in eap_pwd_get_session_id()