2 * WPA/RSN - Shared functions for supplicant and authenticator
3 * Copyright (c) 2002-2018, Jouni Malinen <j@w1.fi>
5 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
12 #include "crypto/md5.h"
13 #include "crypto/sha1.h"
14 #include "crypto/sha256.h"
15 #include "crypto/sha384.h"
16 #include "crypto/sha512.h"
17 #include "crypto/aes_wrap.h"
18 #include "crypto/crypto.h"
19 #include "ieee802_11_defs.h"
21 #include "wpa_common.h"
24 static unsigned int wpa_kck_len(int akmp
, size_t pmk_len
)
27 case WPA_KEY_MGMT_IEEE8021X_SUITE_B_192
:
28 case WPA_KEY_MGMT_FT_IEEE8021X_SHA384
:
30 case WPA_KEY_MGMT_FILS_SHA256
:
31 case WPA_KEY_MGMT_FT_FILS_SHA256
:
32 case WPA_KEY_MGMT_FILS_SHA384
:
33 case WPA_KEY_MGMT_FT_FILS_SHA384
:
35 case WPA_KEY_MGMT_DPP
:
37 case WPA_KEY_MGMT_OWE
:
45 #ifdef CONFIG_IEEE80211R
46 static unsigned int wpa_kck2_len(int akmp
)
49 case WPA_KEY_MGMT_FT_FILS_SHA256
:
51 case WPA_KEY_MGMT_FT_FILS_SHA384
:
57 #endif /* CONFIG_IEEE80211R */
60 static unsigned int wpa_kek_len(int akmp
, size_t pmk_len
)
63 case WPA_KEY_MGMT_FILS_SHA384
:
64 case WPA_KEY_MGMT_FT_FILS_SHA384
:
66 case WPA_KEY_MGMT_IEEE8021X_SUITE_B_192
:
67 case WPA_KEY_MGMT_FILS_SHA256
:
68 case WPA_KEY_MGMT_FT_FILS_SHA256
:
69 case WPA_KEY_MGMT_FT_IEEE8021X_SHA384
:
71 case WPA_KEY_MGMT_DPP
:
72 return pmk_len
<= 32 ? 16 : 32;
73 case WPA_KEY_MGMT_OWE
:
74 return pmk_len
<= 32 ? 16 : 32;
81 #ifdef CONFIG_IEEE80211R
82 static unsigned int wpa_kek2_len(int akmp
)
85 case WPA_KEY_MGMT_FT_FILS_SHA256
:
87 case WPA_KEY_MGMT_FT_FILS_SHA384
:
93 #endif /* CONFIG_IEEE80211R */
96 unsigned int wpa_mic_len(int akmp
, size_t pmk_len
)
99 case WPA_KEY_MGMT_IEEE8021X_SUITE_B_192
:
100 case WPA_KEY_MGMT_FT_IEEE8021X_SHA384
:
102 case WPA_KEY_MGMT_FILS_SHA256
:
103 case WPA_KEY_MGMT_FILS_SHA384
:
104 case WPA_KEY_MGMT_FT_FILS_SHA256
:
105 case WPA_KEY_MGMT_FT_FILS_SHA384
:
107 case WPA_KEY_MGMT_DPP
:
109 case WPA_KEY_MGMT_OWE
:
118 * wpa_use_akm_defined - Is AKM-defined Key Descriptor Version used
119 * @akmp: WPA_KEY_MGMT_* used in key derivation
120 * Returns: 1 if AKM-defined Key Descriptor Version is used; 0 otherwise
122 int wpa_use_akm_defined(int akmp
)
124 return akmp
== WPA_KEY_MGMT_OSEN
||
125 akmp
== WPA_KEY_MGMT_OWE
||
126 akmp
== WPA_KEY_MGMT_DPP
||
127 akmp
== WPA_KEY_MGMT_FT_IEEE8021X_SHA384
||
128 wpa_key_mgmt_sae(akmp
) ||
129 wpa_key_mgmt_suite_b(akmp
) ||
130 wpa_key_mgmt_fils(akmp
);
135 * wpa_use_cmac - Is CMAC integrity algorithm used for EAPOL-Key MIC
136 * @akmp: WPA_KEY_MGMT_* used in key derivation
137 * Returns: 1 if CMAC is used; 0 otherwise
139 int wpa_use_cmac(int akmp
)
141 return akmp
== WPA_KEY_MGMT_OSEN
||
142 akmp
== WPA_KEY_MGMT_OWE
||
143 akmp
== WPA_KEY_MGMT_DPP
||
144 wpa_key_mgmt_ft(akmp
) ||
145 wpa_key_mgmt_sha256(akmp
) ||
146 wpa_key_mgmt_sae(akmp
) ||
147 wpa_key_mgmt_suite_b(akmp
);
152 * wpa_use_aes_key_wrap - Is AES Keywrap algorithm used for EAPOL-Key Key Data
153 * @akmp: WPA_KEY_MGMT_* used in key derivation
154 * Returns: 1 if AES Keywrap is used; 0 otherwise
156 * Note: AKM 00-0F-AC:1 and 00-0F-AC:2 have special rules for selecting whether
157 * to use AES Keywrap based on the negotiated pairwise cipher. This function
158 * does not cover those special cases.
160 int wpa_use_aes_key_wrap(int akmp
)
162 return akmp
== WPA_KEY_MGMT_OSEN
||
163 akmp
== WPA_KEY_MGMT_OWE
||
164 akmp
== WPA_KEY_MGMT_DPP
||
165 wpa_key_mgmt_ft(akmp
) ||
166 wpa_key_mgmt_sha256(akmp
) ||
167 wpa_key_mgmt_sae(akmp
) ||
168 wpa_key_mgmt_suite_b(akmp
);
173 * wpa_eapol_key_mic - Calculate EAPOL-Key MIC
174 * @key: EAPOL-Key Key Confirmation Key (KCK)
175 * @key_len: KCK length in octets
176 * @akmp: WPA_KEY_MGMT_* used in key derivation
177 * @ver: Key descriptor version (WPA_KEY_INFO_TYPE_*)
178 * @buf: Pointer to the beginning of the EAPOL header (version field)
179 * @len: Length of the EAPOL frame (from EAPOL header to the end of the frame)
180 * @mic: Pointer to the buffer to which the EAPOL-Key MIC is written
181 * Returns: 0 on success, -1 on failure
183 * Calculate EAPOL-Key MIC for an EAPOL-Key packet. The EAPOL-Key MIC field has
184 * to be cleared (all zeroes) when calling this function.
186 * Note: 'IEEE Std 802.11i-2004 - 8.5.2 EAPOL-Key frames' has an error in the
187 * description of the Key MIC calculation. It includes packet data from the
188 * beginning of the EAPOL-Key header, not EAPOL header. This incorrect change
189 * happened during final editing of the standard and the correct behavior is
190 * defined in the last draft (IEEE 802.11i/D10).
192 int wpa_eapol_key_mic(const u8
*key
, size_t key_len
, int akmp
, int ver
,
193 const u8
*buf
, size_t len
, u8
*mic
)
195 u8 hash
[SHA512_MAC_LEN
];
198 wpa_printf(MSG_DEBUG
,
199 "WPA: KCK not set - cannot calculate MIC");
205 case WPA_KEY_INFO_TYPE_HMAC_MD5_RC4
:
206 wpa_printf(MSG_DEBUG
, "WPA: EAPOL-Key MIC using HMAC-MD5");
207 return hmac_md5(key
, key_len
, buf
, len
, mic
);
208 #endif /* CONFIG_FIPS */
209 case WPA_KEY_INFO_TYPE_HMAC_SHA1_AES
:
210 wpa_printf(MSG_DEBUG
, "WPA: EAPOL-Key MIC using HMAC-SHA1");
211 if (hmac_sha1(key
, key_len
, buf
, len
, hash
))
213 os_memcpy(mic
, hash
, MD5_MAC_LEN
);
215 case WPA_KEY_INFO_TYPE_AES_128_CMAC
:
216 wpa_printf(MSG_DEBUG
, "WPA: EAPOL-Key MIC using AES-CMAC");
217 return omac1_aes_128(key
, buf
, len
, mic
);
218 case WPA_KEY_INFO_TYPE_AKM_DEFINED
:
221 case WPA_KEY_MGMT_SAE
:
222 case WPA_KEY_MGMT_FT_SAE
:
223 wpa_printf(MSG_DEBUG
,
224 "WPA: EAPOL-Key MIC using AES-CMAC (AKM-defined - SAE)");
225 return omac1_aes_128(key
, buf
, len
, mic
);
226 #endif /* CONFIG_SAE */
228 case WPA_KEY_MGMT_OSEN
:
229 wpa_printf(MSG_DEBUG
,
230 "WPA: EAPOL-Key MIC using AES-CMAC (AKM-defined - OSEN)");
231 return omac1_aes_128(key
, buf
, len
, mic
);
232 #endif /* CONFIG_HS20 */
234 case WPA_KEY_MGMT_IEEE8021X_SUITE_B
:
235 wpa_printf(MSG_DEBUG
,
236 "WPA: EAPOL-Key MIC using HMAC-SHA256 (AKM-defined - Suite B)");
237 if (hmac_sha256(key
, key_len
, buf
, len
, hash
))
239 os_memcpy(mic
, hash
, MD5_MAC_LEN
);
241 #endif /* CONFIG_SUITEB */
242 #ifdef CONFIG_SUITEB192
243 case WPA_KEY_MGMT_IEEE8021X_SUITE_B_192
:
244 wpa_printf(MSG_DEBUG
,
245 "WPA: EAPOL-Key MIC using HMAC-SHA384 (AKM-defined - Suite B 192-bit)");
246 if (hmac_sha384(key
, key_len
, buf
, len
, hash
))
248 os_memcpy(mic
, hash
, 24);
250 #endif /* CONFIG_SUITEB192 */
252 case WPA_KEY_MGMT_OWE
:
253 wpa_printf(MSG_DEBUG
,
254 "WPA: EAPOL-Key MIC using HMAC-SHA%u (AKM-defined - OWE)",
255 (unsigned int) key_len
* 8 * 2);
256 if (key_len
== 128 / 8) {
257 if (hmac_sha256(key
, key_len
, buf
, len
, hash
))
259 } else if (key_len
== 192 / 8) {
260 if (hmac_sha384(key
, key_len
, buf
, len
, hash
))
262 } else if (key_len
== 256 / 8) {
263 if (hmac_sha512(key
, key_len
, buf
, len
, hash
))
267 "OWE: Unsupported KCK length: %u",
268 (unsigned int) key_len
);
271 os_memcpy(mic
, hash
, key_len
);
273 #endif /* CONFIG_OWE */
275 case WPA_KEY_MGMT_DPP
:
276 wpa_printf(MSG_DEBUG
,
277 "WPA: EAPOL-Key MIC using HMAC-SHA%u (AKM-defined - DPP)",
278 (unsigned int) key_len
* 8 * 2);
279 if (key_len
== 128 / 8) {
280 if (hmac_sha256(key
, key_len
, buf
, len
, hash
))
282 } else if (key_len
== 192 / 8) {
283 if (hmac_sha384(key
, key_len
, buf
, len
, hash
))
285 } else if (key_len
== 256 / 8) {
286 if (hmac_sha512(key
, key_len
, buf
, len
, hash
))
290 "DPP: Unsupported KCK length: %u",
291 (unsigned int) key_len
);
294 os_memcpy(mic
, hash
, key_len
);
296 #endif /* CONFIG_DPP */
297 #if defined(CONFIG_IEEE80211R) && defined(CONFIG_SHA384)
298 case WPA_KEY_MGMT_FT_IEEE8021X_SHA384
:
299 wpa_printf(MSG_DEBUG
,
300 "WPA: EAPOL-Key MIC using HMAC-SHA384 (AKM-defined - FT 802.1X SHA384)");
301 if (hmac_sha384(key
, key_len
, buf
, len
, hash
))
303 os_memcpy(mic
, hash
, 24);
305 #endif /* CONFIG_IEEE80211R && CONFIG_SHA384 */
307 wpa_printf(MSG_DEBUG
,
308 "WPA: EAPOL-Key MIC algorithm not known (AKM-defined - akmp=0x%x)",
314 wpa_printf(MSG_DEBUG
,
315 "WPA: EAPOL-Key MIC algorithm not known (ver=%d)",
325 * wpa_pmk_to_ptk - Calculate PTK from PMK, addresses, and nonces
326 * @pmk: Pairwise master key
327 * @pmk_len: Length of PMK
328 * @label: Label to use in derivation
331 * @nonce1: ANonce or SNonce
332 * @nonce2: SNonce or ANonce
333 * @ptk: Buffer for pairwise transient key
334 * @akmp: Negotiated AKM
335 * @cipher: Negotiated pairwise cipher
336 * Returns: 0 on success, -1 on failure
338 * IEEE Std 802.11i-2004 - 8.5.1.2 Pairwise key hierarchy
339 * PTK = PRF-X(PMK, "Pairwise key expansion",
340 * Min(AA, SA) || Max(AA, SA) ||
341 * Min(ANonce, SNonce) || Max(ANonce, SNonce)
344 * The optional Z.x component is used only with DPP and that part is not defined
347 int wpa_pmk_to_ptk(const u8
*pmk
, size_t pmk_len
, const char *label
,
348 const u8
*addr1
, const u8
*addr2
,
349 const u8
*nonce1
, const u8
*nonce2
,
350 struct wpa_ptk
*ptk
, int akmp
, int cipher
,
351 const u8
*z
, size_t z_len
)
353 #define MAX_Z_LEN 66 /* with NIST P-521 */
354 u8 data
[2 * ETH_ALEN
+ 2 * WPA_NONCE_LEN
+ MAX_Z_LEN
];
355 size_t data_len
= 2 * ETH_ALEN
+ 2 * WPA_NONCE_LEN
;
356 u8 tmp
[WPA_KCK_MAX_LEN
+ WPA_KEK_MAX_LEN
+ WPA_TK_MAX_LEN
];
359 int owe_ptk_workaround
= 0;
361 if (akmp
== (WPA_KEY_MGMT_OWE
| WPA_KEY_MGMT_PSK_SHA256
)) {
362 owe_ptk_workaround
= 1;
363 akmp
= WPA_KEY_MGMT_OWE
;
365 #endif /* CONFIG_OWE */
368 wpa_printf(MSG_ERROR
, "WPA: No PMK set for PTK derivation");
372 if (z_len
> MAX_Z_LEN
)
375 if (os_memcmp(addr1
, addr2
, ETH_ALEN
) < 0) {
376 os_memcpy(data
, addr1
, ETH_ALEN
);
377 os_memcpy(data
+ ETH_ALEN
, addr2
, ETH_ALEN
);
379 os_memcpy(data
, addr2
, ETH_ALEN
);
380 os_memcpy(data
+ ETH_ALEN
, addr1
, ETH_ALEN
);
383 if (os_memcmp(nonce1
, nonce2
, WPA_NONCE_LEN
) < 0) {
384 os_memcpy(data
+ 2 * ETH_ALEN
, nonce1
, WPA_NONCE_LEN
);
385 os_memcpy(data
+ 2 * ETH_ALEN
+ WPA_NONCE_LEN
, nonce2
,
388 os_memcpy(data
+ 2 * ETH_ALEN
, nonce2
, WPA_NONCE_LEN
);
389 os_memcpy(data
+ 2 * ETH_ALEN
+ WPA_NONCE_LEN
, nonce1
,
394 os_memcpy(data
+ 2 * ETH_ALEN
+ 2 * WPA_NONCE_LEN
, z
, z_len
);
398 ptk
->kck_len
= wpa_kck_len(akmp
, pmk_len
);
399 ptk
->kek_len
= wpa_kek_len(akmp
, pmk_len
);
400 ptk
->tk_len
= wpa_cipher_key_len(cipher
);
401 if (ptk
->tk_len
== 0) {
402 wpa_printf(MSG_ERROR
,
403 "WPA: Unsupported cipher (0x%x) used in PTK derivation",
407 ptk_len
= ptk
->kck_len
+ ptk
->kek_len
+ ptk
->tk_len
;
409 if (wpa_key_mgmt_sha384(akmp
)) {
410 #if defined(CONFIG_SUITEB192) || defined(CONFIG_FILS)
411 wpa_printf(MSG_DEBUG
, "WPA: PTK derivation using PRF(SHA384)");
412 if (sha384_prf(pmk
, pmk_len
, label
, data
, data_len
,
415 #else /* CONFIG_SUITEB192 || CONFIG_FILS */
417 #endif /* CONFIG_SUITEB192 || CONFIG_FILS */
418 } else if (wpa_key_mgmt_sha256(akmp
)) {
419 wpa_printf(MSG_DEBUG
, "WPA: PTK derivation using PRF(SHA256)");
420 if (sha256_prf(pmk
, pmk_len
, label
, data
, data_len
,
424 } else if (akmp
== WPA_KEY_MGMT_OWE
&& (pmk_len
== 32 ||
425 owe_ptk_workaround
)) {
426 wpa_printf(MSG_DEBUG
, "WPA: PTK derivation using PRF(SHA256)");
427 if (sha256_prf(pmk
, pmk_len
, label
, data
, data_len
,
430 } else if (akmp
== WPA_KEY_MGMT_OWE
&& pmk_len
== 48) {
431 wpa_printf(MSG_DEBUG
, "WPA: PTK derivation using PRF(SHA384)");
432 if (sha384_prf(pmk
, pmk_len
, label
, data
, data_len
,
435 } else if (akmp
== WPA_KEY_MGMT_OWE
&& pmk_len
== 64) {
436 wpa_printf(MSG_DEBUG
, "WPA: PTK derivation using PRF(SHA512)");
437 if (sha512_prf(pmk
, pmk_len
, label
, data
, data_len
,
440 } else if (akmp
== WPA_KEY_MGMT_OWE
) {
441 wpa_printf(MSG_INFO
, "OWE: Unknown PMK length %u",
442 (unsigned int) pmk_len
);
444 #endif /* CONFIG_OWE */
446 } else if (akmp
== WPA_KEY_MGMT_DPP
&& pmk_len
== 32) {
447 wpa_printf(MSG_DEBUG
, "WPA: PTK derivation using PRF(SHA256)");
448 if (sha256_prf(pmk
, pmk_len
, label
, data
, data_len
,
451 } else if (akmp
== WPA_KEY_MGMT_DPP
&& pmk_len
== 48) {
452 wpa_printf(MSG_DEBUG
, "WPA: PTK derivation using PRF(SHA384)");
453 if (sha384_prf(pmk
, pmk_len
, label
, data
, data_len
,
456 } else if (akmp
== WPA_KEY_MGMT_DPP
&& pmk_len
== 64) {
457 wpa_printf(MSG_DEBUG
, "WPA: PTK derivation using PRF(SHA512)");
458 if (sha512_prf(pmk
, pmk_len
, label
, data
, data_len
,
461 } else if (akmp
== WPA_KEY_MGMT_DPP
) {
462 wpa_printf(MSG_INFO
, "DPP: Unknown PMK length %u",
463 (unsigned int) pmk_len
);
465 #endif /* CONFIG_DPP */
467 wpa_printf(MSG_DEBUG
, "WPA: PTK derivation using PRF(SHA1)");
468 if (sha1_prf(pmk
, pmk_len
, label
, data
, data_len
, tmp
,
473 wpa_printf(MSG_DEBUG
, "WPA: PTK derivation - A1=" MACSTR
" A2=" MACSTR
,
474 MAC2STR(addr1
), MAC2STR(addr2
));
475 wpa_hexdump(MSG_DEBUG
, "WPA: Nonce1", nonce1
, WPA_NONCE_LEN
);
476 wpa_hexdump(MSG_DEBUG
, "WPA: Nonce2", nonce2
, WPA_NONCE_LEN
);
478 wpa_hexdump_key(MSG_DEBUG
, "WPA: Z.x", z
, z_len
);
479 wpa_hexdump_key(MSG_DEBUG
, "WPA: PMK", pmk
, pmk_len
);
480 wpa_hexdump_key(MSG_DEBUG
, "WPA: PTK", tmp
, ptk_len
);
482 os_memcpy(ptk
->kck
, tmp
, ptk
->kck_len
);
483 wpa_hexdump_key(MSG_DEBUG
, "WPA: KCK", ptk
->kck
, ptk
->kck_len
);
485 os_memcpy(ptk
->kek
, tmp
+ ptk
->kck_len
, ptk
->kek_len
);
486 wpa_hexdump_key(MSG_DEBUG
, "WPA: KEK", ptk
->kek
, ptk
->kek_len
);
488 os_memcpy(ptk
->tk
, tmp
+ ptk
->kck_len
+ ptk
->kek_len
, ptk
->tk_len
);
489 wpa_hexdump_key(MSG_DEBUG
, "WPA: TK", ptk
->tk
, ptk
->tk_len
);
494 os_memset(tmp
, 0, sizeof(tmp
));
495 os_memset(data
, 0, data_len
);
501 int fils_rmsk_to_pmk(int akmp
, const u8
*rmsk
, size_t rmsk_len
,
502 const u8
*snonce
, const u8
*anonce
, const u8
*dh_ss
,
503 size_t dh_ss_len
, u8
*pmk
, size_t *pmk_len
)
505 u8 nonces
[2 * FILS_NONCE_LEN
];
511 /* PMK = HMAC-Hash(SNonce || ANonce, rMSK [ || DHss ]) */
512 wpa_printf(MSG_DEBUG
, "FILS: rMSK to PMK derivation");
514 if (wpa_key_mgmt_sha384(akmp
))
515 *pmk_len
= SHA384_MAC_LEN
;
516 else if (wpa_key_mgmt_sha256(akmp
))
517 *pmk_len
= SHA256_MAC_LEN
;
521 wpa_hexdump_key(MSG_DEBUG
, "FILS: rMSK", rmsk
, rmsk_len
);
522 wpa_hexdump(MSG_DEBUG
, "FILS: SNonce", snonce
, FILS_NONCE_LEN
);
523 wpa_hexdump(MSG_DEBUG
, "FILS: ANonce", anonce
, FILS_NONCE_LEN
);
524 wpa_hexdump(MSG_DEBUG
, "FILS: DHss", dh_ss
, dh_ss_len
);
526 os_memcpy(nonces
, snonce
, FILS_NONCE_LEN
);
527 os_memcpy(&nonces
[FILS_NONCE_LEN
], anonce
, FILS_NONCE_LEN
);
536 if (wpa_key_mgmt_sha384(akmp
))
537 res
= hmac_sha384_vector(nonces
, 2 * FILS_NONCE_LEN
, num_elem
,
540 res
= hmac_sha256_vector(nonces
, 2 * FILS_NONCE_LEN
, num_elem
,
543 wpa_hexdump_key(MSG_DEBUG
, "FILS: PMK", pmk
, *pmk_len
);
550 int fils_pmkid_erp(int akmp
, const u8
*reauth
, size_t reauth_len
,
555 u8 hash
[SHA384_MAC_LEN
];
558 /* PMKID = Truncate-128(Hash(EAP-Initiate/Reauth)) */
561 if (wpa_key_mgmt_sha384(akmp
))
562 res
= sha384_vector(1, addr
, len
, hash
);
563 else if (wpa_key_mgmt_sha256(akmp
))
564 res
= sha256_vector(1, addr
, len
, hash
);
569 os_memcpy(pmkid
, hash
, PMKID_LEN
);
570 wpa_hexdump(MSG_DEBUG
, "FILS: PMKID", pmkid
, PMKID_LEN
);
575 int fils_pmk_to_ptk(const u8
*pmk
, size_t pmk_len
, const u8
*spa
, const u8
*aa
,
576 const u8
*snonce
, const u8
*anonce
, const u8
*dhss
,
577 size_t dhss_len
, struct wpa_ptk
*ptk
,
578 u8
*ick
, size_t *ick_len
, int akmp
, int cipher
,
579 u8
*fils_ft
, size_t *fils_ft_len
)
583 u8 tmp
[FILS_ICK_MAX_LEN
+ WPA_KEK_MAX_LEN
+ WPA_TK_MAX_LEN
+
586 const char *label
= "FILS PTK Derivation";
590 * FILS-Key-Data = PRF-X(PMK, "FILS PTK Derivation",
591 * SPA || AA || SNonce || ANonce [ || DHss ])
592 * ICK = L(FILS-Key-Data, 0, ICK_bits)
593 * KEK = L(FILS-Key-Data, ICK_bits, KEK_bits)
594 * TK = L(FILS-Key-Data, ICK_bits + KEK_bits, TK_bits)
595 * If doing FT initial mobility domain association:
596 * FILS-FT = L(FILS-Key-Data, ICK_bits + KEK_bits + TK_bits,
599 data_len
= 2 * ETH_ALEN
+ 2 * FILS_NONCE_LEN
+ dhss_len
;
600 data
= os_malloc(data_len
);
604 os_memcpy(pos
, spa
, ETH_ALEN
);
606 os_memcpy(pos
, aa
, ETH_ALEN
);
608 os_memcpy(pos
, snonce
, FILS_NONCE_LEN
);
609 pos
+= FILS_NONCE_LEN
;
610 os_memcpy(pos
, anonce
, FILS_NONCE_LEN
);
611 pos
+= FILS_NONCE_LEN
;
613 os_memcpy(pos
, dhss
, dhss_len
);
616 ptk
->kek_len
= wpa_kek_len(akmp
, pmk_len
);
617 ptk
->tk_len
= wpa_cipher_key_len(cipher
);
618 if (wpa_key_mgmt_sha384(akmp
))
620 else if (wpa_key_mgmt_sha256(akmp
))
624 key_data_len
= *ick_len
+ ptk
->kek_len
+ ptk
->tk_len
;
626 if (fils_ft
&& fils_ft_len
) {
627 if (akmp
== WPA_KEY_MGMT_FT_FILS_SHA256
) {
629 } else if (akmp
== WPA_KEY_MGMT_FT_FILS_SHA384
) {
635 key_data_len
+= *fils_ft_len
;
638 if (wpa_key_mgmt_sha384(akmp
)) {
639 wpa_printf(MSG_DEBUG
, "FILS: PTK derivation using PRF(SHA384)");
640 if (sha384_prf(pmk
, pmk_len
, label
, data
, data_len
,
641 tmp
, key_data_len
) < 0)
644 wpa_printf(MSG_DEBUG
, "FILS: PTK derivation using PRF(SHA256)");
645 if (sha256_prf(pmk
, pmk_len
, label
, data
, data_len
,
646 tmp
, key_data_len
) < 0)
650 wpa_printf(MSG_DEBUG
, "FILS: PTK derivation - SPA=" MACSTR
651 " AA=" MACSTR
, MAC2STR(spa
), MAC2STR(aa
));
652 wpa_hexdump(MSG_DEBUG
, "FILS: SNonce", snonce
, FILS_NONCE_LEN
);
653 wpa_hexdump(MSG_DEBUG
, "FILS: ANonce", anonce
, FILS_NONCE_LEN
);
655 wpa_hexdump_key(MSG_DEBUG
, "FILS: DHss", dhss
, dhss_len
);
656 wpa_hexdump_key(MSG_DEBUG
, "FILS: PMK", pmk
, pmk_len
);
657 wpa_hexdump_key(MSG_DEBUG
, "FILS: FILS-Key-Data", tmp
, key_data_len
);
659 os_memcpy(ick
, tmp
, *ick_len
);
660 wpa_hexdump_key(MSG_DEBUG
, "FILS: ICK", ick
, *ick_len
);
662 os_memcpy(ptk
->kek
, tmp
+ *ick_len
, ptk
->kek_len
);
663 wpa_hexdump_key(MSG_DEBUG
, "FILS: KEK", ptk
->kek
, ptk
->kek_len
);
665 os_memcpy(ptk
->tk
, tmp
+ *ick_len
+ ptk
->kek_len
, ptk
->tk_len
);
666 wpa_hexdump_key(MSG_DEBUG
, "FILS: TK", ptk
->tk
, ptk
->tk_len
);
668 if (fils_ft
&& fils_ft_len
) {
669 os_memcpy(fils_ft
, tmp
+ *ick_len
+ ptk
->kek_len
+ ptk
->tk_len
,
671 wpa_hexdump_key(MSG_DEBUG
, "FILS: FILS-FT",
672 fils_ft
, *fils_ft_len
);
678 os_memset(tmp
, 0, sizeof(tmp
));
681 bin_clear_free(data
, data_len
);
686 int fils_key_auth_sk(const u8
*ick
, size_t ick_len
, const u8
*snonce
,
687 const u8
*anonce
, const u8
*sta_addr
, const u8
*bssid
,
688 const u8
*g_sta
, size_t g_sta_len
,
689 const u8
*g_ap
, size_t g_ap_len
,
690 int akmp
, u8
*key_auth_sta
, u8
*key_auth_ap
,
691 size_t *key_auth_len
)
698 wpa_printf(MSG_DEBUG
, "FILS: Key-Auth derivation: STA-MAC=" MACSTR
699 " AP-BSSID=" MACSTR
, MAC2STR(sta_addr
), MAC2STR(bssid
));
700 wpa_hexdump_key(MSG_DEBUG
, "FILS: ICK", ick
, ick_len
);
701 wpa_hexdump(MSG_DEBUG
, "FILS: SNonce", snonce
, FILS_NONCE_LEN
);
702 wpa_hexdump(MSG_DEBUG
, "FILS: ANonce", anonce
, FILS_NONCE_LEN
);
703 wpa_hexdump(MSG_DEBUG
, "FILS: gSTA", g_sta
, g_sta_len
);
704 wpa_hexdump(MSG_DEBUG
, "FILS: gAP", g_ap
, g_ap_len
);
707 * For (Re)Association Request frame (STA->AP):
708 * Key-Auth = HMAC-Hash(ICK, SNonce || ANonce || STA-MAC || AP-BSSID
709 * [ || gSTA || gAP ])
712 len
[0] = FILS_NONCE_LEN
;
714 len
[1] = FILS_NONCE_LEN
;
719 if (g_sta
&& g_sta_len
&& g_ap
&& g_ap_len
) {
727 if (wpa_key_mgmt_sha384(akmp
)) {
729 res
= hmac_sha384_vector(ick
, ick_len
, num_elem
, addr
, len
,
731 } else if (wpa_key_mgmt_sha256(akmp
)) {
733 res
= hmac_sha256_vector(ick
, ick_len
, num_elem
, addr
, len
,
742 * For (Re)Association Response frame (AP->STA):
743 * Key-Auth = HMAC-Hash(ICK, ANonce || SNonce || AP-BSSID || STA-MAC
744 * [ || gAP || gSTA ])
750 if (g_sta
&& g_sta_len
&& g_ap
&& g_ap_len
) {
757 if (wpa_key_mgmt_sha384(akmp
))
758 res
= hmac_sha384_vector(ick
, ick_len
, num_elem
, addr
, len
,
760 else if (wpa_key_mgmt_sha256(akmp
))
761 res
= hmac_sha256_vector(ick
, ick_len
, num_elem
, addr
, len
,
766 wpa_hexdump(MSG_DEBUG
, "FILS: Key-Auth (STA)",
767 key_auth_sta
, *key_auth_len
);
768 wpa_hexdump(MSG_DEBUG
, "FILS: Key-Auth (AP)",
769 key_auth_ap
, *key_auth_len
);
774 #endif /* CONFIG_FILS */
777 #ifdef CONFIG_IEEE80211R
778 int wpa_ft_mic(const u8
*kck
, size_t kck_len
, const u8
*sta_addr
,
779 const u8
*ap_addr
, u8 transaction_seqnum
,
780 const u8
*mdie
, size_t mdie_len
,
781 const u8
*ftie
, size_t ftie_len
,
782 const u8
*rsnie
, size_t rsnie_len
,
783 const u8
*ric
, size_t ric_len
,
784 const u8
*rsnxe
, size_t rsnxe_len
,
789 size_t i
, num_elem
= 0;
791 size_t mic_len
, fte_fixed_len
;
796 } else if (kck_len
== 24) {
798 #endif /* CONFIG_SHA384 */
800 wpa_printf(MSG_WARNING
, "FT: Unsupported KCK length %u",
801 (unsigned int) kck_len
);
805 fte_fixed_len
= sizeof(struct rsn_ftie
) - 16 + mic_len
;
807 addr
[num_elem
] = sta_addr
;
808 len
[num_elem
] = ETH_ALEN
;
811 addr
[num_elem
] = ap_addr
;
812 len
[num_elem
] = ETH_ALEN
;
815 addr
[num_elem
] = &transaction_seqnum
;
820 addr
[num_elem
] = rsnie
;
821 len
[num_elem
] = rsnie_len
;
825 addr
[num_elem
] = mdie
;
826 len
[num_elem
] = mdie_len
;
830 if (ftie_len
< 2 + fte_fixed_len
)
833 /* IE hdr and mic_control */
834 addr
[num_elem
] = ftie
;
835 len
[num_elem
] = 2 + 2;
838 /* MIC field with all zeros */
839 os_memset(zero_mic
, 0, mic_len
);
840 addr
[num_elem
] = zero_mic
;
841 len
[num_elem
] = mic_len
;
845 addr
[num_elem
] = ftie
+ 2 + 2 + mic_len
;
846 len
[num_elem
] = ftie_len
- (2 + 2 + mic_len
);
850 addr
[num_elem
] = ric
;
851 len
[num_elem
] = ric_len
;
856 addr
[num_elem
] = rsnxe
;
857 len
[num_elem
] = rsnxe_len
;
861 for (i
= 0; i
< num_elem
; i
++)
862 wpa_hexdump(MSG_MSGDUMP
, "FT: MIC data", addr
[i
], len
[i
]);
865 u8 hash
[SHA384_MAC_LEN
];
867 if (hmac_sha384_vector(kck
, kck_len
, num_elem
, addr
, len
, hash
))
869 os_memcpy(mic
, hash
, 24);
871 #endif /* CONFIG_SHA384 */
873 omac1_aes_128_vector(kck
, num_elem
, addr
, len
, mic
))
880 static int wpa_ft_parse_ftie(const u8
*ie
, size_t ie_len
,
881 struct wpa_ft_ies
*parse
, int use_sha384
)
886 parse
->ftie_len
= ie_len
;
888 pos
= ie
+ (use_sha384
? sizeof(struct rsn_ftie_sha384
) :
889 sizeof(struct rsn_ftie
));
891 wpa_hexdump(MSG_DEBUG
, "FT: Parse FTE subelements", pos
, end
- pos
);
893 while (end
- pos
>= 2) {
898 if (len
> end
- pos
) {
899 wpa_printf(MSG_DEBUG
, "FT: Truncated subelement");
904 case FTIE_SUBELEM_R1KH_ID
:
905 if (len
!= FT_R1KH_ID_LEN
) {
906 wpa_printf(MSG_DEBUG
,
907 "FT: Invalid R1KH-ID length in FTIE: %d",
911 parse
->r1kh_id
= pos
;
913 case FTIE_SUBELEM_GTK
:
915 parse
->gtk_len
= len
;
917 case FTIE_SUBELEM_R0KH_ID
:
918 if (len
< 1 || len
> FT_R0KH_ID_MAX_LEN
) {
919 wpa_printf(MSG_DEBUG
,
920 "FT: Invalid R0KH-ID length in FTIE: %d",
924 parse
->r0kh_id
= pos
;
925 parse
->r0kh_id_len
= len
;
927 case FTIE_SUBELEM_IGTK
:
929 parse
->igtk_len
= len
;
932 case FTIE_SUBELEM_OCI
:
934 parse
->oci_len
= len
;
936 #endif /* CONFIG_OCV */
937 case FTIE_SUBELEM_BIGTK
:
939 parse
->bigtk_len
= len
;
942 wpa_printf(MSG_DEBUG
, "FT: Unknown subelem id %u", id
);
953 int wpa_ft_parse_ies(const u8
*ies
, size_t ies_len
,
954 struct wpa_ft_ies
*parse
, int use_sha384
)
957 struct wpa_ie_data data
;
959 const struct rsn_ftie
*ftie
;
960 int prot_ie_count
= 0;
961 int update_use_sha384
= 0;
963 if (use_sha384
< 0) {
965 update_use_sha384
= 1;
968 os_memset(parse
, 0, sizeof(*parse
));
974 while (end
- pos
>= 2) {
984 wpa_hexdump(MSG_DEBUG
, "FT: RSNE", pos
, len
);
986 parse
->rsn_len
= len
;
987 ret
= wpa_parse_wpa_ie_rsn(parse
->rsn
- 2,
991 wpa_printf(MSG_DEBUG
, "FT: Failed to parse "
995 parse
->rsn_capab
= data
.capabilities
;
996 if (data
.num_pmkid
== 1 && data
.pmkid
)
997 parse
->rsn_pmkid
= data
.pmkid
;
998 parse
->key_mgmt
= data
.key_mgmt
;
999 parse
->pairwise_cipher
= data
.pairwise_cipher
;
1000 if (update_use_sha384
) {
1002 wpa_key_mgmt_sha384(parse
->key_mgmt
);
1003 update_use_sha384
= 0;
1007 wpa_hexdump(MSG_DEBUG
, "FT: RSNXE", pos
, len
);
1011 parse
->rsnxe_len
= len
;
1013 case WLAN_EID_MOBILITY_DOMAIN
:
1014 wpa_hexdump(MSG_DEBUG
, "FT: MDE", pos
, len
);
1015 if (len
< sizeof(struct rsn_mdie
))
1018 parse
->mdie_len
= len
;
1020 case WLAN_EID_FAST_BSS_TRANSITION
:
1021 wpa_hexdump(MSG_DEBUG
, "FT: FTE", pos
, len
);
1023 const struct rsn_ftie_sha384
*ftie_sha384
;
1025 if (len
< sizeof(*ftie_sha384
))
1028 (const struct rsn_ftie_sha384
*) pos
;
1029 wpa_hexdump(MSG_DEBUG
, "FT: FTE-MIC Control",
1030 ftie_sha384
->mic_control
, 2);
1031 wpa_hexdump(MSG_DEBUG
, "FT: FTE-MIC",
1033 sizeof(ftie_sha384
->mic
));
1034 parse
->fte_anonce
= ftie_sha384
->anonce
;
1035 wpa_hexdump(MSG_DEBUG
, "FT: FTE-ANonce",
1036 ftie_sha384
->anonce
,
1038 parse
->fte_snonce
= ftie_sha384
->snonce
;
1039 wpa_hexdump(MSG_DEBUG
, "FT: FTE-SNonce",
1040 ftie_sha384
->snonce
,
1042 prot_ie_count
= ftie_sha384
->mic_control
[1];
1043 if (wpa_ft_parse_ftie(pos
, len
, parse
, 1) < 0)
1048 if (len
< sizeof(*ftie
))
1050 ftie
= (const struct rsn_ftie
*) pos
;
1051 wpa_hexdump(MSG_DEBUG
, "FT: FTE-MIC Control",
1052 ftie
->mic_control
, 2);
1053 wpa_hexdump(MSG_DEBUG
, "FT: FTE-MIC",
1054 ftie
->mic
, sizeof(ftie
->mic
));
1055 parse
->fte_anonce
= ftie
->anonce
;
1056 wpa_hexdump(MSG_DEBUG
, "FT: FTE-ANonce",
1057 ftie
->anonce
, WPA_NONCE_LEN
);
1058 parse
->fte_snonce
= ftie
->snonce
;
1059 wpa_hexdump(MSG_DEBUG
, "FT: FTE-SNonce",
1060 ftie
->snonce
, WPA_NONCE_LEN
);
1061 prot_ie_count
= ftie
->mic_control
[1];
1062 if (wpa_ft_parse_ftie(pos
, len
, parse
, 0) < 0)
1065 case WLAN_EID_TIMEOUT_INTERVAL
:
1066 wpa_hexdump(MSG_DEBUG
, "FT: Timeout Interval",
1071 parse
->tie_len
= len
;
1073 case WLAN_EID_RIC_DATA
:
1074 if (parse
->ric
== NULL
)
1075 parse
->ric
= pos
- 2;
1082 if (prot_ie_count
== 0)
1083 return 0; /* no MIC */
1086 * Check that the protected IE count matches with IEs included in the
1097 if (prot_ie_count
< 0) {
1098 wpa_printf(MSG_DEBUG
, "FT: Some required IEs not included in "
1099 "the protected IE count");
1103 if (prot_ie_count
== 0 && parse
->ric
) {
1104 wpa_printf(MSG_DEBUG
, "FT: RIC IE(s) in the frame, but not "
1105 "included in protected IE count");
1109 /* Determine the end of the RIC IE(s) */
1112 while (end
- pos
>= 2 && 2 + pos
[1] <= end
- pos
&&
1117 parse
->ric_len
= pos
- parse
->ric
;
1119 if (prot_ie_count
) {
1120 wpa_printf(MSG_DEBUG
, "FT: %d protected IEs missing from "
1121 "frame", (int) prot_ie_count
);
1127 #endif /* CONFIG_IEEE80211R */
1130 static int rsn_selector_to_bitfield(const u8
*s
)
1132 if (RSN_SELECTOR_GET(s
) == RSN_CIPHER_SUITE_NONE
)
1133 return WPA_CIPHER_NONE
;
1134 if (RSN_SELECTOR_GET(s
) == RSN_CIPHER_SUITE_TKIP
)
1135 return WPA_CIPHER_TKIP
;
1136 if (RSN_SELECTOR_GET(s
) == RSN_CIPHER_SUITE_CCMP
)
1137 return WPA_CIPHER_CCMP
;
1138 if (RSN_SELECTOR_GET(s
) == RSN_CIPHER_SUITE_AES_128_CMAC
)
1139 return WPA_CIPHER_AES_128_CMAC
;
1140 if (RSN_SELECTOR_GET(s
) == RSN_CIPHER_SUITE_GCMP
)
1141 return WPA_CIPHER_GCMP
;
1142 if (RSN_SELECTOR_GET(s
) == RSN_CIPHER_SUITE_CCMP_256
)
1143 return WPA_CIPHER_CCMP_256
;
1144 if (RSN_SELECTOR_GET(s
) == RSN_CIPHER_SUITE_GCMP_256
)
1145 return WPA_CIPHER_GCMP_256
;
1146 if (RSN_SELECTOR_GET(s
) == RSN_CIPHER_SUITE_BIP_GMAC_128
)
1147 return WPA_CIPHER_BIP_GMAC_128
;
1148 if (RSN_SELECTOR_GET(s
) == RSN_CIPHER_SUITE_BIP_GMAC_256
)
1149 return WPA_CIPHER_BIP_GMAC_256
;
1150 if (RSN_SELECTOR_GET(s
) == RSN_CIPHER_SUITE_BIP_CMAC_256
)
1151 return WPA_CIPHER_BIP_CMAC_256
;
1152 if (RSN_SELECTOR_GET(s
) == RSN_CIPHER_SUITE_NO_GROUP_ADDRESSED
)
1153 return WPA_CIPHER_GTK_NOT_USED
;
1158 static int rsn_key_mgmt_to_bitfield(const u8
*s
)
1160 if (RSN_SELECTOR_GET(s
) == RSN_AUTH_KEY_MGMT_UNSPEC_802_1X
)
1161 return WPA_KEY_MGMT_IEEE8021X
;
1162 if (RSN_SELECTOR_GET(s
) == RSN_AUTH_KEY_MGMT_PSK_OVER_802_1X
)
1163 return WPA_KEY_MGMT_PSK
;
1164 #ifdef CONFIG_IEEE80211R
1165 if (RSN_SELECTOR_GET(s
) == RSN_AUTH_KEY_MGMT_FT_802_1X
)
1166 return WPA_KEY_MGMT_FT_IEEE8021X
;
1167 if (RSN_SELECTOR_GET(s
) == RSN_AUTH_KEY_MGMT_FT_PSK
)
1168 return WPA_KEY_MGMT_FT_PSK
;
1169 #ifdef CONFIG_SHA384
1170 if (RSN_SELECTOR_GET(s
) == RSN_AUTH_KEY_MGMT_FT_802_1X_SHA384
)
1171 return WPA_KEY_MGMT_FT_IEEE8021X_SHA384
;
1172 #endif /* CONFIG_SHA384 */
1173 #endif /* CONFIG_IEEE80211R */
1174 if (RSN_SELECTOR_GET(s
) == RSN_AUTH_KEY_MGMT_802_1X_SHA256
)
1175 return WPA_KEY_MGMT_IEEE8021X_SHA256
;
1176 if (RSN_SELECTOR_GET(s
) == RSN_AUTH_KEY_MGMT_PSK_SHA256
)
1177 return WPA_KEY_MGMT_PSK_SHA256
;
1179 if (RSN_SELECTOR_GET(s
) == RSN_AUTH_KEY_MGMT_SAE
)
1180 return WPA_KEY_MGMT_SAE
;
1181 if (RSN_SELECTOR_GET(s
) == RSN_AUTH_KEY_MGMT_FT_SAE
)
1182 return WPA_KEY_MGMT_FT_SAE
;
1183 #endif /* CONFIG_SAE */
1184 if (RSN_SELECTOR_GET(s
) == RSN_AUTH_KEY_MGMT_802_1X_SUITE_B
)
1185 return WPA_KEY_MGMT_IEEE8021X_SUITE_B
;
1186 if (RSN_SELECTOR_GET(s
) == RSN_AUTH_KEY_MGMT_802_1X_SUITE_B_192
)
1187 return WPA_KEY_MGMT_IEEE8021X_SUITE_B_192
;
1188 if (RSN_SELECTOR_GET(s
) == RSN_AUTH_KEY_MGMT_FILS_SHA256
)
1189 return WPA_KEY_MGMT_FILS_SHA256
;
1190 if (RSN_SELECTOR_GET(s
) == RSN_AUTH_KEY_MGMT_FILS_SHA384
)
1191 return WPA_KEY_MGMT_FILS_SHA384
;
1192 if (RSN_SELECTOR_GET(s
) == RSN_AUTH_KEY_MGMT_FT_FILS_SHA256
)
1193 return WPA_KEY_MGMT_FT_FILS_SHA256
;
1194 if (RSN_SELECTOR_GET(s
) == RSN_AUTH_KEY_MGMT_FT_FILS_SHA384
)
1195 return WPA_KEY_MGMT_FT_FILS_SHA384
;
1197 if (RSN_SELECTOR_GET(s
) == RSN_AUTH_KEY_MGMT_OWE
)
1198 return WPA_KEY_MGMT_OWE
;
1199 #endif /* CONFIG_OWE */
1201 if (RSN_SELECTOR_GET(s
) == RSN_AUTH_KEY_MGMT_DPP
)
1202 return WPA_KEY_MGMT_DPP
;
1203 #endif /* CONFIG_DPP */
1204 if (RSN_SELECTOR_GET(s
) == RSN_AUTH_KEY_MGMT_OSEN
)
1205 return WPA_KEY_MGMT_OSEN
;
1210 int wpa_cipher_valid_group(int cipher
)
1212 return wpa_cipher_valid_pairwise(cipher
) ||
1213 cipher
== WPA_CIPHER_GTK_NOT_USED
;
1217 int wpa_cipher_valid_mgmt_group(int cipher
)
1219 return cipher
== WPA_CIPHER_AES_128_CMAC
||
1220 cipher
== WPA_CIPHER_BIP_GMAC_128
||
1221 cipher
== WPA_CIPHER_BIP_GMAC_256
||
1222 cipher
== WPA_CIPHER_BIP_CMAC_256
;
1227 * wpa_parse_wpa_ie_rsn - Parse RSN IE
1228 * @rsn_ie: Buffer containing RSN IE
1229 * @rsn_ie_len: RSN IE buffer length (including IE number and length octets)
1230 * @data: Pointer to structure that will be filled in with parsed data
1231 * Returns: 0 on success, <0 on failure
1233 int wpa_parse_wpa_ie_rsn(const u8
*rsn_ie
, size_t rsn_ie_len
,
1234 struct wpa_ie_data
*data
)
1240 os_memset(data
, 0, sizeof(*data
));
1241 data
->proto
= WPA_PROTO_RSN
;
1242 data
->pairwise_cipher
= WPA_CIPHER_CCMP
;
1243 data
->group_cipher
= WPA_CIPHER_CCMP
;
1244 data
->key_mgmt
= WPA_KEY_MGMT_IEEE8021X
;
1245 data
->capabilities
= 0;
1247 data
->num_pmkid
= 0;
1248 data
->mgmt_group_cipher
= WPA_CIPHER_AES_128_CMAC
;
1250 if (rsn_ie_len
== 0) {
1251 /* No RSN IE - fail silently */
1255 if (rsn_ie_len
< sizeof(struct rsn_ie_hdr
)) {
1256 wpa_printf(MSG_DEBUG
, "%s: ie len too short %lu",
1257 __func__
, (unsigned long) rsn_ie_len
);
1261 if (rsn_ie_len
>= 6 && rsn_ie
[1] >= 4 &&
1262 rsn_ie
[1] == rsn_ie_len
- 2 &&
1263 WPA_GET_BE32(&rsn_ie
[2]) == OSEN_IE_VENDOR_TYPE
) {
1265 left
= rsn_ie_len
- 6;
1267 data
->group_cipher
= WPA_CIPHER_GTK_NOT_USED
;
1268 data
->has_group
= 1;
1269 data
->key_mgmt
= WPA_KEY_MGMT_OSEN
;
1270 data
->proto
= WPA_PROTO_OSEN
;
1272 const struct rsn_ie_hdr
*hdr
;
1274 hdr
= (const struct rsn_ie_hdr
*) rsn_ie
;
1276 if (hdr
->elem_id
!= WLAN_EID_RSN
||
1277 hdr
->len
!= rsn_ie_len
- 2 ||
1278 WPA_GET_LE16(hdr
->version
) != RSN_VERSION
) {
1279 wpa_printf(MSG_DEBUG
, "%s: malformed ie or unknown version",
1284 pos
= (const u8
*) (hdr
+ 1);
1285 left
= rsn_ie_len
- sizeof(*hdr
);
1288 if (left
>= RSN_SELECTOR_LEN
) {
1289 data
->group_cipher
= rsn_selector_to_bitfield(pos
);
1290 data
->has_group
= 1;
1291 if (!wpa_cipher_valid_group(data
->group_cipher
)) {
1292 wpa_printf(MSG_DEBUG
,
1293 "%s: invalid group cipher 0x%x (%08x)",
1294 __func__
, data
->group_cipher
,
1298 pos
+= RSN_SELECTOR_LEN
;
1299 left
-= RSN_SELECTOR_LEN
;
1300 } else if (left
> 0) {
1301 wpa_printf(MSG_DEBUG
, "%s: ie length mismatch, %u too much",
1307 data
->pairwise_cipher
= 0;
1308 count
= WPA_GET_LE16(pos
);
1311 if (count
== 0 || count
> left
/ RSN_SELECTOR_LEN
) {
1312 wpa_printf(MSG_DEBUG
, "%s: ie count botch (pairwise), "
1313 "count %u left %u", __func__
, count
, left
);
1317 data
->has_pairwise
= 1;
1318 for (i
= 0; i
< count
; i
++) {
1319 data
->pairwise_cipher
|= rsn_selector_to_bitfield(pos
);
1320 pos
+= RSN_SELECTOR_LEN
;
1321 left
-= RSN_SELECTOR_LEN
;
1323 if (data
->pairwise_cipher
& WPA_CIPHER_AES_128_CMAC
) {
1324 wpa_printf(MSG_DEBUG
, "%s: AES-128-CMAC used as "
1325 "pairwise cipher", __func__
);
1328 } else if (left
== 1) {
1329 wpa_printf(MSG_DEBUG
, "%s: ie too short (for key mgmt)",
1336 count
= WPA_GET_LE16(pos
);
1339 if (count
== 0 || count
> left
/ RSN_SELECTOR_LEN
) {
1340 wpa_printf(MSG_DEBUG
, "%s: ie count botch (key mgmt), "
1341 "count %u left %u", __func__
, count
, left
);
1344 for (i
= 0; i
< count
; i
++) {
1345 data
->key_mgmt
|= rsn_key_mgmt_to_bitfield(pos
);
1346 pos
+= RSN_SELECTOR_LEN
;
1347 left
-= RSN_SELECTOR_LEN
;
1349 } else if (left
== 1) {
1350 wpa_printf(MSG_DEBUG
, "%s: ie too short (for capabilities)",
1356 data
->capabilities
= WPA_GET_LE16(pos
);
1362 u16 num_pmkid
= WPA_GET_LE16(pos
);
1365 if (num_pmkid
> (unsigned int) left
/ PMKID_LEN
) {
1366 wpa_printf(MSG_DEBUG
, "%s: PMKID underflow "
1367 "(num_pmkid=%u left=%d)",
1368 __func__
, num_pmkid
, left
);
1369 data
->num_pmkid
= 0;
1372 data
->num_pmkid
= num_pmkid
;
1374 pos
+= data
->num_pmkid
* PMKID_LEN
;
1375 left
-= data
->num_pmkid
* PMKID_LEN
;
1380 data
->mgmt_group_cipher
= rsn_selector_to_bitfield(pos
);
1381 if (!wpa_cipher_valid_mgmt_group(data
->mgmt_group_cipher
)) {
1382 wpa_printf(MSG_DEBUG
,
1383 "%s: Unsupported management group cipher 0x%x (%08x)",
1384 __func__
, data
->mgmt_group_cipher
,
1388 pos
+= RSN_SELECTOR_LEN
;
1389 left
-= RSN_SELECTOR_LEN
;
1393 wpa_hexdump(MSG_DEBUG
,
1394 "wpa_parse_wpa_ie_rsn: ignore trailing bytes",
1402 static int wpa_selector_to_bitfield(const u8
*s
)
1404 if (RSN_SELECTOR_GET(s
) == WPA_CIPHER_SUITE_NONE
)
1405 return WPA_CIPHER_NONE
;
1406 if (RSN_SELECTOR_GET(s
) == WPA_CIPHER_SUITE_TKIP
)
1407 return WPA_CIPHER_TKIP
;
1408 if (RSN_SELECTOR_GET(s
) == WPA_CIPHER_SUITE_CCMP
)
1409 return WPA_CIPHER_CCMP
;
1414 static int wpa_key_mgmt_to_bitfield(const u8
*s
)
1416 if (RSN_SELECTOR_GET(s
) == WPA_AUTH_KEY_MGMT_UNSPEC_802_1X
)
1417 return WPA_KEY_MGMT_IEEE8021X
;
1418 if (RSN_SELECTOR_GET(s
) == WPA_AUTH_KEY_MGMT_PSK_OVER_802_1X
)
1419 return WPA_KEY_MGMT_PSK
;
1420 if (RSN_SELECTOR_GET(s
) == WPA_AUTH_KEY_MGMT_NONE
)
1421 return WPA_KEY_MGMT_WPA_NONE
;
1426 int wpa_parse_wpa_ie_wpa(const u8
*wpa_ie
, size_t wpa_ie_len
,
1427 struct wpa_ie_data
*data
)
1429 const struct wpa_ie_hdr
*hdr
;
1434 os_memset(data
, 0, sizeof(*data
));
1435 data
->proto
= WPA_PROTO_WPA
;
1436 data
->pairwise_cipher
= WPA_CIPHER_TKIP
;
1437 data
->group_cipher
= WPA_CIPHER_TKIP
;
1438 data
->key_mgmt
= WPA_KEY_MGMT_IEEE8021X
;
1439 data
->capabilities
= 0;
1441 data
->num_pmkid
= 0;
1442 data
->mgmt_group_cipher
= 0;
1444 if (wpa_ie_len
< sizeof(struct wpa_ie_hdr
)) {
1445 wpa_printf(MSG_DEBUG
, "%s: ie len too short %lu",
1446 __func__
, (unsigned long) wpa_ie_len
);
1450 hdr
= (const struct wpa_ie_hdr
*) wpa_ie
;
1452 if (hdr
->elem_id
!= WLAN_EID_VENDOR_SPECIFIC
||
1453 hdr
->len
!= wpa_ie_len
- 2 ||
1454 RSN_SELECTOR_GET(hdr
->oui
) != WPA_OUI_TYPE
||
1455 WPA_GET_LE16(hdr
->version
) != WPA_VERSION
) {
1456 wpa_printf(MSG_DEBUG
, "%s: malformed ie or unknown version",
1461 pos
= (const u8
*) (hdr
+ 1);
1462 left
= wpa_ie_len
- sizeof(*hdr
);
1464 if (left
>= WPA_SELECTOR_LEN
) {
1465 data
->group_cipher
= wpa_selector_to_bitfield(pos
);
1466 pos
+= WPA_SELECTOR_LEN
;
1467 left
-= WPA_SELECTOR_LEN
;
1468 } else if (left
> 0) {
1469 wpa_printf(MSG_DEBUG
, "%s: ie length mismatch, %u too much",
1475 data
->pairwise_cipher
= 0;
1476 count
= WPA_GET_LE16(pos
);
1479 if (count
== 0 || count
> left
/ WPA_SELECTOR_LEN
) {
1480 wpa_printf(MSG_DEBUG
, "%s: ie count botch (pairwise), "
1481 "count %u left %u", __func__
, count
, left
);
1484 for (i
= 0; i
< count
; i
++) {
1485 data
->pairwise_cipher
|= wpa_selector_to_bitfield(pos
);
1486 pos
+= WPA_SELECTOR_LEN
;
1487 left
-= WPA_SELECTOR_LEN
;
1489 } else if (left
== 1) {
1490 wpa_printf(MSG_DEBUG
, "%s: ie too short (for key mgmt)",
1497 count
= WPA_GET_LE16(pos
);
1500 if (count
== 0 || count
> left
/ WPA_SELECTOR_LEN
) {
1501 wpa_printf(MSG_DEBUG
, "%s: ie count botch (key mgmt), "
1502 "count %u left %u", __func__
, count
, left
);
1505 for (i
= 0; i
< count
; i
++) {
1506 data
->key_mgmt
|= wpa_key_mgmt_to_bitfield(pos
);
1507 pos
+= WPA_SELECTOR_LEN
;
1508 left
-= WPA_SELECTOR_LEN
;
1510 } else if (left
== 1) {
1511 wpa_printf(MSG_DEBUG
, "%s: ie too short (for capabilities)",
1517 data
->capabilities
= WPA_GET_LE16(pos
);
1523 wpa_hexdump(MSG_DEBUG
,
1524 "wpa_parse_wpa_ie_wpa: ignore trailing bytes",
1532 int wpa_default_rsn_cipher(int freq
)
1535 return WPA_CIPHER_GCMP
; /* DMG */
1537 return WPA_CIPHER_CCMP
;
1541 #ifdef CONFIG_IEEE80211R
1544 * wpa_derive_pmk_r0 - Derive PMK-R0 and PMKR0Name
1546 * IEEE Std 802.11r-2008 - 8.5.1.5.3
1548 int wpa_derive_pmk_r0(const u8
*xxkey
, size_t xxkey_len
,
1549 const u8
*ssid
, size_t ssid_len
,
1550 const u8
*mdid
, const u8
*r0kh_id
, size_t r0kh_id_len
,
1551 const u8
*s0kh_id
, u8
*pmk_r0
, u8
*pmk_r0_name
,
1554 u8 buf
[1 + SSID_MAX_LEN
+ MOBILITY_DOMAIN_ID_LEN
+ 1 +
1555 FT_R0KH_ID_MAX_LEN
+ ETH_ALEN
];
1556 u8
*pos
, r0_key_data
[64], hash
[48];
1559 size_t q
= use_sha384
? 48 : 32;
1560 size_t r0_key_data_len
= q
+ 16;
1563 * R0-Key-Data = KDF-384(XXKey, "FT-R0",
1564 * SSIDlength || SSID || MDID || R0KHlength ||
1565 * R0KH-ID || S0KH-ID)
1566 * XXKey is either the second 256 bits of MSK or PSK; or the first
1567 * 384 bits of MSK for FT-EAP-SHA384.
1568 * PMK-R0 = L(R0-Key-Data, 0, Q)
1569 * PMK-R0Name-Salt = L(R0-Key-Data, Q, 128)
1570 * Q = 384 for FT-EAP-SHA384; otherwise, 256
1572 if (ssid_len
> SSID_MAX_LEN
|| r0kh_id_len
> FT_R0KH_ID_MAX_LEN
)
1574 wpa_printf(MSG_DEBUG
, "FT: Derive PMK-R0 using KDF-%s",
1575 use_sha384
? "SHA384" : "SHA256");
1576 wpa_hexdump_key(MSG_DEBUG
, "FT: XXKey", xxkey
, xxkey_len
);
1577 wpa_hexdump_ascii(MSG_DEBUG
, "FT: SSID", ssid
, ssid_len
);
1578 wpa_hexdump(MSG_DEBUG
, "FT: MDID", mdid
, MOBILITY_DOMAIN_ID_LEN
);
1579 wpa_hexdump_ascii(MSG_DEBUG
, "FT: R0KH-ID", r0kh_id
, r0kh_id_len
);
1580 wpa_printf(MSG_DEBUG
, "FT: S0KH-ID: " MACSTR
, MAC2STR(s0kh_id
));
1583 os_memcpy(pos
, ssid
, ssid_len
);
1585 os_memcpy(pos
, mdid
, MOBILITY_DOMAIN_ID_LEN
);
1586 pos
+= MOBILITY_DOMAIN_ID_LEN
;
1587 *pos
++ = r0kh_id_len
;
1588 os_memcpy(pos
, r0kh_id
, r0kh_id_len
);
1590 os_memcpy(pos
, s0kh_id
, ETH_ALEN
);
1593 #ifdef CONFIG_SHA384
1595 if (xxkey_len
!= SHA384_MAC_LEN
) {
1596 wpa_printf(MSG_ERROR
,
1597 "FT: Unexpected XXKey length %d (expected %d)",
1598 (int) xxkey_len
, SHA384_MAC_LEN
);
1601 if (sha384_prf(xxkey
, xxkey_len
, "FT-R0", buf
, pos
- buf
,
1602 r0_key_data
, r0_key_data_len
) < 0)
1605 #endif /* CONFIG_SHA384 */
1607 if (xxkey_len
!= PMK_LEN
) {
1608 wpa_printf(MSG_ERROR
,
1609 "FT: Unexpected XXKey length %d (expected %d)",
1610 (int) xxkey_len
, PMK_LEN
);
1613 if (sha256_prf(xxkey
, xxkey_len
, "FT-R0", buf
, pos
- buf
,
1614 r0_key_data
, r0_key_data_len
) < 0)
1617 os_memcpy(pmk_r0
, r0_key_data
, q
);
1618 wpa_hexdump_key(MSG_DEBUG
, "FT: PMK-R0", pmk_r0
, q
);
1619 wpa_hexdump_key(MSG_DEBUG
, "FT: PMK-R0Name-Salt", &r0_key_data
[q
], 16);
1622 * PMKR0Name = Truncate-128(Hash("FT-R0N" || PMK-R0Name-Salt)
1624 addr
[0] = (const u8
*) "FT-R0N";
1626 addr
[1] = &r0_key_data
[q
];
1629 #ifdef CONFIG_SHA384
1630 if (use_sha384
&& sha384_vector(2, addr
, len
, hash
) < 0)
1632 #endif /* CONFIG_SHA384 */
1633 if (!use_sha384
&& sha256_vector(2, addr
, len
, hash
) < 0)
1635 os_memcpy(pmk_r0_name
, hash
, WPA_PMK_NAME_LEN
);
1636 os_memset(r0_key_data
, 0, sizeof(r0_key_data
));
1642 * wpa_derive_pmk_r1_name - Derive PMKR1Name
1644 * IEEE Std 802.11r-2008 - 8.5.1.5.4
1646 int wpa_derive_pmk_r1_name(const u8
*pmk_r0_name
, const u8
*r1kh_id
,
1647 const u8
*s1kh_id
, u8
*pmk_r1_name
, int use_sha384
)
1654 * PMKR1Name = Truncate-128(Hash("FT-R1N" || PMKR0Name ||
1655 * R1KH-ID || S1KH-ID))
1657 addr
[0] = (const u8
*) "FT-R1N";
1659 addr
[1] = pmk_r0_name
;
1660 len
[1] = WPA_PMK_NAME_LEN
;
1662 len
[2] = FT_R1KH_ID_LEN
;
1666 #ifdef CONFIG_SHA384
1667 if (use_sha384
&& sha384_vector(4, addr
, len
, hash
) < 0)
1669 #endif /* CONFIG_SHA384 */
1670 if (!use_sha384
&& sha256_vector(4, addr
, len
, hash
) < 0)
1672 os_memcpy(pmk_r1_name
, hash
, WPA_PMK_NAME_LEN
);
1678 * wpa_derive_pmk_r1 - Derive PMK-R1 and PMKR1Name from PMK-R0
1680 * IEEE Std 802.11r-2008 - 8.5.1.5.4
1682 int wpa_derive_pmk_r1(const u8
*pmk_r0
, size_t pmk_r0_len
,
1683 const u8
*pmk_r0_name
,
1684 const u8
*r1kh_id
, const u8
*s1kh_id
,
1685 u8
*pmk_r1
, u8
*pmk_r1_name
)
1687 u8 buf
[FT_R1KH_ID_LEN
+ ETH_ALEN
];
1690 /* PMK-R1 = KDF-256(PMK-R0, "FT-R1", R1KH-ID || S1KH-ID) */
1691 wpa_printf(MSG_DEBUG
, "FT: Derive PMK-R1 using KDF-%s",
1692 pmk_r0_len
== SHA384_MAC_LEN
? "SHA384" : "SHA256");
1693 wpa_hexdump_key(MSG_DEBUG
, "FT: PMK-R0", pmk_r0
, pmk_r0_len
);
1694 wpa_hexdump(MSG_DEBUG
, "FT: R1KH-ID", r1kh_id
, FT_R1KH_ID_LEN
);
1695 wpa_printf(MSG_DEBUG
, "FT: S1KH-ID: " MACSTR
, MAC2STR(s1kh_id
));
1697 os_memcpy(pos
, r1kh_id
, FT_R1KH_ID_LEN
);
1698 pos
+= FT_R1KH_ID_LEN
;
1699 os_memcpy(pos
, s1kh_id
, ETH_ALEN
);
1702 #ifdef CONFIG_SHA384
1703 if (pmk_r0_len
== SHA384_MAC_LEN
&&
1704 sha384_prf(pmk_r0
, pmk_r0_len
, "FT-R1",
1705 buf
, pos
- buf
, pmk_r1
, pmk_r0_len
) < 0)
1707 #endif /* CONFIG_SHA384 */
1708 if (pmk_r0_len
== PMK_LEN
&&
1709 sha256_prf(pmk_r0
, pmk_r0_len
, "FT-R1",
1710 buf
, pos
- buf
, pmk_r1
, pmk_r0_len
) < 0)
1712 if (pmk_r0_len
!= SHA384_MAC_LEN
&& pmk_r0_len
!= PMK_LEN
) {
1713 wpa_printf(MSG_ERROR
, "FT: Unexpected PMK-R0 length %d",
1717 wpa_hexdump_key(MSG_DEBUG
, "FT: PMK-R1", pmk_r1
, pmk_r0_len
);
1719 return wpa_derive_pmk_r1_name(pmk_r0_name
, r1kh_id
, s1kh_id
,
1721 pmk_r0_len
== SHA384_MAC_LEN
);
1726 * wpa_pmk_r1_to_ptk - Derive PTK and PTKName from PMK-R1
1728 * IEEE Std 802.11r-2008 - 8.5.1.5.5
1730 int wpa_pmk_r1_to_ptk(const u8
*pmk_r1
, size_t pmk_r1_len
,
1731 const u8
*snonce
, const u8
*anonce
,
1732 const u8
*sta_addr
, const u8
*bssid
,
1733 const u8
*pmk_r1_name
,
1734 struct wpa_ptk
*ptk
, u8
*ptk_name
, int akmp
, int cipher
)
1736 u8 buf
[2 * WPA_NONCE_LEN
+ 2 * ETH_ALEN
];
1740 u8 tmp
[2 * WPA_KCK_MAX_LEN
+ 2 * WPA_KEK_MAX_LEN
+ WPA_TK_MAX_LEN
];
1741 size_t ptk_len
, offset
;
1742 int use_sha384
= wpa_key_mgmt_sha384(akmp
);
1745 * PTK = KDF-PTKLen(PMK-R1, "FT-PTK", SNonce || ANonce ||
1746 * BSSID || STA-ADDR)
1748 wpa_printf(MSG_DEBUG
, "FT: Derive PTK using KDF-%s",
1749 use_sha384
? "SHA384" : "SHA256");
1750 wpa_hexdump_key(MSG_DEBUG
, "FT: PMK-R1", pmk_r1
, pmk_r1_len
);
1751 wpa_hexdump(MSG_DEBUG
, "FT: SNonce", snonce
, WPA_NONCE_LEN
);
1752 wpa_hexdump(MSG_DEBUG
, "FT: ANonce", anonce
, WPA_NONCE_LEN
);
1753 wpa_printf(MSG_DEBUG
, "FT: BSSID=" MACSTR
" STA-ADDR=" MACSTR
,
1754 MAC2STR(bssid
), MAC2STR(sta_addr
));
1756 os_memcpy(pos
, snonce
, WPA_NONCE_LEN
);
1757 pos
+= WPA_NONCE_LEN
;
1758 os_memcpy(pos
, anonce
, WPA_NONCE_LEN
);
1759 pos
+= WPA_NONCE_LEN
;
1760 os_memcpy(pos
, bssid
, ETH_ALEN
);
1762 os_memcpy(pos
, sta_addr
, ETH_ALEN
);
1765 ptk
->kck_len
= wpa_kck_len(akmp
, PMK_LEN
);
1766 ptk
->kck2_len
= wpa_kck2_len(akmp
);
1767 ptk
->kek_len
= wpa_kek_len(akmp
, PMK_LEN
);
1768 ptk
->kek2_len
= wpa_kek2_len(akmp
);
1769 ptk
->tk_len
= wpa_cipher_key_len(cipher
);
1770 ptk_len
= ptk
->kck_len
+ ptk
->kek_len
+ ptk
->tk_len
+
1771 ptk
->kck2_len
+ ptk
->kek2_len
;
1773 #ifdef CONFIG_SHA384
1775 if (pmk_r1_len
!= SHA384_MAC_LEN
) {
1776 wpa_printf(MSG_ERROR
,
1777 "FT: Unexpected PMK-R1 length %d (expected %d)",
1778 (int) pmk_r1_len
, SHA384_MAC_LEN
);
1781 if (sha384_prf(pmk_r1
, pmk_r1_len
, "FT-PTK",
1782 buf
, pos
- buf
, tmp
, ptk_len
) < 0)
1785 #endif /* CONFIG_SHA384 */
1787 if (pmk_r1_len
!= PMK_LEN
) {
1788 wpa_printf(MSG_ERROR
,
1789 "FT: Unexpected PMK-R1 length %d (expected %d)",
1790 (int) pmk_r1_len
, PMK_LEN
);
1793 if (sha256_prf(pmk_r1
, pmk_r1_len
, "FT-PTK",
1794 buf
, pos
- buf
, tmp
, ptk_len
) < 0)
1797 wpa_hexdump_key(MSG_DEBUG
, "FT: PTK", tmp
, ptk_len
);
1800 * PTKName = Truncate-128(SHA-256(PMKR1Name || "FT-PTKN" || SNonce ||
1801 * ANonce || BSSID || STA-ADDR))
1803 wpa_hexdump(MSG_DEBUG
, "FT: PMKR1Name", pmk_r1_name
, WPA_PMK_NAME_LEN
);
1804 addr
[0] = pmk_r1_name
;
1805 len
[0] = WPA_PMK_NAME_LEN
;
1806 addr
[1] = (const u8
*) "FT-PTKN";
1809 len
[2] = WPA_NONCE_LEN
;
1811 len
[3] = WPA_NONCE_LEN
;
1817 if (sha256_vector(6, addr
, len
, hash
) < 0)
1819 os_memcpy(ptk_name
, hash
, WPA_PMK_NAME_LEN
);
1821 os_memcpy(ptk
->kck
, tmp
, ptk
->kck_len
);
1822 offset
= ptk
->kck_len
;
1823 os_memcpy(ptk
->kek
, tmp
+ offset
, ptk
->kek_len
);
1824 offset
+= ptk
->kek_len
;
1825 os_memcpy(ptk
->tk
, tmp
+ offset
, ptk
->tk_len
);
1826 offset
+= ptk
->tk_len
;
1827 os_memcpy(ptk
->kck2
, tmp
+ offset
, ptk
->kck2_len
);
1828 offset
+= ptk
->kck2_len
;
1829 os_memcpy(ptk
->kek2
, tmp
+ offset
, ptk
->kek2_len
);
1831 wpa_hexdump_key(MSG_DEBUG
, "FT: KCK", ptk
->kck
, ptk
->kck_len
);
1832 wpa_hexdump_key(MSG_DEBUG
, "FT: KEK", ptk
->kek
, ptk
->kek_len
);
1834 wpa_hexdump_key(MSG_DEBUG
, "FT: KCK2",
1835 ptk
->kck2
, ptk
->kck2_len
);
1837 wpa_hexdump_key(MSG_DEBUG
, "FT: KEK2",
1838 ptk
->kek2
, ptk
->kek2_len
);
1839 wpa_hexdump_key(MSG_DEBUG
, "FT: TK", ptk
->tk
, ptk
->tk_len
);
1840 wpa_hexdump(MSG_DEBUG
, "FT: PTKName", ptk_name
, WPA_PMK_NAME_LEN
);
1842 os_memset(tmp
, 0, sizeof(tmp
));
1847 #endif /* CONFIG_IEEE80211R */
1851 * rsn_pmkid - Calculate PMK identifier
1852 * @pmk: Pairwise master key
1853 * @pmk_len: Length of pmk in bytes
1854 * @aa: Authenticator address
1855 * @spa: Supplicant address
1856 * @pmkid: Buffer for PMKID
1857 * @akmp: Negotiated key management protocol
1859 * IEEE Std 802.11-2016 - 12.7.1.3 Pairwise key hierarchy
1860 * AKM: 00-0F-AC:5, 00-0F-AC:6, 00-0F-AC:14, 00-0F-AC:16
1861 * PMKID = Truncate-128(HMAC-SHA-256(PMK, "PMK Name" || AA || SPA))
1863 * See rsn_pmkid_suite_b()
1865 * See rsn_pmkid_suite_b_192()
1866 * AKM: 00-0F-AC:13, 00-0F-AC:15, 00-0F-AC:17
1867 * PMKID = Truncate-128(HMAC-SHA-384(PMK, "PMK Name" || AA || SPA))
1869 * PMKID = Truncate-128(HMAC-SHA-1(PMK, "PMK Name" || AA || SPA))
1871 void rsn_pmkid(const u8
*pmk
, size_t pmk_len
, const u8
*aa
, const u8
*spa
,
1872 u8
*pmkid
, int akmp
)
1874 char *title
= "PMK Name";
1876 const size_t len
[3] = { 8, ETH_ALEN
, ETH_ALEN
};
1877 unsigned char hash
[SHA384_MAC_LEN
];
1879 addr
[0] = (u8
*) title
;
1884 #if defined(CONFIG_FILS) || defined(CONFIG_SHA384)
1885 } else if (wpa_key_mgmt_sha384(akmp
)) {
1886 wpa_printf(MSG_DEBUG
, "RSN: Derive PMKID using HMAC-SHA-384");
1887 hmac_sha384_vector(pmk
, pmk_len
, 3, addr
, len
, hash
);
1888 #endif /* CONFIG_FILS || CONFIG_SHA384 */
1889 } else if (wpa_key_mgmt_sha256(akmp
)) {
1890 wpa_printf(MSG_DEBUG
, "RSN: Derive PMKID using HMAC-SHA-256");
1891 hmac_sha256_vector(pmk
, pmk_len
, 3, addr
, len
, hash
);
1893 wpa_printf(MSG_DEBUG
, "RSN: Derive PMKID using HMAC-SHA-1");
1894 hmac_sha1_vector(pmk
, pmk_len
, 3, addr
, len
, hash
);
1896 wpa_hexdump(MSG_DEBUG
, "RSN: Derived PMKID", hash
, PMKID_LEN
);
1897 os_memcpy(pmkid
, hash
, PMKID_LEN
);
1901 #ifdef CONFIG_SUITEB
1903 * rsn_pmkid_suite_b - Calculate PMK identifier for Suite B AKM
1904 * @kck: Key confirmation key
1905 * @kck_len: Length of kck in bytes
1906 * @aa: Authenticator address
1907 * @spa: Supplicant address
1908 * @pmkid: Buffer for PMKID
1909 * Returns: 0 on success, -1 on failure
1911 * IEEE Std 802.11ac-2013 - 11.6.1.3 Pairwise key hierarchy
1912 * PMKID = Truncate(HMAC-SHA-256(KCK, "PMK Name" || AA || SPA))
1914 int rsn_pmkid_suite_b(const u8
*kck
, size_t kck_len
, const u8
*aa
,
1915 const u8
*spa
, u8
*pmkid
)
1917 char *title
= "PMK Name";
1919 const size_t len
[3] = { 8, ETH_ALEN
, ETH_ALEN
};
1920 unsigned char hash
[SHA256_MAC_LEN
];
1922 addr
[0] = (u8
*) title
;
1926 if (hmac_sha256_vector(kck
, kck_len
, 3, addr
, len
, hash
) < 0)
1928 os_memcpy(pmkid
, hash
, PMKID_LEN
);
1931 #endif /* CONFIG_SUITEB */
1934 #ifdef CONFIG_SUITEB192
1936 * rsn_pmkid_suite_b_192 - Calculate PMK identifier for Suite B AKM
1937 * @kck: Key confirmation key
1938 * @kck_len: Length of kck in bytes
1939 * @aa: Authenticator address
1940 * @spa: Supplicant address
1941 * @pmkid: Buffer for PMKID
1942 * Returns: 0 on success, -1 on failure
1944 * IEEE Std 802.11ac-2013 - 11.6.1.3 Pairwise key hierarchy
1945 * PMKID = Truncate(HMAC-SHA-384(KCK, "PMK Name" || AA || SPA))
1947 int rsn_pmkid_suite_b_192(const u8
*kck
, size_t kck_len
, const u8
*aa
,
1948 const u8
*spa
, u8
*pmkid
)
1950 char *title
= "PMK Name";
1952 const size_t len
[3] = { 8, ETH_ALEN
, ETH_ALEN
};
1953 unsigned char hash
[SHA384_MAC_LEN
];
1955 addr
[0] = (u8
*) title
;
1959 if (hmac_sha384_vector(kck
, kck_len
, 3, addr
, len
, hash
) < 0)
1961 os_memcpy(pmkid
, hash
, PMKID_LEN
);
1964 #endif /* CONFIG_SUITEB192 */
1968 * wpa_cipher_txt - Convert cipher suite to a text string
1969 * @cipher: Cipher suite (WPA_CIPHER_* enum)
1970 * Returns: Pointer to a text string of the cipher suite name
1972 const char * wpa_cipher_txt(int cipher
)
1975 case WPA_CIPHER_NONE
:
1978 case WPA_CIPHER_WEP40
:
1980 case WPA_CIPHER_WEP104
:
1982 #endif /* CONFIG_WEP */
1983 case WPA_CIPHER_TKIP
:
1985 case WPA_CIPHER_CCMP
:
1987 case WPA_CIPHER_CCMP
| WPA_CIPHER_TKIP
:
1989 case WPA_CIPHER_GCMP
:
1991 case WPA_CIPHER_GCMP_256
:
1993 case WPA_CIPHER_CCMP_256
:
1995 case WPA_CIPHER_AES_128_CMAC
:
1997 case WPA_CIPHER_BIP_GMAC_128
:
1998 return "BIP-GMAC-128";
1999 case WPA_CIPHER_BIP_GMAC_256
:
2000 return "BIP-GMAC-256";
2001 case WPA_CIPHER_BIP_CMAC_256
:
2002 return "BIP-CMAC-256";
2003 case WPA_CIPHER_GTK_NOT_USED
:
2004 return "GTK_NOT_USED";
2012 * wpa_key_mgmt_txt - Convert key management suite to a text string
2013 * @key_mgmt: Key management suite (WPA_KEY_MGMT_* enum)
2014 * @proto: WPA/WPA2 version (WPA_PROTO_*)
2015 * Returns: Pointer to a text string of the key management suite name
2017 const char * wpa_key_mgmt_txt(int key_mgmt
, int proto
)
2020 case WPA_KEY_MGMT_IEEE8021X
:
2021 if (proto
== (WPA_PROTO_RSN
| WPA_PROTO_WPA
))
2022 return "WPA2+WPA/IEEE 802.1X/EAP";
2023 return proto
== WPA_PROTO_RSN
?
2024 "WPA2/IEEE 802.1X/EAP" : "WPA/IEEE 802.1X/EAP";
2025 case WPA_KEY_MGMT_PSK
:
2026 if (proto
== (WPA_PROTO_RSN
| WPA_PROTO_WPA
))
2027 return "WPA2-PSK+WPA-PSK";
2028 return proto
== WPA_PROTO_RSN
?
2029 "WPA2-PSK" : "WPA-PSK";
2030 case WPA_KEY_MGMT_NONE
:
2032 case WPA_KEY_MGMT_WPA_NONE
:
2034 case WPA_KEY_MGMT_IEEE8021X_NO_WPA
:
2035 return "IEEE 802.1X (no WPA)";
2036 #ifdef CONFIG_IEEE80211R
2037 case WPA_KEY_MGMT_FT_IEEE8021X
:
2039 case WPA_KEY_MGMT_FT_IEEE8021X_SHA384
:
2040 return "FT-EAP-SHA384";
2041 case WPA_KEY_MGMT_FT_PSK
:
2043 #endif /* CONFIG_IEEE80211R */
2044 case WPA_KEY_MGMT_IEEE8021X_SHA256
:
2045 return "WPA2-EAP-SHA256";
2046 case WPA_KEY_MGMT_PSK_SHA256
:
2047 return "WPA2-PSK-SHA256";
2048 case WPA_KEY_MGMT_WPS
:
2050 case WPA_KEY_MGMT_SAE
:
2052 case WPA_KEY_MGMT_FT_SAE
:
2054 case WPA_KEY_MGMT_OSEN
:
2056 case WPA_KEY_MGMT_IEEE8021X_SUITE_B
:
2057 return "WPA2-EAP-SUITE-B";
2058 case WPA_KEY_MGMT_IEEE8021X_SUITE_B_192
:
2059 return "WPA2-EAP-SUITE-B-192";
2060 case WPA_KEY_MGMT_FILS_SHA256
:
2061 return "FILS-SHA256";
2062 case WPA_KEY_MGMT_FILS_SHA384
:
2063 return "FILS-SHA384";
2064 case WPA_KEY_MGMT_FT_FILS_SHA256
:
2065 return "FT-FILS-SHA256";
2066 case WPA_KEY_MGMT_FT_FILS_SHA384
:
2067 return "FT-FILS-SHA384";
2068 case WPA_KEY_MGMT_OWE
:
2070 case WPA_KEY_MGMT_DPP
:
2078 u32
wpa_akm_to_suite(int akm
)
2080 if (akm
& WPA_KEY_MGMT_FT_IEEE8021X_SHA384
)
2081 return RSN_AUTH_KEY_MGMT_FT_802_1X_SHA384
;
2082 if (akm
& WPA_KEY_MGMT_FT_IEEE8021X
)
2083 return RSN_AUTH_KEY_MGMT_FT_802_1X
;
2084 if (akm
& WPA_KEY_MGMT_FT_PSK
)
2085 return RSN_AUTH_KEY_MGMT_FT_PSK
;
2086 if (akm
& WPA_KEY_MGMT_IEEE8021X_SHA256
)
2087 return RSN_AUTH_KEY_MGMT_802_1X_SHA256
;
2088 if (akm
& WPA_KEY_MGMT_IEEE8021X
)
2089 return RSN_AUTH_KEY_MGMT_UNSPEC_802_1X
;
2090 if (akm
& WPA_KEY_MGMT_PSK_SHA256
)
2091 return RSN_AUTH_KEY_MGMT_PSK_SHA256
;
2092 if (akm
& WPA_KEY_MGMT_PSK
)
2093 return RSN_AUTH_KEY_MGMT_PSK_OVER_802_1X
;
2094 if (akm
& WPA_KEY_MGMT_CCKM
)
2095 return RSN_AUTH_KEY_MGMT_CCKM
;
2096 if (akm
& WPA_KEY_MGMT_OSEN
)
2097 return RSN_AUTH_KEY_MGMT_OSEN
;
2098 if (akm
& WPA_KEY_MGMT_IEEE8021X_SUITE_B
)
2099 return RSN_AUTH_KEY_MGMT_802_1X_SUITE_B
;
2100 if (akm
& WPA_KEY_MGMT_IEEE8021X_SUITE_B_192
)
2101 return RSN_AUTH_KEY_MGMT_802_1X_SUITE_B_192
;
2102 if (akm
& WPA_KEY_MGMT_FILS_SHA256
)
2103 return RSN_AUTH_KEY_MGMT_FILS_SHA256
;
2104 if (akm
& WPA_KEY_MGMT_FILS_SHA384
)
2105 return RSN_AUTH_KEY_MGMT_FILS_SHA384
;
2106 if (akm
& WPA_KEY_MGMT_FT_FILS_SHA256
)
2107 return RSN_AUTH_KEY_MGMT_FT_FILS_SHA256
;
2108 if (akm
& WPA_KEY_MGMT_FT_FILS_SHA384
)
2109 return RSN_AUTH_KEY_MGMT_FT_FILS_SHA384
;
2110 if (akm
& WPA_KEY_MGMT_SAE
)
2111 return RSN_AUTH_KEY_MGMT_SAE
;
2112 if (akm
& WPA_KEY_MGMT_FT_SAE
)
2113 return RSN_AUTH_KEY_MGMT_FT_SAE
;
2114 if (akm
& WPA_KEY_MGMT_OWE
)
2115 return RSN_AUTH_KEY_MGMT_OWE
;
2116 if (akm
& WPA_KEY_MGMT_DPP
)
2117 return RSN_AUTH_KEY_MGMT_DPP
;
2122 int wpa_compare_rsn_ie(int ft_initial_assoc
,
2123 const u8
*ie1
, size_t ie1len
,
2124 const u8
*ie2
, size_t ie2len
)
2126 if (ie1
== NULL
|| ie2
== NULL
)
2129 if (ie1len
== ie2len
&& os_memcmp(ie1
, ie2
, ie1len
) == 0)
2130 return 0; /* identical IEs */
2132 #ifdef CONFIG_IEEE80211R
2133 if (ft_initial_assoc
) {
2134 struct wpa_ie_data ie1d
, ie2d
;
2136 * The PMKID-List in RSN IE is different between Beacon/Probe
2137 * Response/(Re)Association Request frames and EAPOL-Key
2138 * messages in FT initial mobility domain association. Allow
2139 * for this, but verify that other parts of the RSN IEs are
2142 if (wpa_parse_wpa_ie_rsn(ie1
, ie1len
, &ie1d
) < 0 ||
2143 wpa_parse_wpa_ie_rsn(ie2
, ie2len
, &ie2d
) < 0)
2145 if (ie1d
.proto
== ie2d
.proto
&&
2146 ie1d
.pairwise_cipher
== ie2d
.pairwise_cipher
&&
2147 ie1d
.group_cipher
== ie2d
.group_cipher
&&
2148 ie1d
.key_mgmt
== ie2d
.key_mgmt
&&
2149 ie1d
.capabilities
== ie2d
.capabilities
&&
2150 ie1d
.mgmt_group_cipher
== ie2d
.mgmt_group_cipher
)
2153 #endif /* CONFIG_IEEE80211R */
2159 int wpa_insert_pmkid(u8
*ies
, size_t *ies_len
, const u8
*pmkid
)
2161 u8
*start
, *end
, *rpos
, *rend
;
2165 end
= ies
+ *ies_len
;
2167 while (start
< end
) {
2168 if (*start
== WLAN_EID_RSN
)
2170 start
+= 2 + start
[1];
2173 wpa_printf(MSG_ERROR
, "RSN: Could not find RSNE in IEs data");
2176 wpa_hexdump(MSG_DEBUG
, "RSN: RSNE before modification",
2177 start
, 2 + start
[1]);
2179 /* Find start of PMKID-Count */
2181 rend
= rpos
+ start
[1];
2183 /* Skip Version and Group Data Cipher Suite */
2185 /* Skip Pairwise Cipher Suite Count and List */
2186 rpos
+= 2 + WPA_GET_LE16(rpos
) * RSN_SELECTOR_LEN
;
2187 /* Skip AKM Suite Count and List */
2188 rpos
+= 2 + WPA_GET_LE16(rpos
) * RSN_SELECTOR_LEN
;
2191 /* Add RSN Capabilities */
2192 os_memmove(rpos
+ 2, rpos
, end
- rpos
);
2199 /* Skip RSN Capabilities */
2202 wpa_printf(MSG_ERROR
,
2203 "RSN: Could not parse RSNE in IEs data");
2209 /* No PMKID-Count field included; add it */
2210 os_memmove(rpos
+ 2 + PMKID_LEN
, rpos
, end
+ added
- rpos
);
2211 WPA_PUT_LE16(rpos
, 1);
2213 os_memcpy(rpos
, pmkid
, PMKID_LEN
);
2214 added
+= 2 + PMKID_LEN
;
2215 start
[1] += 2 + PMKID_LEN
;
2219 if (rend
- rpos
< 2)
2221 num_pmkid
= WPA_GET_LE16(rpos
);
2222 /* PMKID-Count was included; use it */
2223 if (num_pmkid
!= 0) {
2226 if (num_pmkid
* PMKID_LEN
> rend
- rpos
- 2)
2229 * PMKID may have been included in RSN IE in
2230 * (Re)Association Request frame, so remove the old
2231 * PMKID(s) first before adding the new one.
2233 wpa_printf(MSG_DEBUG
,
2234 "RSN: Remove %u old PMKID(s) from RSNE",
2236 after
= rpos
+ 2 + num_pmkid
* PMKID_LEN
;
2237 os_memmove(rpos
+ 2, after
, end
- after
);
2238 start
[1] -= num_pmkid
* PMKID_LEN
;
2239 added
-= num_pmkid
* PMKID_LEN
;
2241 WPA_PUT_LE16(rpos
, 1);
2243 os_memmove(rpos
+ PMKID_LEN
, rpos
, end
+ added
- rpos
);
2244 os_memcpy(rpos
, pmkid
, PMKID_LEN
);
2246 start
[1] += PMKID_LEN
;
2249 wpa_hexdump(MSG_DEBUG
, "RSN: RSNE after modification (PMKID inserted)",
2250 start
, 2 + start
[1]);
2258 int wpa_cipher_key_len(int cipher
)
2261 case WPA_CIPHER_CCMP_256
:
2262 case WPA_CIPHER_GCMP_256
:
2263 case WPA_CIPHER_BIP_GMAC_256
:
2264 case WPA_CIPHER_BIP_CMAC_256
:
2266 case WPA_CIPHER_CCMP
:
2267 case WPA_CIPHER_GCMP
:
2268 case WPA_CIPHER_AES_128_CMAC
:
2269 case WPA_CIPHER_BIP_GMAC_128
:
2271 case WPA_CIPHER_TKIP
:
2279 int wpa_cipher_rsc_len(int cipher
)
2282 case WPA_CIPHER_CCMP_256
:
2283 case WPA_CIPHER_GCMP_256
:
2284 case WPA_CIPHER_CCMP
:
2285 case WPA_CIPHER_GCMP
:
2286 case WPA_CIPHER_TKIP
:
2294 enum wpa_alg
wpa_cipher_to_alg(int cipher
)
2297 case WPA_CIPHER_CCMP_256
:
2298 return WPA_ALG_CCMP_256
;
2299 case WPA_CIPHER_GCMP_256
:
2300 return WPA_ALG_GCMP_256
;
2301 case WPA_CIPHER_CCMP
:
2302 return WPA_ALG_CCMP
;
2303 case WPA_CIPHER_GCMP
:
2304 return WPA_ALG_GCMP
;
2305 case WPA_CIPHER_TKIP
:
2306 return WPA_ALG_TKIP
;
2307 case WPA_CIPHER_AES_128_CMAC
:
2308 return WPA_ALG_IGTK
;
2309 case WPA_CIPHER_BIP_GMAC_128
:
2310 return WPA_ALG_BIP_GMAC_128
;
2311 case WPA_CIPHER_BIP_GMAC_256
:
2312 return WPA_ALG_BIP_GMAC_256
;
2313 case WPA_CIPHER_BIP_CMAC_256
:
2314 return WPA_ALG_BIP_CMAC_256
;
2316 return WPA_ALG_NONE
;
2320 int wpa_cipher_valid_pairwise(int cipher
)
2322 return cipher
== WPA_CIPHER_CCMP_256
||
2323 cipher
== WPA_CIPHER_GCMP_256
||
2324 cipher
== WPA_CIPHER_CCMP
||
2325 cipher
== WPA_CIPHER_GCMP
||
2326 cipher
== WPA_CIPHER_TKIP
;
2330 u32
wpa_cipher_to_suite(int proto
, int cipher
)
2332 if (cipher
& WPA_CIPHER_CCMP_256
)
2333 return RSN_CIPHER_SUITE_CCMP_256
;
2334 if (cipher
& WPA_CIPHER_GCMP_256
)
2335 return RSN_CIPHER_SUITE_GCMP_256
;
2336 if (cipher
& WPA_CIPHER_CCMP
)
2337 return (proto
== WPA_PROTO_RSN
?
2338 RSN_CIPHER_SUITE_CCMP
: WPA_CIPHER_SUITE_CCMP
);
2339 if (cipher
& WPA_CIPHER_GCMP
)
2340 return RSN_CIPHER_SUITE_GCMP
;
2341 if (cipher
& WPA_CIPHER_TKIP
)
2342 return (proto
== WPA_PROTO_RSN
?
2343 RSN_CIPHER_SUITE_TKIP
: WPA_CIPHER_SUITE_TKIP
);
2344 if (cipher
& WPA_CIPHER_NONE
)
2345 return (proto
== WPA_PROTO_RSN
?
2346 RSN_CIPHER_SUITE_NONE
: WPA_CIPHER_SUITE_NONE
);
2347 if (cipher
& WPA_CIPHER_GTK_NOT_USED
)
2348 return RSN_CIPHER_SUITE_NO_GROUP_ADDRESSED
;
2349 if (cipher
& WPA_CIPHER_AES_128_CMAC
)
2350 return RSN_CIPHER_SUITE_AES_128_CMAC
;
2351 if (cipher
& WPA_CIPHER_BIP_GMAC_128
)
2352 return RSN_CIPHER_SUITE_BIP_GMAC_128
;
2353 if (cipher
& WPA_CIPHER_BIP_GMAC_256
)
2354 return RSN_CIPHER_SUITE_BIP_GMAC_256
;
2355 if (cipher
& WPA_CIPHER_BIP_CMAC_256
)
2356 return RSN_CIPHER_SUITE_BIP_CMAC_256
;
2361 int rsn_cipher_put_suites(u8
*start
, int ciphers
)
2365 if (ciphers
& WPA_CIPHER_CCMP_256
) {
2366 RSN_SELECTOR_PUT(pos
, RSN_CIPHER_SUITE_CCMP_256
);
2367 pos
+= RSN_SELECTOR_LEN
;
2369 if (ciphers
& WPA_CIPHER_GCMP_256
) {
2370 RSN_SELECTOR_PUT(pos
, RSN_CIPHER_SUITE_GCMP_256
);
2371 pos
+= RSN_SELECTOR_LEN
;
2373 if (ciphers
& WPA_CIPHER_CCMP
) {
2374 RSN_SELECTOR_PUT(pos
, RSN_CIPHER_SUITE_CCMP
);
2375 pos
+= RSN_SELECTOR_LEN
;
2377 if (ciphers
& WPA_CIPHER_GCMP
) {
2378 RSN_SELECTOR_PUT(pos
, RSN_CIPHER_SUITE_GCMP
);
2379 pos
+= RSN_SELECTOR_LEN
;
2381 if (ciphers
& WPA_CIPHER_TKIP
) {
2382 RSN_SELECTOR_PUT(pos
, RSN_CIPHER_SUITE_TKIP
);
2383 pos
+= RSN_SELECTOR_LEN
;
2385 if (ciphers
& WPA_CIPHER_NONE
) {
2386 RSN_SELECTOR_PUT(pos
, RSN_CIPHER_SUITE_NONE
);
2387 pos
+= RSN_SELECTOR_LEN
;
2390 return (pos
- start
) / RSN_SELECTOR_LEN
;
2394 int wpa_cipher_put_suites(u8
*start
, int ciphers
)
2398 if (ciphers
& WPA_CIPHER_CCMP
) {
2399 RSN_SELECTOR_PUT(pos
, WPA_CIPHER_SUITE_CCMP
);
2400 pos
+= WPA_SELECTOR_LEN
;
2402 if (ciphers
& WPA_CIPHER_TKIP
) {
2403 RSN_SELECTOR_PUT(pos
, WPA_CIPHER_SUITE_TKIP
);
2404 pos
+= WPA_SELECTOR_LEN
;
2406 if (ciphers
& WPA_CIPHER_NONE
) {
2407 RSN_SELECTOR_PUT(pos
, WPA_CIPHER_SUITE_NONE
);
2408 pos
+= WPA_SELECTOR_LEN
;
2411 return (pos
- start
) / RSN_SELECTOR_LEN
;
2415 int wpa_pick_pairwise_cipher(int ciphers
, int none_allowed
)
2417 if (ciphers
& WPA_CIPHER_CCMP_256
)
2418 return WPA_CIPHER_CCMP_256
;
2419 if (ciphers
& WPA_CIPHER_GCMP_256
)
2420 return WPA_CIPHER_GCMP_256
;
2421 if (ciphers
& WPA_CIPHER_CCMP
)
2422 return WPA_CIPHER_CCMP
;
2423 if (ciphers
& WPA_CIPHER_GCMP
)
2424 return WPA_CIPHER_GCMP
;
2425 if (ciphers
& WPA_CIPHER_TKIP
)
2426 return WPA_CIPHER_TKIP
;
2427 if (none_allowed
&& (ciphers
& WPA_CIPHER_NONE
))
2428 return WPA_CIPHER_NONE
;
2433 int wpa_pick_group_cipher(int ciphers
)
2435 if (ciphers
& WPA_CIPHER_CCMP_256
)
2436 return WPA_CIPHER_CCMP_256
;
2437 if (ciphers
& WPA_CIPHER_GCMP_256
)
2438 return WPA_CIPHER_GCMP_256
;
2439 if (ciphers
& WPA_CIPHER_CCMP
)
2440 return WPA_CIPHER_CCMP
;
2441 if (ciphers
& WPA_CIPHER_GCMP
)
2442 return WPA_CIPHER_GCMP
;
2443 if (ciphers
& WPA_CIPHER_GTK_NOT_USED
)
2444 return WPA_CIPHER_GTK_NOT_USED
;
2445 if (ciphers
& WPA_CIPHER_TKIP
)
2446 return WPA_CIPHER_TKIP
;
2451 int wpa_parse_cipher(const char *value
)
2454 char *start
, *end
, *buf
;
2456 buf
= os_strdup(value
);
2461 while (*start
!= '\0') {
2462 while (*start
== ' ' || *start
== '\t')
2467 while (*end
!= ' ' && *end
!= '\t' && *end
!= '\0')
2469 last
= *end
== '\0';
2471 if (os_strcmp(start
, "CCMP-256") == 0)
2472 val
|= WPA_CIPHER_CCMP_256
;
2473 else if (os_strcmp(start
, "GCMP-256") == 0)
2474 val
|= WPA_CIPHER_GCMP_256
;
2475 else if (os_strcmp(start
, "CCMP") == 0)
2476 val
|= WPA_CIPHER_CCMP
;
2477 else if (os_strcmp(start
, "GCMP") == 0)
2478 val
|= WPA_CIPHER_GCMP
;
2479 else if (os_strcmp(start
, "TKIP") == 0)
2480 val
|= WPA_CIPHER_TKIP
;
2482 else if (os_strcmp(start
, "WEP104") == 0)
2483 val
|= WPA_CIPHER_WEP104
;
2484 else if (os_strcmp(start
, "WEP40") == 0)
2485 val
|= WPA_CIPHER_WEP40
;
2486 #endif /* CONFIG_WEP */
2487 else if (os_strcmp(start
, "NONE") == 0)
2488 val
|= WPA_CIPHER_NONE
;
2489 else if (os_strcmp(start
, "GTK_NOT_USED") == 0)
2490 val
|= WPA_CIPHER_GTK_NOT_USED
;
2491 else if (os_strcmp(start
, "AES-128-CMAC") == 0)
2492 val
|= WPA_CIPHER_AES_128_CMAC
;
2493 else if (os_strcmp(start
, "BIP-GMAC-128") == 0)
2494 val
|= WPA_CIPHER_BIP_GMAC_128
;
2495 else if (os_strcmp(start
, "BIP-GMAC-256") == 0)
2496 val
|= WPA_CIPHER_BIP_GMAC_256
;
2497 else if (os_strcmp(start
, "BIP-CMAC-256") == 0)
2498 val
|= WPA_CIPHER_BIP_CMAC_256
;
2514 int wpa_write_ciphers(char *start
, char *end
, int ciphers
, const char *delim
)
2519 if (ciphers
& WPA_CIPHER_CCMP_256
) {
2520 ret
= os_snprintf(pos
, end
- pos
, "%sCCMP-256",
2521 pos
== start
? "" : delim
);
2522 if (os_snprintf_error(end
- pos
, ret
))
2526 if (ciphers
& WPA_CIPHER_GCMP_256
) {
2527 ret
= os_snprintf(pos
, end
- pos
, "%sGCMP-256",
2528 pos
== start
? "" : delim
);
2529 if (os_snprintf_error(end
- pos
, ret
))
2533 if (ciphers
& WPA_CIPHER_CCMP
) {
2534 ret
= os_snprintf(pos
, end
- pos
, "%sCCMP",
2535 pos
== start
? "" : delim
);
2536 if (os_snprintf_error(end
- pos
, ret
))
2540 if (ciphers
& WPA_CIPHER_GCMP
) {
2541 ret
= os_snprintf(pos
, end
- pos
, "%sGCMP",
2542 pos
== start
? "" : delim
);
2543 if (os_snprintf_error(end
- pos
, ret
))
2547 if (ciphers
& WPA_CIPHER_TKIP
) {
2548 ret
= os_snprintf(pos
, end
- pos
, "%sTKIP",
2549 pos
== start
? "" : delim
);
2550 if (os_snprintf_error(end
- pos
, ret
))
2554 if (ciphers
& WPA_CIPHER_AES_128_CMAC
) {
2555 ret
= os_snprintf(pos
, end
- pos
, "%sAES-128-CMAC",
2556 pos
== start
? "" : delim
);
2557 if (os_snprintf_error(end
- pos
, ret
))
2561 if (ciphers
& WPA_CIPHER_BIP_GMAC_128
) {
2562 ret
= os_snprintf(pos
, end
- pos
, "%sBIP-GMAC-128",
2563 pos
== start
? "" : delim
);
2564 if (os_snprintf_error(end
- pos
, ret
))
2568 if (ciphers
& WPA_CIPHER_BIP_GMAC_256
) {
2569 ret
= os_snprintf(pos
, end
- pos
, "%sBIP-GMAC-256",
2570 pos
== start
? "" : delim
);
2571 if (os_snprintf_error(end
- pos
, ret
))
2575 if (ciphers
& WPA_CIPHER_BIP_CMAC_256
) {
2576 ret
= os_snprintf(pos
, end
- pos
, "%sBIP-CMAC-256",
2577 pos
== start
? "" : delim
);
2578 if (os_snprintf_error(end
- pos
, ret
))
2582 if (ciphers
& WPA_CIPHER_NONE
) {
2583 ret
= os_snprintf(pos
, end
- pos
, "%sNONE",
2584 pos
== start
? "" : delim
);
2585 if (os_snprintf_error(end
- pos
, ret
))
2594 int wpa_select_ap_group_cipher(int wpa
, int wpa_pairwise
, int rsn_pairwise
)
2598 /* Select group cipher based on the enabled pairwise cipher suites */
2600 pairwise
|= wpa_pairwise
;
2602 pairwise
|= rsn_pairwise
;
2604 if (pairwise
& WPA_CIPHER_TKIP
)
2605 return WPA_CIPHER_TKIP
;
2606 if ((pairwise
& (WPA_CIPHER_CCMP
| WPA_CIPHER_GCMP
)) == WPA_CIPHER_GCMP
)
2607 return WPA_CIPHER_GCMP
;
2608 if ((pairwise
& (WPA_CIPHER_GCMP_256
| WPA_CIPHER_CCMP
|
2609 WPA_CIPHER_GCMP
)) == WPA_CIPHER_GCMP_256
)
2610 return WPA_CIPHER_GCMP_256
;
2611 if ((pairwise
& (WPA_CIPHER_CCMP_256
| WPA_CIPHER_CCMP
|
2612 WPA_CIPHER_GCMP
)) == WPA_CIPHER_CCMP_256
)
2613 return WPA_CIPHER_CCMP_256
;
2614 return WPA_CIPHER_CCMP
;
2619 int fils_domain_name_hash(const char *domain
, u8
*hash
)
2621 char buf
[255], *wpos
= buf
;
2622 const char *pos
= domain
;
2625 u8 mac
[SHA256_MAC_LEN
];
2627 for (len
= 0; len
< sizeof(buf
) && *pos
; len
++) {
2628 if (isalpha(*pos
) && isupper(*pos
))
2629 *wpos
++ = tolower(*pos
);
2635 addr
[0] = (const u8
*) buf
;
2636 if (sha256_vector(1, addr
, &len
, mac
) < 0)
2638 os_memcpy(hash
, mac
, 2);
2641 #endif /* CONFIG_FILS */
2645 * wpa_parse_vendor_specific - Parse Vendor Specific IEs
2646 * @pos: Pointer to the IE header
2647 * @end: Pointer to the end of the Key Data buffer
2648 * @ie: Pointer to parsed IE data
2649 * Returns: 0 on success, 1 if end mark is found, -1 on failure
2651 static int wpa_parse_vendor_specific(const u8
*pos
, const u8
*end
,
2652 struct wpa_eapol_ie_parse
*ie
)
2657 wpa_printf(MSG_MSGDUMP
,
2658 "Too short vendor specific IE ignored (len=%u)",
2663 oui
= WPA_GET_BE24(&pos
[2]);
2664 if (oui
== OUI_MICROSOFT
&& pos
[5] == WMM_OUI_TYPE
&& pos
[1] > 4) {
2665 if (pos
[6] == WMM_OUI_SUBTYPE_INFORMATION_ELEMENT
) {
2667 ie
->wmm_len
= pos
[1];
2668 wpa_hexdump(MSG_DEBUG
, "WPA: WMM IE",
2669 ie
->wmm
, ie
->wmm_len
);
2670 } else if (pos
[6] == WMM_OUI_SUBTYPE_PARAMETER_ELEMENT
) {
2672 ie
->wmm_len
= pos
[1];
2673 wpa_hexdump(MSG_DEBUG
, "WPA: WMM Parameter Element",
2674 ie
->wmm
, ie
->wmm_len
);
2682 * wpa_parse_generic - Parse EAPOL-Key Key Data Generic IEs
2683 * @pos: Pointer to the IE header
2684 * @ie: Pointer to parsed IE data
2685 * Returns: 0 on success, 1 if end mark is found, -1 on failure
2687 static int wpa_parse_generic(const u8
*pos
, struct wpa_eapol_ie_parse
*ie
)
2693 RSN_SELECTOR_GET(pos
+ 2) == WPA_OUI_TYPE
&&
2694 pos
[2 + WPA_SELECTOR_LEN
] == 1 &&
2695 pos
[2 + WPA_SELECTOR_LEN
+ 1] == 0) {
2697 ie
->wpa_ie_len
= pos
[1] + 2;
2698 wpa_hexdump(MSG_DEBUG
, "WPA: WPA IE in EAPOL-Key",
2699 ie
->wpa_ie
, ie
->wpa_ie_len
);
2703 if (pos
[1] >= 4 && WPA_GET_BE32(pos
+ 2) == OSEN_IE_VENDOR_TYPE
) {
2705 ie
->osen_len
= pos
[1] + 2;
2709 if (pos
[1] >= RSN_SELECTOR_LEN
+ PMKID_LEN
&&
2710 RSN_SELECTOR_GET(pos
+ 2) == RSN_KEY_DATA_PMKID
) {
2711 ie
->pmkid
= pos
+ 2 + RSN_SELECTOR_LEN
;
2712 wpa_hexdump(MSG_DEBUG
, "WPA: PMKID in EAPOL-Key",
2717 if (pos
[1] >= RSN_SELECTOR_LEN
+ 2 &&
2718 RSN_SELECTOR_GET(pos
+ 2) == RSN_KEY_DATA_KEYID
) {
2719 ie
->key_id
= pos
+ 2 + RSN_SELECTOR_LEN
;
2720 wpa_hexdump(MSG_DEBUG
, "WPA: KeyID in EAPOL-Key",
2725 if (pos
[1] > RSN_SELECTOR_LEN
+ 2 &&
2726 RSN_SELECTOR_GET(pos
+ 2) == RSN_KEY_DATA_GROUPKEY
) {
2727 ie
->gtk
= pos
+ 2 + RSN_SELECTOR_LEN
;
2728 ie
->gtk_len
= pos
[1] - RSN_SELECTOR_LEN
;
2729 wpa_hexdump_key(MSG_DEBUG
, "WPA: GTK in EAPOL-Key",
2734 if (pos
[1] > RSN_SELECTOR_LEN
+ 2 &&
2735 RSN_SELECTOR_GET(pos
+ 2) == RSN_KEY_DATA_MAC_ADDR
) {
2736 ie
->mac_addr
= pos
+ 2 + RSN_SELECTOR_LEN
;
2737 ie
->mac_addr_len
= pos
[1] - RSN_SELECTOR_LEN
;
2738 wpa_hexdump(MSG_DEBUG
, "WPA: MAC Address in EAPOL-Key",
2743 if (pos
[1] > RSN_SELECTOR_LEN
+ 2 &&
2744 RSN_SELECTOR_GET(pos
+ 2) == RSN_KEY_DATA_IGTK
) {
2745 ie
->igtk
= pos
+ 2 + RSN_SELECTOR_LEN
;
2746 ie
->igtk_len
= pos
[1] - RSN_SELECTOR_LEN
;
2747 wpa_hexdump_key(MSG_DEBUG
, "WPA: IGTK in EAPOL-Key",
2752 if (pos
[1] > RSN_SELECTOR_LEN
+ 2 &&
2753 RSN_SELECTOR_GET(pos
+ 2) == RSN_KEY_DATA_BIGTK
) {
2754 ie
->bigtk
= pos
+ 2 + RSN_SELECTOR_LEN
;
2755 ie
->bigtk_len
= pos
[1] - RSN_SELECTOR_LEN
;
2756 wpa_hexdump_key(MSG_DEBUG
, "WPA: BIGTK in EAPOL-Key",
2761 if (pos
[1] >= RSN_SELECTOR_LEN
+ 1 &&
2762 RSN_SELECTOR_GET(pos
+ 2) == WFA_KEY_DATA_IP_ADDR_REQ
) {
2763 ie
->ip_addr_req
= pos
+ 2 + RSN_SELECTOR_LEN
;
2764 wpa_hexdump(MSG_DEBUG
, "WPA: IP Address Request in EAPOL-Key",
2765 ie
->ip_addr_req
, pos
[1] - RSN_SELECTOR_LEN
);
2769 if (pos
[1] >= RSN_SELECTOR_LEN
+ 3 * 4 &&
2770 RSN_SELECTOR_GET(pos
+ 2) == WFA_KEY_DATA_IP_ADDR_ALLOC
) {
2771 ie
->ip_addr_alloc
= pos
+ 2 + RSN_SELECTOR_LEN
;
2772 wpa_hexdump(MSG_DEBUG
,
2773 "WPA: IP Address Allocation in EAPOL-Key",
2774 ie
->ip_addr_alloc
, pos
[1] - RSN_SELECTOR_LEN
);
2778 if (pos
[1] > RSN_SELECTOR_LEN
+ 2 &&
2779 RSN_SELECTOR_GET(pos
+ 2) == RSN_KEY_DATA_OCI
) {
2780 ie
->oci
= pos
+ 2 + RSN_SELECTOR_LEN
;
2781 ie
->oci_len
= pos
[1] - RSN_SELECTOR_LEN
;
2782 wpa_hexdump(MSG_DEBUG
, "WPA: OCI KDE in EAPOL-Key",
2792 * wpa_parse_kde_ies - Parse EAPOL-Key Key Data IEs
2793 * @buf: Pointer to the Key Data buffer
2794 * @len: Key Data Length
2795 * @ie: Pointer to parsed IE data
2796 * Returns: 0 on success, -1 on failure
2798 int wpa_parse_kde_ies(const u8
*buf
, size_t len
, struct wpa_eapol_ie_parse
*ie
)
2800 const u8
*pos
, *end
;
2803 os_memset(ie
, 0, sizeof(*ie
));
2804 for (pos
= buf
, end
= pos
+ len
; end
- pos
> 1; pos
+= 2 + pos
[1]) {
2805 if (pos
[0] == 0xdd &&
2806 ((pos
== buf
+ len
- 1) || pos
[1] == 0)) {
2807 /* Ignore padding */
2810 if (2 + pos
[1] > end
- pos
) {
2811 wpa_printf(MSG_DEBUG
,
2812 "WPA: EAPOL-Key Key Data underflow (ie=%d len=%d pos=%d)",
2813 pos
[0], pos
[1], (int) (pos
- buf
));
2814 wpa_hexdump_key(MSG_DEBUG
, "WPA: Key Data", buf
, len
);
2818 if (*pos
== WLAN_EID_RSN
) {
2820 ie
->rsn_ie_len
= pos
[1] + 2;
2821 wpa_hexdump(MSG_DEBUG
, "WPA: RSN IE in EAPOL-Key",
2822 ie
->rsn_ie
, ie
->rsn_ie_len
);
2823 } else if (*pos
== WLAN_EID_RSNX
) {
2825 ie
->rsnxe_len
= pos
[1] + 2;
2826 wpa_hexdump(MSG_DEBUG
, "WPA: RSNXE in EAPOL-Key",
2827 ie
->rsnxe
, ie
->rsnxe_len
);
2828 } else if (*pos
== WLAN_EID_MOBILITY_DOMAIN
) {
2830 ie
->mdie_len
= pos
[1] + 2;
2831 wpa_hexdump(MSG_DEBUG
, "WPA: MDIE in EAPOL-Key",
2832 ie
->mdie
, ie
->mdie_len
);
2833 } else if (*pos
== WLAN_EID_FAST_BSS_TRANSITION
) {
2835 ie
->ftie_len
= pos
[1] + 2;
2836 wpa_hexdump(MSG_DEBUG
, "WPA: FTIE in EAPOL-Key",
2837 ie
->ftie
, ie
->ftie_len
);
2838 } else if (*pos
== WLAN_EID_TIMEOUT_INTERVAL
&& pos
[1] >= 5) {
2839 if (pos
[2] == WLAN_TIMEOUT_REASSOC_DEADLINE
) {
2840 ie
->reassoc_deadline
= pos
;
2841 wpa_hexdump(MSG_DEBUG
, "WPA: Reassoc Deadline "
2843 ie
->reassoc_deadline
, pos
[1] + 2);
2844 } else if (pos
[2] == WLAN_TIMEOUT_KEY_LIFETIME
) {
2845 ie
->key_lifetime
= pos
;
2846 wpa_hexdump(MSG_DEBUG
, "WPA: KeyLifetime "
2848 ie
->key_lifetime
, pos
[1] + 2);
2850 wpa_hexdump(MSG_DEBUG
, "WPA: Unrecognized "
2851 "EAPOL-Key Key Data IE",
2854 } else if (*pos
== WLAN_EID_LINK_ID
) {
2857 ie
->lnkid_len
= pos
[1] + 2;
2859 } else if (*pos
== WLAN_EID_EXT_CAPAB
) {
2860 ie
->ext_capab
= pos
;
2861 ie
->ext_capab_len
= pos
[1] + 2;
2862 } else if (*pos
== WLAN_EID_SUPP_RATES
) {
2863 ie
->supp_rates
= pos
;
2864 ie
->supp_rates_len
= pos
[1] + 2;
2865 } else if (*pos
== WLAN_EID_EXT_SUPP_RATES
) {
2866 ie
->ext_supp_rates
= pos
;
2867 ie
->ext_supp_rates_len
= pos
[1] + 2;
2868 } else if (*pos
== WLAN_EID_HT_CAP
&&
2869 pos
[1] >= sizeof(struct ieee80211_ht_capabilities
)) {
2870 ie
->ht_capabilities
= pos
+ 2;
2871 } else if (*pos
== WLAN_EID_VHT_AID
) {
2873 ie
->aid
= WPA_GET_LE16(pos
+ 2) & 0x3fff;
2874 } else if (*pos
== WLAN_EID_VHT_CAP
&&
2875 pos
[1] >= sizeof(struct ieee80211_vht_capabilities
))
2877 ie
->vht_capabilities
= pos
+ 2;
2878 } else if (*pos
== WLAN_EID_QOS
&& pos
[1] >= 1) {
2879 ie
->qosinfo
= pos
[2];
2880 } else if (*pos
== WLAN_EID_SUPPORTED_CHANNELS
) {
2881 ie
->supp_channels
= pos
+ 2;
2882 ie
->supp_channels_len
= pos
[1];
2883 } else if (*pos
== WLAN_EID_SUPPORTED_OPERATING_CLASSES
) {
2885 * The value of the Length field of the Supported
2886 * Operating Classes element is between 2 and 253.
2887 * Silently skip invalid elements to avoid interop
2888 * issues when trying to use the value.
2890 if (pos
[1] >= 2 && pos
[1] <= 253) {
2891 ie
->supp_oper_classes
= pos
+ 2;
2892 ie
->supp_oper_classes_len
= pos
[1];
2894 } else if (*pos
== WLAN_EID_VENDOR_SPECIFIC
) {
2895 ret
= wpa_parse_generic(pos
, ie
);
2903 ret
= wpa_parse_vendor_specific(pos
, end
, ie
);
2911 wpa_hexdump(MSG_DEBUG
,
2912 "WPA: Unrecognized EAPOL-Key Key Data IE",