Lines Matching defs:peerkey
2 * WPA Supplicant - PeerKey for Direct Link Setup (DLS)
22 #include "peerkey.h"
48 struct wpa_peerkey *peerkey = timeout_ctx;
55 struct wpa_peerkey *peerkey)
57 eloop_cancel_timeout(wpa_supplicant_smk_timeout, sm, peerkey);
58 os_free(peerkey);
127 int ver, struct wpa_peerkey *peerkey)
137 kde_len = peerkey->rsnie_p_len +
156 os_memcpy(reply->key_nonce, peerkey->pnonce, WPA_NONCE_LEN);
162 pos = wpa_add_ie(pos, peerkey->rsnie_p, peerkey->rsnie_p_len);
165 pos = wpa_add_kde(pos, RSN_KEY_DATA_MAC_ADDR, peerkey->addr, ETH_ALEN);
168 wpa_add_kde(pos, RSN_KEY_DATA_NONCE, peerkey->inonce, WPA_NONCE_LEN);
182 struct wpa_peerkey *peerkey;
233 wpa_printf(MSG_DEBUG, "RSN: Using %s for PeerKey",
239 peerkey = os_zalloc(sizeof(*peerkey));
240 if (peerkey == NULL)
242 os_memcpy(peerkey->addr, kde.mac_addr, ETH_ALEN);
243 os_memcpy(peerkey->inonce, key->key_nonce, WPA_NONCE_LEN);
244 os_memcpy(peerkey->rsnie_i, kde.rsn_ie, kde.rsn_ie_len);
245 peerkey->rsnie_i_len = kde.rsn_ie_len;
246 peerkey->cipher = cipher;
247 peerkey->akmp = ie.key_mgmt;
249 if (random_get_bytes(peerkey->pnonce, WPA_NONCE_LEN)) {
252 wpa_supplicant_peerkey_free(sm, peerkey);
256 hdr = (struct rsn_ie_hdr *) peerkey->rsnie_p;
270 hdr->len = (pos - peerkey->rsnie_p) - 2;
271 peerkey->rsnie_p_len = pos - peerkey->rsnie_p;
273 peerkey->rsnie_p, peerkey->rsnie_p_len);
275 wpa_supplicant_send_smk_m3(sm, src_addr, key, ver, peerkey);
277 peerkey->next = sm->peerkey;
278 sm->peerkey = peerkey;
323 struct wpa_peerkey *peerkey)
341 if (peerkey->cipher != WPA_CIPHER_TKIP)
349 if (peerkey->cipher != WPA_CIPHER_TKIP)
354 os_memcpy(msg->replay_counter, peerkey->replay_counter,
356 inc_byte_array(peerkey->replay_counter, WPA_REPLAY_COUNTER_LEN);
360 peerkey->smkid, PMKID_LEN);
362 if (random_get_bytes(peerkey->inonce, WPA_NONCE_LEN)) {
369 peerkey->inonce, WPA_NONCE_LEN);
370 os_memcpy(msg->key_nonce, peerkey->inonce, WPA_NONCE_LEN);
373 MAC2STR(peerkey->addr));
374 wpa_eapol_key_send(sm, NULL, 0, ver, peerkey->addr, ETH_P_EAPOL,
380 struct wpa_peerkey *peerkey)
389 kde_len = peerkey->rsnie_i_len +
400 if (peerkey->cipher != WPA_CIPHER_TKIP)
409 if (peerkey->cipher != WPA_CIPHER_TKIP)
414 os_memcpy(msg->replay_counter, peerkey->replay_counter,
416 inc_byte_array(peerkey->replay_counter, WPA_REPLAY_COUNTER_LEN);
420 pos = wpa_add_ie(pos, peerkey->rsnie_i, peerkey->rsnie_i_len);
421 lifetime = host_to_be32(peerkey->lifetime);
425 os_memcpy(msg->key_nonce, peerkey->inonce, WPA_NONCE_LEN);
428 MAC2STR(peerkey->addr));
429 wpa_eapol_key_send(sm, peerkey->stk.kck, peerkey->stk.kck_len, ver,
430 peerkey->addr, ETH_P_EAPOL, mbuf, mlen,
435 static int wpa_supplicant_process_smk_m4(struct wpa_peerkey *peerkey,
441 if (os_memcmp(kde->smk + PMK_LEN, peerkey->pnonce, WPA_NONCE_LEN) != 0)
448 if (os_memcmp(kde->nonce, peerkey->inonce, WPA_NONCE_LEN) != 0) {
462 struct wpa_peerkey *peerkey,
477 if (os_memcmp(key->key_nonce, peerkey->inonce, WPA_NONCE_LEN) != 0) {
483 if (os_memcmp(kde->smk + PMK_LEN, peerkey->inonce, WPA_NONCE_LEN) != 0)
490 os_memcpy(peerkey->rsnie_p, kde->rsn_ie, kde->rsn_ie_len);
491 peerkey->rsnie_p_len = kde->rsn_ie_len;
492 os_memcpy(peerkey->pnonce, kde->nonce, WPA_NONCE_LEN);
505 wpa_printf(MSG_DEBUG, "RSN: Using %s for PeerKey",
507 peerkey->cipher = cipher;
517 struct wpa_peerkey *peerkey;
542 for (peerkey = sm->peerkey; peerkey; peerkey = peerkey->next) {
543 if (os_memcmp(peerkey->addr, kde.mac_addr, ETH_ALEN) == 0 &&
544 os_memcmp(peerkey->initiator ? peerkey->inonce :
545 peerkey->pnonce,
549 if (peerkey == NULL) {
556 if (peerkey->initiator) {
558 peerkey, &kde) < 0)
561 if (wpa_supplicant_process_smk_m4(peerkey, &kde) < 0)
565 os_memcpy(peerkey->smk, kde.smk, PMK_LEN);
566 peerkey->smk_complete = 1;
567 wpa_hexdump_key(MSG_DEBUG, "RSN: SMK", peerkey->smk, PMK_LEN);
572 peerkey->lifetime = lifetime;
574 sm, peerkey);
576 if (peerkey->initiator) {
577 peerkey->smk, peerkey->pnonce, peerkey->addr,
578 peerkey->inonce, sm->own_addr, peerkey->smkid,
579 peerkey->akmp);
580 wpa_supplicant_send_stk_1_of_4(sm, peerkey);
582 rsn_smkid(peerkey->smk, peerkey->pnonce, sm->own_addr,
583 peerkey->inonce, peerkey->addr, peerkey->smkid,
584 peerkey->akmp);
586 wpa_hexdump(MSG_DEBUG, "RSN: SMKID", peerkey->smkid, PMKID_LEN);
635 struct wpa_peerkey *peerkey;
637 for (peerkey = sm->peerkey; peerkey; peerkey = peerkey->next) {
638 if (os_memcmp(peerkey->addr, kde.mac_addr, ETH_ALEN) ==
642 if (peerkey == NULL) {
655 struct wpa_peerkey *peerkey,
667 MACSTR " (ver=%d)", MAC2STR(peerkey->addr), ver);
678 if (os_memcmp_const(ie.pmkid, peerkey->smkid, PMKID_LEN) != 0) {
684 if (random_get_bytes(peerkey->pnonce, WPA_NONCE_LEN)) {
690 peerkey->pnonce, WPA_NONCE_LEN);
694 stk = &peerkey->tstk;
695 wpa_pmk_to_ptk(peerkey->smk, PMK_LEN, "Peer key expansion",
696 sm->own_addr, peerkey->addr,
697 peerkey->pnonce, key->key_nonce,
698 stk, peerkey->akmp, peerkey->cipher);
703 peerkey->tstk_set = 1;
705 kde_buf_len = peerkey->rsnie_p_len +
712 pos = wpa_add_ie(pos, peerkey->rsnie_p, peerkey->rsnie_p_len);
713 lifetime = host_to_be32(peerkey->lifetime);
716 wpa_add_kde(pos, RSN_KEY_DATA_PMKID, peerkey->smkid, PMKID_LEN);
718 if (wpa_supplicant_send_2_of_4(sm, peerkey->addr, key, ver,
719 peerkey->pnonce, kde_buf, kde_buf_len,
726 os_memcpy(peerkey->inonce, key->key_nonce, WPA_NONCE_LEN);
731 struct wpa_peerkey *peerkey,
741 if (lifetime >= peerkey->lifetime) {
744 "seconds - ignored", lifetime, peerkey->lifetime);
750 lifetime, peerkey->lifetime);
751 peerkey->lifetime = lifetime;
753 eloop_cancel_timeout(wpa_supplicant_smk_timeout, sm, peerkey);
755 sm, peerkey);
760 struct wpa_peerkey *peerkey,
768 MACSTR " (ver=%d)", MAC2STR(peerkey->addr), ver);
781 if (os_memcmp_const(kde.pmkid, peerkey->smkid, PMKID_LEN) != 0) {
787 if (kde.rsn_ie_len != peerkey->rsnie_p_len ||
788 os_memcmp(kde.rsn_ie, peerkey->rsnie_p, kde.rsn_ie_len) != 0) {
792 peerkey->rsnie_p, peerkey->rsnie_p_len);
798 wpa_supplicant_update_smk_lifetime(sm, peerkey, &kde);
800 wpa_supplicant_send_stk_3_of_4(sm, peerkey);
801 os_memcpy(peerkey->pnonce, key->key_nonce, WPA_NONCE_LEN);
806 struct wpa_peerkey *peerkey,
817 MACSTR " (ver=%d)", MAC2STR(peerkey->addr), ver);
830 if (kde.rsn_ie_len != peerkey->rsnie_i_len ||
831 os_memcmp(kde.rsn_ie, peerkey->rsnie_i, kde.rsn_ie_len) != 0) {
836 peerkey->rsnie_i, peerkey->rsnie_i_len);
843 if (os_memcmp(peerkey->inonce, key->key_nonce, WPA_NONCE_LEN) != 0) {
847 MAC2STR(peerkey->addr));
851 wpa_supplicant_update_smk_lifetime(sm, peerkey, &kde);
853 if (wpa_supplicant_send_4_of_4(sm, peerkey->addr, key, ver,
855 &peerkey->stk))
858 _key = peerkey->stk.tk;
859 if (peerkey->cipher == WPA_CIPHER_TKIP) {
870 if (wpa_sm_set_key(sm, peerkey->cipher, peerkey->addr, 0, 1,
882 struct wpa_peerkey *peerkey,
889 MACSTR " (ver=%d)", MAC2STR(peerkey->addr), ver);
892 if (wpa_sm_set_key(sm, peerkey->cipher, peerkey->addr, 0, 1,
893 rsc, sizeof(rsc), peerkey->stk.tk,
894 peerkey->cipher == WPA_CIPHER_TKIP ? 32 : 16) < 0) {
903 * peerkey_verify_eapol_key_mic - Verify PeerKey MIC
905 * @peerkey: Pointer to the PeerKey data for the peer
913 struct wpa_peerkey *peerkey,
921 if (peerkey->initiator && !peerkey->stk_set) {
922 wpa_pmk_to_ptk(peerkey->smk, PMK_LEN, "Peer key expansion",
923 sm->own_addr, peerkey->addr,
924 peerkey->inonce, key->key_nonce,
925 &peerkey->stk, peerkey->akmp, peerkey->cipher);
926 peerkey->stk_set = 1;
930 if (peerkey->tstk_set) {
932 wpa_eapol_key_mic(peerkey->tstk.kck, peerkey->tstk.kck_len,
939 peerkey->tstk_set = 0;
940 peerkey->stk_set = 1;
941 os_memcpy(&peerkey->stk, &peerkey->tstk,
942 sizeof(peerkey->stk));
943 os_memset(&peerkey->tstk, 0, sizeof(peerkey->tstk));
947 if (!ok && peerkey->stk_set) {
949 wpa_eapol_key_mic(peerkey->stk.kck, peerkey->stk.kck_len,
965 os_memcpy(peerkey->replay_counter, key->replay_counter,
967 peerkey->replay_counter_set = 1;
989 struct wpa_peerkey *peerkey;
1015 peerkey = os_zalloc(sizeof(*peerkey));
1016 if (peerkey == NULL)
1018 peerkey->initiator = 1;
1019 os_memcpy(peerkey->addr, peer, ETH_ALEN);
1020 peerkey->akmp = sm->key_mgmt;
1027 hdr = (struct rsn_ie_hdr *) peerkey->rsnie_i;
1042 hdr->len = (pos - peerkey->rsnie_i) - 2;
1043 peerkey->rsnie_i_len = pos - peerkey->rsnie_i;
1045 peerkey->rsnie_i, peerkey->rsnie_i_len);
1047 kde_len = peerkey->rsnie_i_len + 2 + RSN_SELECTOR_LEN + ETH_ALEN;
1053 wpa_supplicant_peerkey_free(sm, peerkey);
1066 if (random_get_bytes(peerkey->inonce, WPA_NONCE_LEN)) {
1070 wpa_supplicant_peerkey_free(sm, peerkey);
1073 os_memcpy(req->key_nonce, peerkey->inonce, WPA_NONCE_LEN);
1081 pos = wpa_add_ie(pos, peerkey->rsnie_i, peerkey->rsnie_i_len);
1090 peerkey->next = sm->peerkey;
1091 sm->peerkey = peerkey;
1098 * peerkey_deinit - Free PeerKey values
1103 struct wpa_peerkey *prev, *peerkey = sm->peerkey;
1104 while (peerkey) {
1105 prev = peerkey;
1106 peerkey = peerkey->next;
1109 sm->peerkey = NULL;
1113 void peerkey_rx_eapol_4way(struct wpa_sm *sm, struct wpa_peerkey *peerkey,
1120 wpa_supplicant_process_stk_3_of_4(sm, peerkey, key, ver,
1124 wpa_supplicant_process_stk_1_of_4(sm, peerkey, key, ver,
1128 wpa_supplicant_process_stk_4_of_4(sm, peerkey, key, ver);
1131 wpa_supplicant_process_stk_2_of_4(sm, peerkey, key, ver,