2 * hostapd / EAP-pwd (RFC 5931) server
3 * Copyright (c) 2010, Dan Harkins <dharkins@lounge.org>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the BSD license.
8 * Alternatively, this software may be distributed under the terms of the
9 * GNU General Public License version 2 as published by the Free Software
12 * See README and COPYING for more details.
18 #include "eap_server/eap_i.h"
19 #include "eap_common/eap_pwd_common.h"
24 PWD_ID_Req, PWD_Commit_Req, PWD_Confirm_Req, SUCCESS, FAILURE
37 BIGNUM *private_value;
41 EC_POINT *peer_element;
43 u8 my_confirm[SHA256_DIGEST_LENGTH];
46 u8 emsk[EAP_EMSK_LEN];
52 static const char * eap_pwd_state_txt(int state)
58 return "PWD-Commit-Req";
60 return "PWD-Confirm-Req";
71 static void eap_pwd_state(struct eap_pwd_data *data, int state)
73 wpa_printf(MSG_DEBUG, "EAP-pwd: %s -> %s",
74 eap_pwd_state_txt(data->state), eap_pwd_state_txt(state));
79 static void * eap_pwd_init(struct eap_sm *sm)
81 struct eap_pwd_data *data;
83 if (sm->user == NULL || sm->user->password == NULL ||
84 sm->user->password_len == 0) {
85 wpa_printf(MSG_INFO, "EAP-PWD (server): Password is not "
90 data = os_zalloc(sizeof(*data));
94 data->group_num = sm->pwd_group;
95 wpa_printf(MSG_DEBUG, "EAP-pwd: Selected group number %d",
97 data->state = PWD_ID_Req;
99 data->id_server = (u8 *) os_strdup("server");
101 data->id_server_len = os_strlen((char *) data->id_server);
103 data->password = os_malloc(sm->user->password_len);
104 if (data->password == NULL) {
105 wpa_printf(MSG_INFO, "EAP-PWD: Memory allocation password "
107 os_free(data->id_server);
111 data->password_len = sm->user->password_len;
112 os_memcpy(data->password, sm->user->password, data->password_len);
114 data->bnctx = BN_CTX_new();
115 if (data->bnctx == NULL) {
116 wpa_printf(MSG_INFO, "EAP-PWD: bn context allocation fail");
117 os_free(data->password);
118 os_free(data->id_server);
127 static void eap_pwd_reset(struct eap_sm *sm, void *priv)
129 struct eap_pwd_data *data = priv;
131 BN_free(data->private_value);
132 BN_free(data->peer_scalar);
133 BN_free(data->my_scalar);
135 BN_CTX_free(data->bnctx);
136 EC_POINT_free(data->my_element);
137 EC_POINT_free(data->peer_element);
138 os_free(data->id_peer);
139 os_free(data->id_server);
140 os_free(data->password);
142 EC_GROUP_free(data->grp->group);
143 EC_POINT_free(data->grp->pwe);
144 BN_free(data->grp->order);
145 BN_free(data->grp->prime);
152 static struct wpabuf *
153 eap_pwd_build_id_req(struct eap_sm *sm, struct eap_pwd_data *data, u8 id)
157 wpa_printf(MSG_DEBUG, "EAP-pwd: ID/Request");
158 req = eap_msg_alloc(EAP_VENDOR_IETF, EAP_TYPE_PWD,
159 1 + sizeof(struct eap_pwd_id) +
161 EAP_CODE_REQUEST, id);
163 eap_pwd_state(data, FAILURE);
167 /* an lfsr is good enough to generate unpredictable tokens */
168 data->token = os_random();
169 wpabuf_put_u8(req, EAP_PWD_OPCODE_ID_EXCH);
170 wpabuf_put_be16(req, data->group_num);
171 wpabuf_put_u8(req, EAP_PWD_DEFAULT_RAND_FUNC);
172 wpabuf_put_u8(req, EAP_PWD_DEFAULT_PRF);
173 wpabuf_put_data(req, &data->token, sizeof(data->token));
174 wpabuf_put_u8(req, EAP_PWD_PREP_NONE);
175 wpabuf_put_data(req, data->id_server, data->id_server_len);
181 static struct wpabuf *
182 eap_pwd_build_commit_req(struct eap_sm *sm, struct eap_pwd_data *data, u8 id)
184 struct wpabuf *req = NULL;
185 BIGNUM *mask = NULL, *x = NULL, *y = NULL;
186 u8 *scalar = NULL, *element = NULL;
189 wpa_printf(MSG_DEBUG, "EAP-pwd: Commit/Request");
191 if (((data->private_value = BN_new()) == NULL) ||
192 ((data->my_element = EC_POINT_new(data->grp->group)) == NULL) ||
193 ((data->my_scalar = BN_new()) == NULL) ||
194 ((mask = BN_new()) == NULL)) {
195 wpa_printf(MSG_INFO, "EAP-PWD (server): scalar allocation "
200 BN_rand_range(data->private_value, data->grp->order);
201 BN_rand_range(mask, data->grp->order);
202 BN_add(data->my_scalar, data->private_value, mask);
203 BN_mod(data->my_scalar, data->my_scalar, data->grp->order,
206 if (!EC_POINT_mul(data->grp->group, data->my_element, NULL,
207 data->grp->pwe, mask, data->bnctx)) {
208 wpa_printf(MSG_INFO, "EAP-PWD (server): element allocation "
210 eap_pwd_state(data, FAILURE);
214 if (!EC_POINT_invert(data->grp->group, data->my_element, data->bnctx))
216 wpa_printf(MSG_INFO, "EAP-PWD (server): element inversion "
222 if (((x = BN_new()) == NULL) ||
223 ((y = BN_new()) == NULL)) {
224 wpa_printf(MSG_INFO, "EAP-PWD (server): point allocation "
228 if (!EC_POINT_get_affine_coordinates_GFp(data->grp->group,
229 data->my_element, x, y,
231 wpa_printf(MSG_INFO, "EAP-PWD (server): point assignment "
236 if (((scalar = os_malloc(BN_num_bytes(data->grp->order))) == NULL) ||
237 ((element = os_malloc(BN_num_bytes(data->grp->prime) * 2)) ==
239 wpa_printf(MSG_INFO, "EAP-PWD (server): data allocation fail");
244 * bignums occupy as little memory as possible so one that is
245 * sufficiently smaller than the prime or order might need pre-pending
248 os_memset(scalar, 0, BN_num_bytes(data->grp->order));
249 os_memset(element, 0, BN_num_bytes(data->grp->prime) * 2);
250 offset = BN_num_bytes(data->grp->order) -
251 BN_num_bytes(data->my_scalar);
252 BN_bn2bin(data->my_scalar, scalar + offset);
254 offset = BN_num_bytes(data->grp->prime) - BN_num_bytes(x);
255 BN_bn2bin(x, element + offset);
256 offset = BN_num_bytes(data->grp->prime) - BN_num_bytes(y);
257 BN_bn2bin(y, element + BN_num_bytes(data->grp->prime) + offset);
259 req = eap_msg_alloc(EAP_VENDOR_IETF, EAP_TYPE_PWD,
260 1 + (2 * BN_num_bytes(data->grp->prime)) +
261 BN_num_bytes(data->grp->order),
262 EAP_CODE_REQUEST, id);
265 wpabuf_put_u8(req, EAP_PWD_OPCODE_COMMIT_EXCH);
267 /* We send the element as (x,y) followed by the scalar */
268 wpabuf_put_data(req, element, (2 * BN_num_bytes(data->grp->prime)));
269 wpabuf_put_data(req, scalar, BN_num_bytes(data->grp->order));
277 eap_pwd_state(data, FAILURE);
283 static struct wpabuf *
284 eap_pwd_build_confirm_req(struct eap_sm *sm, struct eap_pwd_data *data, u8 id)
286 struct wpabuf *req = NULL;
287 BIGNUM *x = NULL, *y = NULL;
289 u8 conf[SHA256_DIGEST_LENGTH], *cruft = NULL, *ptr;
293 wpa_printf(MSG_DEBUG, "EAP-pwd: Confirm/Request");
295 /* Each component of the cruft will be at most as big as the prime */
296 if (((cruft = os_malloc(BN_num_bytes(data->grp->prime))) == NULL) ||
297 ((x = BN_new()) == NULL) || ((y = BN_new()) == NULL)) {
298 wpa_printf(MSG_INFO, "EAP-PWD (server): debug allocation "
304 * commit is H(k | server_element | server_scalar | peer_element |
305 * peer_scalar | ciphersuite)
310 * Zero the memory each time because this is mod prime math and some
311 * value may start with a few zeros and the previous one did not.
315 os_memset(cruft, 0, BN_num_bytes(data->grp->prime));
316 offset = BN_num_bytes(data->grp->prime) - BN_num_bytes(data->k);
317 BN_bn2bin(data->k, cruft + offset);
318 H_Update(&ctx, cruft, BN_num_bytes(data->grp->prime));
320 /* server element: x, y */
321 if (!EC_POINT_get_affine_coordinates_GFp(data->grp->group,
322 data->my_element, x, y,
324 wpa_printf(MSG_INFO, "EAP-PWD (server): confirm point "
329 os_memset(cruft, 0, BN_num_bytes(data->grp->prime));
330 offset = BN_num_bytes(data->grp->prime) - BN_num_bytes(x);
331 BN_bn2bin(x, cruft + offset);
332 H_Update(&ctx, cruft, BN_num_bytes(data->grp->prime));
333 os_memset(cruft, 0, BN_num_bytes(data->grp->prime));
334 offset = BN_num_bytes(data->grp->prime) - BN_num_bytes(y);
335 BN_bn2bin(y, cruft + offset);
336 H_Update(&ctx, cruft, BN_num_bytes(data->grp->prime));
339 os_memset(cruft, 0, BN_num_bytes(data->grp->prime));
340 offset = BN_num_bytes(data->grp->order) -
341 BN_num_bytes(data->my_scalar);
342 BN_bn2bin(data->my_scalar, cruft + offset);
343 H_Update(&ctx, cruft, BN_num_bytes(data->grp->order));
345 /* peer element: x, y */
346 if (!EC_POINT_get_affine_coordinates_GFp(data->grp->group,
347 data->peer_element, x, y,
349 wpa_printf(MSG_INFO, "EAP-PWD (server): confirm point "
354 os_memset(cruft, 0, BN_num_bytes(data->grp->prime));
355 offset = BN_num_bytes(data->grp->prime) - BN_num_bytes(x);
356 BN_bn2bin(x, cruft + offset);
357 H_Update(&ctx, cruft, BN_num_bytes(data->grp->prime));
358 os_memset(cruft, 0, BN_num_bytes(data->grp->prime));
359 offset = BN_num_bytes(data->grp->prime) - BN_num_bytes(y);
360 BN_bn2bin(y, cruft + offset);
361 H_Update(&ctx, cruft, BN_num_bytes(data->grp->prime));
364 os_memset(cruft, 0, BN_num_bytes(data->grp->prime));
365 offset = BN_num_bytes(data->grp->order) -
366 BN_num_bytes(data->peer_scalar);
367 BN_bn2bin(data->peer_scalar, cruft + offset);
368 H_Update(&ctx, cruft, BN_num_bytes(data->grp->order));
371 grp = htons(data->group_num);
372 os_memset(cruft, 0, BN_num_bytes(data->grp->prime));
374 os_memcpy(ptr, &grp, sizeof(u16));
376 *ptr = EAP_PWD_DEFAULT_RAND_FUNC;
378 *ptr = EAP_PWD_DEFAULT_PRF;
380 H_Update(&ctx, cruft, ptr-cruft);
382 /* all done with the random function */
384 os_memcpy(data->my_confirm, conf, SHA256_DIGEST_LENGTH);
386 req = eap_msg_alloc(EAP_VENDOR_IETF, EAP_TYPE_PWD,
387 1 + SHA256_DIGEST_LENGTH,
388 EAP_CODE_REQUEST, id);
392 wpabuf_put_u8(req, EAP_PWD_OPCODE_CONFIRM_EXCH);
393 wpabuf_put_data(req, conf, SHA256_DIGEST_LENGTH);
400 eap_pwd_state(data, FAILURE);
406 static struct wpabuf *
407 eap_pwd_build_req(struct eap_sm *sm, void *priv, u8 id)
409 struct eap_pwd_data *data = priv;
411 switch (data->state) {
413 return eap_pwd_build_id_req(sm, data, id);
415 return eap_pwd_build_commit_req(sm, data, id);
416 case PWD_Confirm_Req:
417 return eap_pwd_build_confirm_req(sm, data, id);
419 wpa_printf(MSG_INFO, "EAP-pwd: Unknown state %d in build_req",
428 static Boolean eap_pwd_check(struct eap_sm *sm, void *priv,
429 struct wpabuf *respData)
431 struct eap_pwd_data *data = priv;
435 pos = eap_hdr_validate(EAP_VENDOR_IETF, EAP_TYPE_PWD, respData, &len);
436 if (pos == NULL || len < 1) {
437 wpa_printf(MSG_INFO, "EAP-pwd: Invalid frame");
441 wpa_printf(MSG_DEBUG, "EAP-pwd: Received frame: opcode=%d", *pos);
443 if (data->state == PWD_ID_Req && *pos == EAP_PWD_OPCODE_ID_EXCH)
446 if (data->state == PWD_Commit_Req &&
447 *pos == EAP_PWD_OPCODE_COMMIT_EXCH)
450 if (data->state == PWD_Confirm_Req &&
451 *pos == EAP_PWD_OPCODE_CONFIRM_EXCH)
454 wpa_printf(MSG_INFO, "EAP-pwd: Unexpected opcode=%d in state=%d",
461 static void eap_pwd_process_id_resp(struct eap_sm *sm,
462 struct eap_pwd_data *data,
463 const u8 *payload, size_t payload_len)
465 struct eap_pwd_id *id;
467 if (payload_len < sizeof(struct eap_pwd_id)) {
468 wpa_printf(MSG_INFO, "EAP-pwd: Invalid ID response");
472 id = (struct eap_pwd_id *) payload;
473 if ((data->group_num != be_to_host16(id->group_num)) ||
474 (id->random_function != EAP_PWD_DEFAULT_RAND_FUNC) ||
475 (os_memcmp(id->token, (u8 *)&data->token, sizeof(data->token))) ||
476 (id->prf != EAP_PWD_DEFAULT_PRF)) {
477 wpa_printf(MSG_INFO, "EAP-pwd: peer changed parameters");
478 eap_pwd_state(data, FAILURE);
481 data->id_peer = os_malloc(payload_len - sizeof(struct eap_pwd_id));
482 if (data->id_peer == NULL) {
483 wpa_printf(MSG_INFO, "EAP-PWD: memory allocation id fail");
486 data->id_peer_len = payload_len - sizeof(struct eap_pwd_id);
487 os_memcpy(data->id_peer, id->identity, data->id_peer_len);
488 wpa_hexdump_ascii(MSG_DEBUG, "EAP-PWD (server): peer sent id of",
489 data->id_peer, data->id_peer_len);
491 if ((data->grp = os_malloc(sizeof(EAP_PWD_group))) == NULL) {
492 wpa_printf(MSG_INFO, "EAP-PWD: failed to allocate memory for "
496 if (compute_password_element(data->grp, data->group_num,
497 data->password, data->password_len,
498 data->id_server, data->id_server_len,
499 data->id_peer, data->id_peer_len,
500 (u8 *) &data->token)) {
501 wpa_printf(MSG_INFO, "EAP-PWD (server): unable to compute "
505 wpa_printf(MSG_DEBUG, "EAP-PWD (server): computed %d bit PWE...",
506 BN_num_bits(data->grp->prime));
508 eap_pwd_state(data, PWD_Commit_Req);
513 eap_pwd_process_commit_resp(struct eap_sm *sm, struct eap_pwd_data *data,
514 const u8 *payload, size_t payload_len)
517 BIGNUM *x = NULL, *y = NULL, *cofactor = NULL;
518 EC_POINT *K = NULL, *point = NULL;
521 wpa_printf(MSG_DEBUG, "EAP-pwd: Received commit response");
523 if (((data->peer_scalar = BN_new()) == NULL) ||
524 ((data->k = BN_new()) == NULL) ||
525 ((cofactor = BN_new()) == NULL) ||
526 ((x = BN_new()) == NULL) ||
527 ((y = BN_new()) == NULL) ||
528 ((point = EC_POINT_new(data->grp->group)) == NULL) ||
529 ((K = EC_POINT_new(data->grp->group)) == NULL) ||
530 ((data->peer_element = EC_POINT_new(data->grp->group)) == NULL)) {
531 wpa_printf(MSG_INFO, "EAP-PWD (server): peer data allocation "
536 if (!EC_GROUP_get_cofactor(data->grp->group, cofactor, NULL)) {
537 wpa_printf(MSG_INFO, "EAP-PWD (server): unable to get "
538 "cofactor for curve");
542 /* element, x then y, followed by scalar */
543 ptr = (u8 *) payload;
544 BN_bin2bn(ptr, BN_num_bytes(data->grp->prime), x);
545 ptr += BN_num_bytes(data->grp->prime);
546 BN_bin2bn(ptr, BN_num_bytes(data->grp->prime), y);
547 ptr += BN_num_bytes(data->grp->prime);
548 BN_bin2bn(ptr, BN_num_bytes(data->grp->order), data->peer_scalar);
549 if (!EC_POINT_set_affine_coordinates_GFp(data->grp->group,
550 data->peer_element, x, y,
552 wpa_printf(MSG_INFO, "EAP-PWD (server): setting peer element "
557 /* check to ensure peer's element is not in a small sub-group */
558 if (BN_cmp(cofactor, BN_value_one())) {
559 if (!EC_POINT_mul(data->grp->group, point, NULL,
560 data->peer_element, cofactor, NULL)) {
561 wpa_printf(MSG_INFO, "EAP-PWD (server): cannot "
562 "multiply peer element by order");
565 if (EC_POINT_is_at_infinity(data->grp->group, point)) {
566 wpa_printf(MSG_INFO, "EAP-PWD (server): peer element "
567 "is at infinity!\n");
572 /* compute the shared key, k */
573 if ((!EC_POINT_mul(data->grp->group, K, NULL, data->grp->pwe,
574 data->peer_scalar, data->bnctx)) ||
575 (!EC_POINT_add(data->grp->group, K, K, data->peer_element,
577 (!EC_POINT_mul(data->grp->group, K, NULL, K, data->private_value,
579 wpa_printf(MSG_INFO, "EAP-PWD (server): computing shared key "
584 /* ensure that the shared key isn't in a small sub-group */
585 if (BN_cmp(cofactor, BN_value_one())) {
586 if (!EC_POINT_mul(data->grp->group, K, NULL, K, cofactor,
588 wpa_printf(MSG_INFO, "EAP-PWD (server): cannot "
589 "multiply shared key point by order!\n");
595 * This check is strictly speaking just for the case above where
596 * co-factor > 1 but it was suggested that even though this is probably
597 * never going to happen it is a simple and safe check "just to be
598 * sure" so let's be safe.
600 if (EC_POINT_is_at_infinity(data->grp->group, K)) {
601 wpa_printf(MSG_INFO, "EAP-PWD (server): shared key point is "
605 if (!EC_POINT_get_affine_coordinates_GFp(data->grp->group, K, data->k,
606 NULL, data->bnctx)) {
607 wpa_printf(MSG_INFO, "EAP-PWD (server): unable to extract "
608 "shared secret from secret point");
615 EC_POINT_free(point);
621 eap_pwd_state(data, PWD_Confirm_Req);
623 eap_pwd_state(data, FAILURE);
628 eap_pwd_process_confirm_resp(struct eap_sm *sm, struct eap_pwd_data *data,
629 const u8 *payload, size_t payload_len)
631 BIGNUM *x = NULL, *y = NULL;
635 u8 conf[SHA256_DIGEST_LENGTH], *cruft = NULL, *ptr;
638 /* build up the ciphersuite: group | random_function | prf */
639 grp = htons(data->group_num);
641 os_memcpy(ptr, &grp, sizeof(u16));
643 *ptr = EAP_PWD_DEFAULT_RAND_FUNC;
645 *ptr = EAP_PWD_DEFAULT_PRF;
647 /* each component of the cruft will be at most as big as the prime */
648 if (((cruft = os_malloc(BN_num_bytes(data->grp->prime))) == NULL) ||
649 ((x = BN_new()) == NULL) || ((y = BN_new()) == NULL)) {
650 wpa_printf(MSG_INFO, "EAP-PWD (peer): allocation fail");
655 * commit is H(k | peer_element | peer_scalar | server_element |
656 * server_scalar | ciphersuite)
661 os_memset(cruft, 0, BN_num_bytes(data->grp->prime));
662 offset = BN_num_bytes(data->grp->prime) - BN_num_bytes(data->k);
663 BN_bn2bin(data->k, cruft + offset);
664 H_Update(&ctx, cruft, BN_num_bytes(data->grp->prime));
666 /* peer element: x, y */
667 if (!EC_POINT_get_affine_coordinates_GFp(data->grp->group,
668 data->peer_element, x, y,
670 wpa_printf(MSG_INFO, "EAP-PWD (server): confirm point "
674 os_memset(cruft, 0, BN_num_bytes(data->grp->prime));
675 offset = BN_num_bytes(data->grp->prime) - BN_num_bytes(x);
676 BN_bn2bin(x, cruft + offset);
677 H_Update(&ctx, cruft, BN_num_bytes(data->grp->prime));
678 os_memset(cruft, 0, BN_num_bytes(data->grp->prime));
679 offset = BN_num_bytes(data->grp->prime) - BN_num_bytes(y);
680 BN_bn2bin(y, cruft + offset);
681 H_Update(&ctx, cruft, BN_num_bytes(data->grp->prime));
684 os_memset(cruft, 0, BN_num_bytes(data->grp->prime));
685 offset = BN_num_bytes(data->grp->order) -
686 BN_num_bytes(data->peer_scalar);
687 BN_bn2bin(data->peer_scalar, cruft + offset);
688 H_Update(&ctx, cruft, BN_num_bytes(data->grp->order));
690 /* server element: x, y */
691 if (!EC_POINT_get_affine_coordinates_GFp(data->grp->group,
692 data->my_element, x, y,
694 wpa_printf(MSG_INFO, "EAP-PWD (server): confirm point "
699 os_memset(cruft, 0, BN_num_bytes(data->grp->prime));
700 offset = BN_num_bytes(data->grp->prime) - BN_num_bytes(x);
701 BN_bn2bin(x, cruft + offset);
702 H_Update(&ctx, cruft, BN_num_bytes(data->grp->prime));
703 os_memset(cruft, 0, BN_num_bytes(data->grp->prime));
704 offset = BN_num_bytes(data->grp->prime) - BN_num_bytes(y);
705 BN_bn2bin(y, cruft + offset);
706 H_Update(&ctx, cruft, BN_num_bytes(data->grp->prime));
709 os_memset(cruft, 0, BN_num_bytes(data->grp->prime));
710 offset = BN_num_bytes(data->grp->order) -
711 BN_num_bytes(data->my_scalar);
712 BN_bn2bin(data->my_scalar, cruft + offset);
713 H_Update(&ctx, cruft, BN_num_bytes(data->grp->order));
716 os_memset(cruft, 0, BN_num_bytes(data->grp->prime));
717 H_Update(&ctx, (u8 *)&cs, sizeof(u32));
722 ptr = (u8 *) payload;
723 if (os_memcmp(conf, ptr, SHA256_DIGEST_LENGTH)) {
724 wpa_printf(MSG_INFO, "EAP-PWD (server): confirm did not "
729 wpa_printf(MSG_DEBUG, "EAP-pwd (server): confirm verified");
730 if (compute_keys(data->grp, data->bnctx, data->k,
731 data->peer_scalar, data->my_scalar, conf,
732 data->my_confirm, &cs, data->msk, data->emsk) < 0)
733 eap_pwd_state(data, FAILURE);
735 eap_pwd_state(data, SUCCESS);
744 static void eap_pwd_process(struct eap_sm *sm, void *priv,
745 struct wpabuf *respData)
747 struct eap_pwd_data *data = priv;
752 pos = eap_hdr_validate(EAP_VENDOR_IETF, EAP_TYPE_PWD, respData, &len);
753 if ((pos == NULL) || (len < 1)) {
754 wpa_printf(MSG_INFO, "Bad EAP header! pos %s and len = %d",
755 (pos == NULL) ? "is NULL" : "is not NULL",
762 case EAP_PWD_OPCODE_ID_EXCH:
763 eap_pwd_process_id_resp(sm, data, pos + 1, len - 1);
765 case EAP_PWD_OPCODE_COMMIT_EXCH:
766 eap_pwd_process_commit_resp(sm, data, pos + 1, len - 1);
768 case EAP_PWD_OPCODE_CONFIRM_EXCH:
769 eap_pwd_process_confirm_resp(sm, data, pos + 1, len - 1);
775 static u8 * eap_pwd_getkey(struct eap_sm *sm, void *priv, size_t *len)
777 struct eap_pwd_data *data = priv;
780 if (data->state != SUCCESS)
783 key = os_malloc(EAP_MSK_LEN);
787 os_memcpy(key, data->msk, EAP_MSK_LEN);
794 static u8 * eap_pwd_get_emsk(struct eap_sm *sm, void *priv, size_t *len)
796 struct eap_pwd_data *data = priv;
799 if (data->state != SUCCESS)
802 key = os_malloc(EAP_EMSK_LEN);
806 os_memcpy(key, data->emsk, EAP_EMSK_LEN);
813 static Boolean eap_pwd_is_success(struct eap_sm *sm, void *priv)
815 struct eap_pwd_data *data = priv;
816 return data->state == SUCCESS;
820 static Boolean eap_pwd_is_done(struct eap_sm *sm, void *priv)
822 struct eap_pwd_data *data = priv;
823 return (data->state == SUCCESS) || (data->state == FAILURE);
827 int eap_server_pwd_register(void)
829 struct eap_method *eap;
835 EVP_add_digest(EVP_sha256());
838 (void) gettimeofday(&tp, &tz);
839 sr ^= (tp.tv_sec ^ tp.tv_usec);
842 eap = eap_server_method_alloc(EAP_SERVER_METHOD_INTERFACE_VERSION,
843 EAP_VENDOR_IETF, EAP_TYPE_PWD,
848 eap->init = eap_pwd_init;
849 eap->reset = eap_pwd_reset;
850 eap->buildReq = eap_pwd_build_req;
851 eap->check = eap_pwd_check;
852 eap->process = eap_pwd_process;
853 eap->isDone = eap_pwd_is_done;
854 eap->getKey = eap_pwd_getkey;
855 eap->get_emsk = eap_pwd_get_emsk;
856 eap->isSuccess = eap_pwd_is_success;
858 ret = eap_server_method_register(eap);
860 eap_server_method_free(eap);