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 #if defined(CONFIG_IEEE80211R) || defined(CONFIG_IEEE80211W)
216 case WPA_KEY_INFO_TYPE_AES_128_CMAC
:
217 wpa_printf(MSG_DEBUG
, "WPA: EAPOL-Key MIC using AES-CMAC");
218 return omac1_aes_128(key
, buf
, len
, mic
);
219 #endif /* CONFIG_IEEE80211R || CONFIG_IEEE80211W */
220 case WPA_KEY_INFO_TYPE_AKM_DEFINED
:
223 case WPA_KEY_MGMT_SAE
:
224 case WPA_KEY_MGMT_FT_SAE
:
225 wpa_printf(MSG_DEBUG
,
226 "WPA: EAPOL-Key MIC using AES-CMAC (AKM-defined - SAE)");
227 return omac1_aes_128(key
, buf
, len
, mic
);
228 #endif /* CONFIG_SAE */
230 case WPA_KEY_MGMT_OSEN
:
231 wpa_printf(MSG_DEBUG
,
232 "WPA: EAPOL-Key MIC using AES-CMAC (AKM-defined - OSEN)");
233 return omac1_aes_128(key
, buf
, len
, mic
);
234 #endif /* CONFIG_HS20 */
236 case WPA_KEY_MGMT_IEEE8021X_SUITE_B
:
237 wpa_printf(MSG_DEBUG
,
238 "WPA: EAPOL-Key MIC using HMAC-SHA256 (AKM-defined - Suite B)");
239 if (hmac_sha256(key
, key_len
, buf
, len
, hash
))
241 os_memcpy(mic
, hash
, MD5_MAC_LEN
);
243 #endif /* CONFIG_SUITEB */
244 #ifdef CONFIG_SUITEB192
245 case WPA_KEY_MGMT_IEEE8021X_SUITE_B_192
:
246 wpa_printf(MSG_DEBUG
,
247 "WPA: EAPOL-Key MIC using HMAC-SHA384 (AKM-defined - Suite B 192-bit)");
248 if (hmac_sha384(key
, key_len
, buf
, len
, hash
))
250 os_memcpy(mic
, hash
, 24);
252 #endif /* CONFIG_SUITEB192 */
254 case WPA_KEY_MGMT_OWE
:
255 wpa_printf(MSG_DEBUG
,
256 "WPA: EAPOL-Key MIC using HMAC-SHA%u (AKM-defined - OWE)",
257 (unsigned int) key_len
* 8 * 2);
258 if (key_len
== 128 / 8) {
259 if (hmac_sha256(key
, key_len
, buf
, len
, hash
))
261 } else if (key_len
== 192 / 8) {
262 if (hmac_sha384(key
, key_len
, buf
, len
, hash
))
264 } else if (key_len
== 256 / 8) {
265 if (hmac_sha512(key
, key_len
, buf
, len
, hash
))
269 "OWE: Unsupported KCK length: %u",
270 (unsigned int) key_len
);
273 os_memcpy(mic
, hash
, key_len
);
275 #endif /* CONFIG_OWE */
277 case WPA_KEY_MGMT_DPP
:
278 wpa_printf(MSG_DEBUG
,
279 "WPA: EAPOL-Key MIC using HMAC-SHA%u (AKM-defined - DPP)",
280 (unsigned int) key_len
* 8 * 2);
281 if (key_len
== 128 / 8) {
282 if (hmac_sha256(key
, key_len
, buf
, len
, hash
))
284 } else if (key_len
== 192 / 8) {
285 if (hmac_sha384(key
, key_len
, buf
, len
, hash
))
287 } else if (key_len
== 256 / 8) {
288 if (hmac_sha512(key
, key_len
, buf
, len
, hash
))
292 "DPP: Unsupported KCK length: %u",
293 (unsigned int) key_len
);
296 os_memcpy(mic
, hash
, key_len
);
298 #endif /* CONFIG_DPP */
299 #if defined(CONFIG_IEEE80211R) && defined(CONFIG_SHA384)
300 case WPA_KEY_MGMT_FT_IEEE8021X_SHA384
:
301 wpa_printf(MSG_DEBUG
,
302 "WPA: EAPOL-Key MIC using HMAC-SHA384 (AKM-defined - FT 802.1X SHA384)");
303 if (hmac_sha384(key
, key_len
, buf
, len
, hash
))
305 os_memcpy(mic
, hash
, 24);
307 #endif /* CONFIG_IEEE80211R && CONFIG_SHA384 */
309 wpa_printf(MSG_DEBUG
,
310 "WPA: EAPOL-Key MIC algorithm not known (AKM-defined - akmp=0x%x)",
316 wpa_printf(MSG_DEBUG
,
317 "WPA: EAPOL-Key MIC algorithm not known (ver=%d)",
327 * wpa_pmk_to_ptk - Calculate PTK from PMK, addresses, and nonces
328 * @pmk: Pairwise master key
329 * @pmk_len: Length of PMK
330 * @label: Label to use in derivation
333 * @nonce1: ANonce or SNonce
334 * @nonce2: SNonce or ANonce
335 * @ptk: Buffer for pairwise transient key
336 * @akmp: Negotiated AKM
337 * @cipher: Negotiated pairwise cipher
338 * Returns: 0 on success, -1 on failure
340 * IEEE Std 802.11i-2004 - 8.5.1.2 Pairwise key hierarchy
341 * PTK = PRF-X(PMK, "Pairwise key expansion",
342 * Min(AA, SA) || Max(AA, SA) ||
343 * Min(ANonce, SNonce) || Max(ANonce, SNonce)
346 * The optional Z.x component is used only with DPP and that part is not defined
349 int wpa_pmk_to_ptk(const u8
*pmk
, size_t pmk_len
, const char *label
,
350 const u8
*addr1
, const u8
*addr2
,
351 const u8
*nonce1
, const u8
*nonce2
,
352 struct wpa_ptk
*ptk
, int akmp
, int cipher
,
353 const u8
*z
, size_t z_len
)
355 #define MAX_Z_LEN 66 /* with NIST P-521 */
356 u8 data
[2 * ETH_ALEN
+ 2 * WPA_NONCE_LEN
+ MAX_Z_LEN
];
357 size_t data_len
= 2 * ETH_ALEN
+ 2 * WPA_NONCE_LEN
;
358 u8 tmp
[WPA_KCK_MAX_LEN
+ WPA_KEK_MAX_LEN
+ WPA_TK_MAX_LEN
];
362 wpa_printf(MSG_ERROR
, "WPA: No PMK set for PTK derivation");
366 if (z_len
> MAX_Z_LEN
)
369 if (os_memcmp(addr1
, addr2
, ETH_ALEN
) < 0) {
370 os_memcpy(data
, addr1
, ETH_ALEN
);
371 os_memcpy(data
+ ETH_ALEN
, addr2
, ETH_ALEN
);
373 os_memcpy(data
, addr2
, ETH_ALEN
);
374 os_memcpy(data
+ ETH_ALEN
, addr1
, ETH_ALEN
);
377 if (os_memcmp(nonce1
, nonce2
, WPA_NONCE_LEN
) < 0) {
378 os_memcpy(data
+ 2 * ETH_ALEN
, nonce1
, WPA_NONCE_LEN
);
379 os_memcpy(data
+ 2 * ETH_ALEN
+ WPA_NONCE_LEN
, nonce2
,
382 os_memcpy(data
+ 2 * ETH_ALEN
, nonce2
, WPA_NONCE_LEN
);
383 os_memcpy(data
+ 2 * ETH_ALEN
+ WPA_NONCE_LEN
, nonce1
,
388 os_memcpy(data
+ 2 * ETH_ALEN
+ 2 * WPA_NONCE_LEN
, z
, z_len
);
392 ptk
->kck_len
= wpa_kck_len(akmp
, pmk_len
);
393 ptk
->kek_len
= wpa_kek_len(akmp
, pmk_len
);
394 ptk
->tk_len
= wpa_cipher_key_len(cipher
);
395 if (ptk
->tk_len
== 0) {
396 wpa_printf(MSG_ERROR
,
397 "WPA: Unsupported cipher (0x%x) used in PTK derivation",
401 ptk_len
= ptk
->kck_len
+ ptk
->kek_len
+ ptk
->tk_len
;
403 if (wpa_key_mgmt_sha384(akmp
)) {
404 #if defined(CONFIG_SUITEB192) || defined(CONFIG_FILS)
405 wpa_printf(MSG_DEBUG
, "WPA: PTK derivation using PRF(SHA384)");
406 if (sha384_prf(pmk
, pmk_len
, label
, data
, data_len
,
409 #else /* CONFIG_SUITEB192 || CONFIG_FILS */
411 #endif /* CONFIG_SUITEB192 || CONFIG_FILS */
412 } else if (wpa_key_mgmt_sha256(akmp
) || akmp
== WPA_KEY_MGMT_OWE
) {
413 #if defined(CONFIG_IEEE80211W) || defined(CONFIG_SAE) || defined(CONFIG_FILS)
414 wpa_printf(MSG_DEBUG
, "WPA: PTK derivation using PRF(SHA256)");
415 if (sha256_prf(pmk
, pmk_len
, label
, data
, data_len
,
418 #else /* CONFIG_IEEE80211W or CONFIG_SAE or CONFIG_FILS */
420 #endif /* CONFIG_IEEE80211W or CONFIG_SAE or CONFIG_FILS */
422 } else if (akmp
== WPA_KEY_MGMT_DPP
&& pmk_len
== 32) {
423 wpa_printf(MSG_DEBUG
, "WPA: PTK derivation using PRF(SHA256)");
424 if (sha256_prf(pmk
, pmk_len
, label
, data
, data_len
,
427 } else if (akmp
== WPA_KEY_MGMT_DPP
&& pmk_len
== 48) {
428 wpa_printf(MSG_DEBUG
, "WPA: PTK derivation using PRF(SHA384)");
429 if (sha384_prf(pmk
, pmk_len
, label
, data
, data_len
,
432 } else if (akmp
== WPA_KEY_MGMT_DPP
&& pmk_len
== 64) {
433 wpa_printf(MSG_DEBUG
, "WPA: PTK derivation using PRF(SHA512)");
434 if (sha512_prf(pmk
, pmk_len
, label
, data
, data_len
,
437 } else if (akmp
== WPA_KEY_MGMT_DPP
) {
438 wpa_printf(MSG_INFO
, "DPP: Unknown PMK length %u",
439 (unsigned int) pmk_len
);
441 #endif /* CONFIG_DPP */
443 wpa_printf(MSG_DEBUG
, "WPA: PTK derivation using PRF(SHA1)");
444 if (sha1_prf(pmk
, pmk_len
, label
, data
, data_len
, tmp
,
449 wpa_printf(MSG_DEBUG
, "WPA: PTK derivation - A1=" MACSTR
" A2=" MACSTR
,
450 MAC2STR(addr1
), MAC2STR(addr2
));
451 wpa_hexdump(MSG_DEBUG
, "WPA: Nonce1", nonce1
, WPA_NONCE_LEN
);
452 wpa_hexdump(MSG_DEBUG
, "WPA: Nonce2", nonce2
, WPA_NONCE_LEN
);
454 wpa_hexdump_key(MSG_DEBUG
, "WPA: Z.x", z
, z_len
);
455 wpa_hexdump_key(MSG_DEBUG
, "WPA: PMK", pmk
, pmk_len
);
456 wpa_hexdump_key(MSG_DEBUG
, "WPA: PTK", tmp
, ptk_len
);
458 os_memcpy(ptk
->kck
, tmp
, ptk
->kck_len
);
459 wpa_hexdump_key(MSG_DEBUG
, "WPA: KCK", ptk
->kck
, ptk
->kck_len
);
461 os_memcpy(ptk
->kek
, tmp
+ ptk
->kck_len
, ptk
->kek_len
);
462 wpa_hexdump_key(MSG_DEBUG
, "WPA: KEK", ptk
->kek
, ptk
->kek_len
);
464 os_memcpy(ptk
->tk
, tmp
+ ptk
->kck_len
+ ptk
->kek_len
, ptk
->tk_len
);
465 wpa_hexdump_key(MSG_DEBUG
, "WPA: TK", ptk
->tk
, ptk
->tk_len
);
470 os_memset(tmp
, 0, sizeof(tmp
));
471 os_memset(data
, 0, data_len
);
477 int fils_rmsk_to_pmk(int akmp
, const u8
*rmsk
, size_t rmsk_len
,
478 const u8
*snonce
, const u8
*anonce
, const u8
*dh_ss
,
479 size_t dh_ss_len
, u8
*pmk
, size_t *pmk_len
)
481 u8 nonces
[2 * FILS_NONCE_LEN
];
487 /* PMK = HMAC-Hash(SNonce || ANonce, rMSK [ || DHss ]) */
488 wpa_printf(MSG_DEBUG
, "FILS: rMSK to PMK derivation");
490 if (wpa_key_mgmt_sha384(akmp
))
491 *pmk_len
= SHA384_MAC_LEN
;
492 else if (wpa_key_mgmt_sha256(akmp
))
493 *pmk_len
= SHA256_MAC_LEN
;
497 wpa_hexdump_key(MSG_DEBUG
, "FILS: rMSK", rmsk
, rmsk_len
);
498 wpa_hexdump(MSG_DEBUG
, "FILS: SNonce", snonce
, FILS_NONCE_LEN
);
499 wpa_hexdump(MSG_DEBUG
, "FILS: ANonce", anonce
, FILS_NONCE_LEN
);
500 wpa_hexdump(MSG_DEBUG
, "FILS: DHss", dh_ss
, dh_ss_len
);
502 os_memcpy(nonces
, snonce
, FILS_NONCE_LEN
);
503 os_memcpy(&nonces
[FILS_NONCE_LEN
], anonce
, FILS_NONCE_LEN
);
512 if (wpa_key_mgmt_sha384(akmp
))
513 res
= hmac_sha384_vector(nonces
, 2 * FILS_NONCE_LEN
, num_elem
,
516 res
= hmac_sha256_vector(nonces
, 2 * FILS_NONCE_LEN
, num_elem
,
519 wpa_hexdump_key(MSG_DEBUG
, "FILS: PMK", pmk
, *pmk_len
);
526 int fils_pmkid_erp(int akmp
, const u8
*reauth
, size_t reauth_len
,
531 u8 hash
[SHA384_MAC_LEN
];
534 /* PMKID = Truncate-128(Hash(EAP-Initiate/Reauth)) */
537 if (wpa_key_mgmt_sha384(akmp
))
538 res
= sha384_vector(1, addr
, len
, hash
);
539 else if (wpa_key_mgmt_sha256(akmp
))
540 res
= sha256_vector(1, addr
, len
, hash
);
545 os_memcpy(pmkid
, hash
, PMKID_LEN
);
546 wpa_hexdump(MSG_DEBUG
, "FILS: PMKID", pmkid
, PMKID_LEN
);
551 int fils_pmk_to_ptk(const u8
*pmk
, size_t pmk_len
, const u8
*spa
, const u8
*aa
,
552 const u8
*snonce
, const u8
*anonce
, const u8
*dhss
,
553 size_t dhss_len
, struct wpa_ptk
*ptk
,
554 u8
*ick
, size_t *ick_len
, int akmp
, int cipher
,
555 u8
*fils_ft
, size_t *fils_ft_len
)
559 u8 tmp
[FILS_ICK_MAX_LEN
+ WPA_KEK_MAX_LEN
+ WPA_TK_MAX_LEN
+
562 const char *label
= "FILS PTK Derivation";
566 * FILS-Key-Data = PRF-X(PMK, "FILS PTK Derivation",
567 * SPA || AA || SNonce || ANonce [ || DHss ])
568 * ICK = L(FILS-Key-Data, 0, ICK_bits)
569 * KEK = L(FILS-Key-Data, ICK_bits, KEK_bits)
570 * TK = L(FILS-Key-Data, ICK_bits + KEK_bits, TK_bits)
571 * If doing FT initial mobility domain association:
572 * FILS-FT = L(FILS-Key-Data, ICK_bits + KEK_bits + TK_bits,
575 data_len
= 2 * ETH_ALEN
+ 2 * FILS_NONCE_LEN
+ dhss_len
;
576 data
= os_malloc(data_len
);
580 os_memcpy(pos
, spa
, ETH_ALEN
);
582 os_memcpy(pos
, aa
, ETH_ALEN
);
584 os_memcpy(pos
, snonce
, FILS_NONCE_LEN
);
585 pos
+= FILS_NONCE_LEN
;
586 os_memcpy(pos
, anonce
, FILS_NONCE_LEN
);
587 pos
+= FILS_NONCE_LEN
;
589 os_memcpy(pos
, dhss
, dhss_len
);
592 ptk
->kek_len
= wpa_kek_len(akmp
, pmk_len
);
593 ptk
->tk_len
= wpa_cipher_key_len(cipher
);
594 if (wpa_key_mgmt_sha384(akmp
))
596 else if (wpa_key_mgmt_sha256(akmp
))
600 key_data_len
= *ick_len
+ ptk
->kek_len
+ ptk
->tk_len
;
602 if (fils_ft
&& fils_ft_len
) {
603 if (akmp
== WPA_KEY_MGMT_FT_FILS_SHA256
) {
605 } else if (akmp
== WPA_KEY_MGMT_FT_FILS_SHA384
) {
611 key_data_len
+= *fils_ft_len
;
614 if (wpa_key_mgmt_sha384(akmp
)) {
615 wpa_printf(MSG_DEBUG
, "FILS: PTK derivation using PRF(SHA384)");
616 if (sha384_prf(pmk
, pmk_len
, label
, data
, data_len
,
617 tmp
, key_data_len
) < 0)
620 wpa_printf(MSG_DEBUG
, "FILS: PTK derivation using PRF(SHA256)");
621 if (sha256_prf(pmk
, pmk_len
, label
, data
, data_len
,
622 tmp
, key_data_len
) < 0)
626 wpa_printf(MSG_DEBUG
, "FILS: PTK derivation - SPA=" MACSTR
627 " AA=" MACSTR
, MAC2STR(spa
), MAC2STR(aa
));
628 wpa_hexdump(MSG_DEBUG
, "FILS: SNonce", snonce
, FILS_NONCE_LEN
);
629 wpa_hexdump(MSG_DEBUG
, "FILS: ANonce", anonce
, FILS_NONCE_LEN
);
631 wpa_hexdump_key(MSG_DEBUG
, "FILS: DHss", dhss
, dhss_len
);
632 wpa_hexdump_key(MSG_DEBUG
, "FILS: PMK", pmk
, pmk_len
);
633 wpa_hexdump_key(MSG_DEBUG
, "FILS: FILS-Key-Data", tmp
, key_data_len
);
635 os_memcpy(ick
, tmp
, *ick_len
);
636 wpa_hexdump_key(MSG_DEBUG
, "FILS: ICK", ick
, *ick_len
);
638 os_memcpy(ptk
->kek
, tmp
+ *ick_len
, ptk
->kek_len
);
639 wpa_hexdump_key(MSG_DEBUG
, "FILS: KEK", ptk
->kek
, ptk
->kek_len
);
641 os_memcpy(ptk
->tk
, tmp
+ *ick_len
+ ptk
->kek_len
, ptk
->tk_len
);
642 wpa_hexdump_key(MSG_DEBUG
, "FILS: TK", ptk
->tk
, ptk
->tk_len
);
644 if (fils_ft
&& fils_ft_len
) {
645 os_memcpy(fils_ft
, tmp
+ *ick_len
+ ptk
->kek_len
+ ptk
->tk_len
,
647 wpa_hexdump_key(MSG_DEBUG
, "FILS: FILS-FT",
648 fils_ft
, *fils_ft_len
);
654 os_memset(tmp
, 0, sizeof(tmp
));
657 bin_clear_free(data
, data_len
);
662 int fils_key_auth_sk(const u8
*ick
, size_t ick_len
, const u8
*snonce
,
663 const u8
*anonce
, const u8
*sta_addr
, const u8
*bssid
,
664 const u8
*g_sta
, size_t g_sta_len
,
665 const u8
*g_ap
, size_t g_ap_len
,
666 int akmp
, u8
*key_auth_sta
, u8
*key_auth_ap
,
667 size_t *key_auth_len
)
674 wpa_printf(MSG_DEBUG
, "FILS: Key-Auth derivation: STA-MAC=" MACSTR
675 " AP-BSSID=" MACSTR
, MAC2STR(sta_addr
), MAC2STR(bssid
));
676 wpa_hexdump_key(MSG_DEBUG
, "FILS: ICK", ick
, ick_len
);
677 wpa_hexdump(MSG_DEBUG
, "FILS: SNonce", snonce
, FILS_NONCE_LEN
);
678 wpa_hexdump(MSG_DEBUG
, "FILS: ANonce", anonce
, FILS_NONCE_LEN
);
679 wpa_hexdump(MSG_DEBUG
, "FILS: gSTA", g_sta
, g_sta_len
);
680 wpa_hexdump(MSG_DEBUG
, "FILS: gAP", g_ap
, g_ap_len
);
683 * For (Re)Association Request frame (STA->AP):
684 * Key-Auth = HMAC-Hash(ICK, SNonce || ANonce || STA-MAC || AP-BSSID
685 * [ || gSTA || gAP ])
688 len
[0] = FILS_NONCE_LEN
;
690 len
[1] = FILS_NONCE_LEN
;
695 if (g_sta
&& g_ap_len
&& g_ap
&& g_ap_len
) {
703 if (wpa_key_mgmt_sha384(akmp
)) {
705 res
= hmac_sha384_vector(ick
, ick_len
, num_elem
, addr
, len
,
707 } else if (wpa_key_mgmt_sha256(akmp
)) {
709 res
= hmac_sha256_vector(ick
, ick_len
, num_elem
, addr
, len
,
718 * For (Re)Association Response frame (AP->STA):
719 * Key-Auth = HMAC-Hash(ICK, ANonce || SNonce || AP-BSSID || STA-MAC
720 * [ || gAP || gSTA ])
726 if (g_sta
&& g_ap_len
&& g_ap
&& g_ap_len
) {
733 if (wpa_key_mgmt_sha384(akmp
))
734 res
= hmac_sha384_vector(ick
, ick_len
, num_elem
, addr
, len
,
736 else if (wpa_key_mgmt_sha256(akmp
))
737 res
= hmac_sha256_vector(ick
, ick_len
, num_elem
, addr
, len
,
742 wpa_hexdump(MSG_DEBUG
, "FILS: Key-Auth (STA)",
743 key_auth_sta
, *key_auth_len
);
744 wpa_hexdump(MSG_DEBUG
, "FILS: Key-Auth (AP)",
745 key_auth_ap
, *key_auth_len
);
750 #endif /* CONFIG_FILS */
753 #ifdef CONFIG_IEEE80211R
754 int wpa_ft_mic(const u8
*kck
, size_t kck_len
, const u8
*sta_addr
,
755 const u8
*ap_addr
, u8 transaction_seqnum
,
756 const u8
*mdie
, size_t mdie_len
,
757 const u8
*ftie
, size_t ftie_len
,
758 const u8
*rsnie
, size_t rsnie_len
,
759 const u8
*ric
, size_t ric_len
, u8
*mic
)
763 size_t i
, num_elem
= 0;
765 size_t mic_len
, fte_fixed_len
;
770 } else if (kck_len
== 24) {
772 #endif /* CONFIG_SHA384 */
774 wpa_printf(MSG_WARNING
, "FT: Unsupported KCK length %u",
775 (unsigned int) kck_len
);
779 fte_fixed_len
= sizeof(struct rsn_ftie
) - 16 + mic_len
;
781 addr
[num_elem
] = sta_addr
;
782 len
[num_elem
] = ETH_ALEN
;
785 addr
[num_elem
] = ap_addr
;
786 len
[num_elem
] = ETH_ALEN
;
789 addr
[num_elem
] = &transaction_seqnum
;
794 addr
[num_elem
] = rsnie
;
795 len
[num_elem
] = rsnie_len
;
799 addr
[num_elem
] = mdie
;
800 len
[num_elem
] = mdie_len
;
804 if (ftie_len
< 2 + fte_fixed_len
)
807 /* IE hdr and mic_control */
808 addr
[num_elem
] = ftie
;
809 len
[num_elem
] = 2 + 2;
812 /* MIC field with all zeros */
813 os_memset(zero_mic
, 0, mic_len
);
814 addr
[num_elem
] = zero_mic
;
815 len
[num_elem
] = mic_len
;
819 addr
[num_elem
] = ftie
+ 2 + 2 + mic_len
;
820 len
[num_elem
] = ftie_len
- (2 + 2 + mic_len
);
824 addr
[num_elem
] = ric
;
825 len
[num_elem
] = ric_len
;
829 for (i
= 0; i
< num_elem
; i
++)
830 wpa_hexdump(MSG_MSGDUMP
, "FT: MIC data", addr
[i
], len
[i
]);
833 u8 hash
[SHA384_MAC_LEN
];
835 if (hmac_sha384_vector(kck
, kck_len
, num_elem
, addr
, len
, hash
))
837 os_memcpy(mic
, hash
, 24);
839 #endif /* CONFIG_SHA384 */
841 omac1_aes_128_vector(kck
, num_elem
, addr
, len
, mic
))
848 static int wpa_ft_parse_ftie(const u8
*ie
, size_t ie_len
,
849 struct wpa_ft_ies
*parse
, int use_sha384
)
854 parse
->ftie_len
= ie_len
;
856 pos
= ie
+ (use_sha384
? sizeof(struct rsn_ftie_sha384
) :
857 sizeof(struct rsn_ftie
));
859 wpa_hexdump(MSG_DEBUG
, "FT: Parse FTE subelements", pos
, end
- pos
);
861 while (end
- pos
>= 2) {
866 if (len
> end
- pos
) {
867 wpa_printf(MSG_DEBUG
, "FT: Truncated subelement");
872 case FTIE_SUBELEM_R1KH_ID
:
873 if (len
!= FT_R1KH_ID_LEN
) {
874 wpa_printf(MSG_DEBUG
,
875 "FT: Invalid R1KH-ID length in FTIE: %d",
879 parse
->r1kh_id
= pos
;
881 case FTIE_SUBELEM_GTK
:
883 parse
->gtk_len
= len
;
885 case FTIE_SUBELEM_R0KH_ID
:
886 if (len
< 1 || len
> FT_R0KH_ID_MAX_LEN
) {
887 wpa_printf(MSG_DEBUG
,
888 "FT: Invalid R0KH-ID length in FTIE: %d",
892 parse
->r0kh_id
= pos
;
893 parse
->r0kh_id_len
= len
;
895 #ifdef CONFIG_IEEE80211W
896 case FTIE_SUBELEM_IGTK
:
898 parse
->igtk_len
= len
;
900 #endif /* CONFIG_IEEE80211W */
902 case FTIE_SUBELEM_OCI
:
904 parse
->oci_len
= len
;
906 #endif /* CONFIG_OCV */
908 wpa_printf(MSG_DEBUG
, "FT: Unknown subelem id %u", id
);
919 int wpa_ft_parse_ies(const u8
*ies
, size_t ies_len
,
920 struct wpa_ft_ies
*parse
, int use_sha384
)
923 struct wpa_ie_data data
;
925 const struct rsn_ftie
*ftie
;
926 int prot_ie_count
= 0;
927 int update_use_sha384
= 0;
929 if (use_sha384
< 0) {
931 update_use_sha384
= 1;
934 os_memset(parse
, 0, sizeof(*parse
));
940 while (end
- pos
>= 2) {
950 wpa_hexdump(MSG_DEBUG
, "FT: RSNE", pos
, len
);
952 parse
->rsn_len
= len
;
953 ret
= wpa_parse_wpa_ie_rsn(parse
->rsn
- 2,
957 wpa_printf(MSG_DEBUG
, "FT: Failed to parse "
961 parse
->rsn_capab
= data
.capabilities
;
962 if (data
.num_pmkid
== 1 && data
.pmkid
)
963 parse
->rsn_pmkid
= data
.pmkid
;
964 parse
->key_mgmt
= data
.key_mgmt
;
965 parse
->pairwise_cipher
= data
.pairwise_cipher
;
966 if (update_use_sha384
) {
968 wpa_key_mgmt_sha384(parse
->key_mgmt
);
969 update_use_sha384
= 0;
972 case WLAN_EID_MOBILITY_DOMAIN
:
973 wpa_hexdump(MSG_DEBUG
, "FT: MDE", pos
, len
);
974 if (len
< sizeof(struct rsn_mdie
))
977 parse
->mdie_len
= len
;
979 case WLAN_EID_FAST_BSS_TRANSITION
:
980 wpa_hexdump(MSG_DEBUG
, "FT: FTE", pos
, len
);
982 const struct rsn_ftie_sha384
*ftie_sha384
;
984 if (len
< sizeof(*ftie_sha384
))
987 (const struct rsn_ftie_sha384
*) pos
;
988 wpa_hexdump(MSG_DEBUG
, "FT: FTE-MIC Control",
989 ftie_sha384
->mic_control
, 2);
990 wpa_hexdump(MSG_DEBUG
, "FT: FTE-MIC",
992 sizeof(ftie_sha384
->mic
));
993 wpa_hexdump(MSG_DEBUG
, "FT: FTE-ANonce",
996 wpa_hexdump(MSG_DEBUG
, "FT: FTE-SNonce",
999 prot_ie_count
= ftie_sha384
->mic_control
[1];
1000 if (wpa_ft_parse_ftie(pos
, len
, parse
, 1) < 0)
1005 if (len
< sizeof(*ftie
))
1007 ftie
= (const struct rsn_ftie
*) pos
;
1008 wpa_hexdump(MSG_DEBUG
, "FT: FTE-MIC Control",
1009 ftie
->mic_control
, 2);
1010 wpa_hexdump(MSG_DEBUG
, "FT: FTE-MIC",
1011 ftie
->mic
, sizeof(ftie
->mic
));
1012 wpa_hexdump(MSG_DEBUG
, "FT: FTE-ANonce",
1013 ftie
->anonce
, WPA_NONCE_LEN
);
1014 wpa_hexdump(MSG_DEBUG
, "FT: FTE-SNonce",
1015 ftie
->snonce
, WPA_NONCE_LEN
);
1016 prot_ie_count
= ftie
->mic_control
[1];
1017 if (wpa_ft_parse_ftie(pos
, len
, parse
, 0) < 0)
1020 case WLAN_EID_TIMEOUT_INTERVAL
:
1021 wpa_hexdump(MSG_DEBUG
, "FT: Timeout Interval",
1026 parse
->tie_len
= len
;
1028 case WLAN_EID_RIC_DATA
:
1029 if (parse
->ric
== NULL
)
1030 parse
->ric
= pos
- 2;
1037 if (prot_ie_count
== 0)
1038 return 0; /* no MIC */
1041 * Check that the protected IE count matches with IEs included in the
1050 if (prot_ie_count
< 0) {
1051 wpa_printf(MSG_DEBUG
, "FT: Some required IEs not included in "
1052 "the protected IE count");
1056 if (prot_ie_count
== 0 && parse
->ric
) {
1057 wpa_printf(MSG_DEBUG
, "FT: RIC IE(s) in the frame, but not "
1058 "included in protected IE count");
1062 /* Determine the end of the RIC IE(s) */
1065 while (end
- pos
>= 2 && 2 + pos
[1] <= end
- pos
&&
1070 parse
->ric_len
= pos
- parse
->ric
;
1072 if (prot_ie_count
) {
1073 wpa_printf(MSG_DEBUG
, "FT: %d protected IEs missing from "
1074 "frame", (int) prot_ie_count
);
1080 #endif /* CONFIG_IEEE80211R */
1083 static int rsn_selector_to_bitfield(const u8
*s
)
1085 if (RSN_SELECTOR_GET(s
) == RSN_CIPHER_SUITE_NONE
)
1086 return WPA_CIPHER_NONE
;
1087 if (RSN_SELECTOR_GET(s
) == RSN_CIPHER_SUITE_TKIP
)
1088 return WPA_CIPHER_TKIP
;
1089 if (RSN_SELECTOR_GET(s
) == RSN_CIPHER_SUITE_CCMP
)
1090 return WPA_CIPHER_CCMP
;
1091 #ifdef CONFIG_IEEE80211W
1092 if (RSN_SELECTOR_GET(s
) == RSN_CIPHER_SUITE_AES_128_CMAC
)
1093 return WPA_CIPHER_AES_128_CMAC
;
1094 #endif /* CONFIG_IEEE80211W */
1095 if (RSN_SELECTOR_GET(s
) == RSN_CIPHER_SUITE_GCMP
)
1096 return WPA_CIPHER_GCMP
;
1097 if (RSN_SELECTOR_GET(s
) == RSN_CIPHER_SUITE_CCMP_256
)
1098 return WPA_CIPHER_CCMP_256
;
1099 if (RSN_SELECTOR_GET(s
) == RSN_CIPHER_SUITE_GCMP_256
)
1100 return WPA_CIPHER_GCMP_256
;
1101 if (RSN_SELECTOR_GET(s
) == RSN_CIPHER_SUITE_BIP_GMAC_128
)
1102 return WPA_CIPHER_BIP_GMAC_128
;
1103 if (RSN_SELECTOR_GET(s
) == RSN_CIPHER_SUITE_BIP_GMAC_256
)
1104 return WPA_CIPHER_BIP_GMAC_256
;
1105 if (RSN_SELECTOR_GET(s
) == RSN_CIPHER_SUITE_BIP_CMAC_256
)
1106 return WPA_CIPHER_BIP_CMAC_256
;
1107 if (RSN_SELECTOR_GET(s
) == RSN_CIPHER_SUITE_NO_GROUP_ADDRESSED
)
1108 return WPA_CIPHER_GTK_NOT_USED
;
1113 static int rsn_key_mgmt_to_bitfield(const u8
*s
)
1115 if (RSN_SELECTOR_GET(s
) == RSN_AUTH_KEY_MGMT_UNSPEC_802_1X
)
1116 return WPA_KEY_MGMT_IEEE8021X
;
1117 if (RSN_SELECTOR_GET(s
) == RSN_AUTH_KEY_MGMT_PSK_OVER_802_1X
)
1118 return WPA_KEY_MGMT_PSK
;
1119 #ifdef CONFIG_IEEE80211R
1120 if (RSN_SELECTOR_GET(s
) == RSN_AUTH_KEY_MGMT_FT_802_1X
)
1121 return WPA_KEY_MGMT_FT_IEEE8021X
;
1122 if (RSN_SELECTOR_GET(s
) == RSN_AUTH_KEY_MGMT_FT_PSK
)
1123 return WPA_KEY_MGMT_FT_PSK
;
1124 #ifdef CONFIG_SHA384
1125 if (RSN_SELECTOR_GET(s
) == RSN_AUTH_KEY_MGMT_FT_802_1X_SHA384
)
1126 return WPA_KEY_MGMT_FT_IEEE8021X_SHA384
;
1127 #endif /* CONFIG_SHA384 */
1128 #endif /* CONFIG_IEEE80211R */
1129 #ifdef CONFIG_IEEE80211W
1130 if (RSN_SELECTOR_GET(s
) == RSN_AUTH_KEY_MGMT_802_1X_SHA256
)
1131 return WPA_KEY_MGMT_IEEE8021X_SHA256
;
1132 if (RSN_SELECTOR_GET(s
) == RSN_AUTH_KEY_MGMT_PSK_SHA256
)
1133 return WPA_KEY_MGMT_PSK_SHA256
;
1134 #endif /* CONFIG_IEEE80211W */
1136 if (RSN_SELECTOR_GET(s
) == RSN_AUTH_KEY_MGMT_SAE
)
1137 return WPA_KEY_MGMT_SAE
;
1138 if (RSN_SELECTOR_GET(s
) == RSN_AUTH_KEY_MGMT_FT_SAE
)
1139 return WPA_KEY_MGMT_FT_SAE
;
1140 #endif /* CONFIG_SAE */
1141 if (RSN_SELECTOR_GET(s
) == RSN_AUTH_KEY_MGMT_802_1X_SUITE_B
)
1142 return WPA_KEY_MGMT_IEEE8021X_SUITE_B
;
1143 if (RSN_SELECTOR_GET(s
) == RSN_AUTH_KEY_MGMT_802_1X_SUITE_B_192
)
1144 return WPA_KEY_MGMT_IEEE8021X_SUITE_B_192
;
1145 if (RSN_SELECTOR_GET(s
) == RSN_AUTH_KEY_MGMT_FILS_SHA256
)
1146 return WPA_KEY_MGMT_FILS_SHA256
;
1147 if (RSN_SELECTOR_GET(s
) == RSN_AUTH_KEY_MGMT_FILS_SHA384
)
1148 return WPA_KEY_MGMT_FILS_SHA384
;
1149 if (RSN_SELECTOR_GET(s
) == RSN_AUTH_KEY_MGMT_FT_FILS_SHA256
)
1150 return WPA_KEY_MGMT_FT_FILS_SHA256
;
1151 if (RSN_SELECTOR_GET(s
) == RSN_AUTH_KEY_MGMT_FT_FILS_SHA384
)
1152 return WPA_KEY_MGMT_FT_FILS_SHA384
;
1154 if (RSN_SELECTOR_GET(s
) == RSN_AUTH_KEY_MGMT_OWE
)
1155 return WPA_KEY_MGMT_OWE
;
1156 #endif /* CONFIG_OWE */
1158 if (RSN_SELECTOR_GET(s
) == RSN_AUTH_KEY_MGMT_DPP
)
1159 return WPA_KEY_MGMT_DPP
;
1160 #endif /* CONFIG_DPP */
1161 if (RSN_SELECTOR_GET(s
) == RSN_AUTH_KEY_MGMT_OSEN
)
1162 return WPA_KEY_MGMT_OSEN
;
1167 int wpa_cipher_valid_group(int cipher
)
1169 return wpa_cipher_valid_pairwise(cipher
) ||
1170 cipher
== WPA_CIPHER_GTK_NOT_USED
;
1174 #ifdef CONFIG_IEEE80211W
1175 int wpa_cipher_valid_mgmt_group(int cipher
)
1177 return cipher
== WPA_CIPHER_AES_128_CMAC
||
1178 cipher
== WPA_CIPHER_BIP_GMAC_128
||
1179 cipher
== WPA_CIPHER_BIP_GMAC_256
||
1180 cipher
== WPA_CIPHER_BIP_CMAC_256
;
1182 #endif /* CONFIG_IEEE80211W */
1186 * wpa_parse_wpa_ie_rsn - Parse RSN IE
1187 * @rsn_ie: Buffer containing RSN IE
1188 * @rsn_ie_len: RSN IE buffer length (including IE number and length octets)
1189 * @data: Pointer to structure that will be filled in with parsed data
1190 * Returns: 0 on success, <0 on failure
1192 int wpa_parse_wpa_ie_rsn(const u8
*rsn_ie
, size_t rsn_ie_len
,
1193 struct wpa_ie_data
*data
)
1199 os_memset(data
, 0, sizeof(*data
));
1200 data
->proto
= WPA_PROTO_RSN
;
1201 data
->pairwise_cipher
= WPA_CIPHER_CCMP
;
1202 data
->group_cipher
= WPA_CIPHER_CCMP
;
1203 data
->key_mgmt
= WPA_KEY_MGMT_IEEE8021X
;
1204 data
->capabilities
= 0;
1206 data
->num_pmkid
= 0;
1207 #ifdef CONFIG_IEEE80211W
1208 data
->mgmt_group_cipher
= WPA_CIPHER_AES_128_CMAC
;
1209 #else /* CONFIG_IEEE80211W */
1210 data
->mgmt_group_cipher
= 0;
1211 #endif /* CONFIG_IEEE80211W */
1213 if (rsn_ie_len
== 0) {
1214 /* No RSN IE - fail silently */
1218 if (rsn_ie_len
< sizeof(struct rsn_ie_hdr
)) {
1219 wpa_printf(MSG_DEBUG
, "%s: ie len too short %lu",
1220 __func__
, (unsigned long) rsn_ie_len
);
1224 if (rsn_ie_len
>= 6 && rsn_ie
[1] >= 4 &&
1225 rsn_ie
[1] == rsn_ie_len
- 2 &&
1226 WPA_GET_BE32(&rsn_ie
[2]) == OSEN_IE_VENDOR_TYPE
) {
1228 left
= rsn_ie_len
- 6;
1230 data
->group_cipher
= WPA_CIPHER_GTK_NOT_USED
;
1231 data
->has_group
= 1;
1232 data
->key_mgmt
= WPA_KEY_MGMT_OSEN
;
1233 data
->proto
= WPA_PROTO_OSEN
;
1235 const struct rsn_ie_hdr
*hdr
;
1237 hdr
= (const struct rsn_ie_hdr
*) rsn_ie
;
1239 if (hdr
->elem_id
!= WLAN_EID_RSN
||
1240 hdr
->len
!= rsn_ie_len
- 2 ||
1241 WPA_GET_LE16(hdr
->version
) != RSN_VERSION
) {
1242 wpa_printf(MSG_DEBUG
, "%s: malformed ie or unknown version",
1247 pos
= (const u8
*) (hdr
+ 1);
1248 left
= rsn_ie_len
- sizeof(*hdr
);
1251 if (left
>= RSN_SELECTOR_LEN
) {
1252 data
->group_cipher
= rsn_selector_to_bitfield(pos
);
1253 data
->has_group
= 1;
1254 if (!wpa_cipher_valid_group(data
->group_cipher
)) {
1255 wpa_printf(MSG_DEBUG
,
1256 "%s: invalid group cipher 0x%x (%08x)",
1257 __func__
, data
->group_cipher
,
1261 pos
+= RSN_SELECTOR_LEN
;
1262 left
-= RSN_SELECTOR_LEN
;
1263 } else if (left
> 0) {
1264 wpa_printf(MSG_DEBUG
, "%s: ie length mismatch, %u too much",
1270 data
->pairwise_cipher
= 0;
1271 count
= WPA_GET_LE16(pos
);
1274 if (count
== 0 || count
> left
/ RSN_SELECTOR_LEN
) {
1275 wpa_printf(MSG_DEBUG
, "%s: ie count botch (pairwise), "
1276 "count %u left %u", __func__
, count
, left
);
1280 data
->has_pairwise
= 1;
1281 for (i
= 0; i
< count
; i
++) {
1282 data
->pairwise_cipher
|= rsn_selector_to_bitfield(pos
);
1283 pos
+= RSN_SELECTOR_LEN
;
1284 left
-= RSN_SELECTOR_LEN
;
1286 #ifdef CONFIG_IEEE80211W
1287 if (data
->pairwise_cipher
& WPA_CIPHER_AES_128_CMAC
) {
1288 wpa_printf(MSG_DEBUG
, "%s: AES-128-CMAC used as "
1289 "pairwise cipher", __func__
);
1292 #endif /* CONFIG_IEEE80211W */
1293 } else if (left
== 1) {
1294 wpa_printf(MSG_DEBUG
, "%s: ie too short (for key mgmt)",
1301 count
= WPA_GET_LE16(pos
);
1304 if (count
== 0 || count
> left
/ RSN_SELECTOR_LEN
) {
1305 wpa_printf(MSG_DEBUG
, "%s: ie count botch (key mgmt), "
1306 "count %u left %u", __func__
, count
, left
);
1309 for (i
= 0; i
< count
; i
++) {
1310 data
->key_mgmt
|= rsn_key_mgmt_to_bitfield(pos
);
1311 pos
+= RSN_SELECTOR_LEN
;
1312 left
-= RSN_SELECTOR_LEN
;
1314 } else if (left
== 1) {
1315 wpa_printf(MSG_DEBUG
, "%s: ie too short (for capabilities)",
1321 data
->capabilities
= WPA_GET_LE16(pos
);
1327 u16 num_pmkid
= WPA_GET_LE16(pos
);
1330 if (num_pmkid
> (unsigned int) left
/ PMKID_LEN
) {
1331 wpa_printf(MSG_DEBUG
, "%s: PMKID underflow "
1332 "(num_pmkid=%u left=%d)",
1333 __func__
, num_pmkid
, left
);
1334 data
->num_pmkid
= 0;
1337 data
->num_pmkid
= num_pmkid
;
1339 pos
+= data
->num_pmkid
* PMKID_LEN
;
1340 left
-= data
->num_pmkid
* PMKID_LEN
;
1344 #ifdef CONFIG_IEEE80211W
1346 data
->mgmt_group_cipher
= rsn_selector_to_bitfield(pos
);
1347 if (!wpa_cipher_valid_mgmt_group(data
->mgmt_group_cipher
)) {
1348 wpa_printf(MSG_DEBUG
,
1349 "%s: Unsupported management group cipher 0x%x (%08x)",
1350 __func__
, data
->mgmt_group_cipher
,
1354 pos
+= RSN_SELECTOR_LEN
;
1355 left
-= RSN_SELECTOR_LEN
;
1357 #endif /* CONFIG_IEEE80211W */
1360 wpa_hexdump(MSG_DEBUG
,
1361 "wpa_parse_wpa_ie_rsn: ignore trailing bytes",
1369 static int wpa_selector_to_bitfield(const u8
*s
)
1371 if (RSN_SELECTOR_GET(s
) == WPA_CIPHER_SUITE_NONE
)
1372 return WPA_CIPHER_NONE
;
1373 if (RSN_SELECTOR_GET(s
) == WPA_CIPHER_SUITE_TKIP
)
1374 return WPA_CIPHER_TKIP
;
1375 if (RSN_SELECTOR_GET(s
) == WPA_CIPHER_SUITE_CCMP
)
1376 return WPA_CIPHER_CCMP
;
1381 static int wpa_key_mgmt_to_bitfield(const u8
*s
)
1383 if (RSN_SELECTOR_GET(s
) == WPA_AUTH_KEY_MGMT_UNSPEC_802_1X
)
1384 return WPA_KEY_MGMT_IEEE8021X
;
1385 if (RSN_SELECTOR_GET(s
) == WPA_AUTH_KEY_MGMT_PSK_OVER_802_1X
)
1386 return WPA_KEY_MGMT_PSK
;
1387 if (RSN_SELECTOR_GET(s
) == WPA_AUTH_KEY_MGMT_NONE
)
1388 return WPA_KEY_MGMT_WPA_NONE
;
1393 int wpa_parse_wpa_ie_wpa(const u8
*wpa_ie
, size_t wpa_ie_len
,
1394 struct wpa_ie_data
*data
)
1396 const struct wpa_ie_hdr
*hdr
;
1401 os_memset(data
, 0, sizeof(*data
));
1402 data
->proto
= WPA_PROTO_WPA
;
1403 data
->pairwise_cipher
= WPA_CIPHER_TKIP
;
1404 data
->group_cipher
= WPA_CIPHER_TKIP
;
1405 data
->key_mgmt
= WPA_KEY_MGMT_IEEE8021X
;
1406 data
->capabilities
= 0;
1408 data
->num_pmkid
= 0;
1409 data
->mgmt_group_cipher
= 0;
1411 if (wpa_ie_len
< sizeof(struct wpa_ie_hdr
)) {
1412 wpa_printf(MSG_DEBUG
, "%s: ie len too short %lu",
1413 __func__
, (unsigned long) wpa_ie_len
);
1417 hdr
= (const struct wpa_ie_hdr
*) wpa_ie
;
1419 if (hdr
->elem_id
!= WLAN_EID_VENDOR_SPECIFIC
||
1420 hdr
->len
!= wpa_ie_len
- 2 ||
1421 RSN_SELECTOR_GET(hdr
->oui
) != WPA_OUI_TYPE
||
1422 WPA_GET_LE16(hdr
->version
) != WPA_VERSION
) {
1423 wpa_printf(MSG_DEBUG
, "%s: malformed ie or unknown version",
1428 pos
= (const u8
*) (hdr
+ 1);
1429 left
= wpa_ie_len
- sizeof(*hdr
);
1431 if (left
>= WPA_SELECTOR_LEN
) {
1432 data
->group_cipher
= wpa_selector_to_bitfield(pos
);
1433 pos
+= WPA_SELECTOR_LEN
;
1434 left
-= WPA_SELECTOR_LEN
;
1435 } else if (left
> 0) {
1436 wpa_printf(MSG_DEBUG
, "%s: ie length mismatch, %u too much",
1442 data
->pairwise_cipher
= 0;
1443 count
= WPA_GET_LE16(pos
);
1446 if (count
== 0 || count
> left
/ WPA_SELECTOR_LEN
) {
1447 wpa_printf(MSG_DEBUG
, "%s: ie count botch (pairwise), "
1448 "count %u left %u", __func__
, count
, left
);
1451 for (i
= 0; i
< count
; i
++) {
1452 data
->pairwise_cipher
|= wpa_selector_to_bitfield(pos
);
1453 pos
+= WPA_SELECTOR_LEN
;
1454 left
-= WPA_SELECTOR_LEN
;
1456 } else if (left
== 1) {
1457 wpa_printf(MSG_DEBUG
, "%s: ie too short (for key mgmt)",
1464 count
= WPA_GET_LE16(pos
);
1467 if (count
== 0 || count
> left
/ WPA_SELECTOR_LEN
) {
1468 wpa_printf(MSG_DEBUG
, "%s: ie count botch (key mgmt), "
1469 "count %u left %u", __func__
, count
, left
);
1472 for (i
= 0; i
< count
; i
++) {
1473 data
->key_mgmt
|= wpa_key_mgmt_to_bitfield(pos
);
1474 pos
+= WPA_SELECTOR_LEN
;
1475 left
-= WPA_SELECTOR_LEN
;
1477 } else if (left
== 1) {
1478 wpa_printf(MSG_DEBUG
, "%s: ie too short (for capabilities)",
1484 data
->capabilities
= WPA_GET_LE16(pos
);
1490 wpa_hexdump(MSG_DEBUG
,
1491 "wpa_parse_wpa_ie_wpa: ignore trailing bytes",
1499 int wpa_default_rsn_cipher(int freq
)
1502 return WPA_CIPHER_GCMP
; /* DMG */
1504 return WPA_CIPHER_CCMP
;
1508 #ifdef CONFIG_IEEE80211R
1511 * wpa_derive_pmk_r0 - Derive PMK-R0 and PMKR0Name
1513 * IEEE Std 802.11r-2008 - 8.5.1.5.3
1515 int wpa_derive_pmk_r0(const u8
*xxkey
, size_t xxkey_len
,
1516 const u8
*ssid
, size_t ssid_len
,
1517 const u8
*mdid
, const u8
*r0kh_id
, size_t r0kh_id_len
,
1518 const u8
*s0kh_id
, u8
*pmk_r0
, u8
*pmk_r0_name
,
1521 u8 buf
[1 + SSID_MAX_LEN
+ MOBILITY_DOMAIN_ID_LEN
+ 1 +
1522 FT_R0KH_ID_MAX_LEN
+ ETH_ALEN
];
1523 u8
*pos
, r0_key_data
[64], hash
[48];
1526 size_t q
= use_sha384
? 48 : 32;
1527 size_t r0_key_data_len
= q
+ 16;
1530 * R0-Key-Data = KDF-384(XXKey, "FT-R0",
1531 * SSIDlength || SSID || MDID || R0KHlength ||
1532 * R0KH-ID || S0KH-ID)
1533 * XXKey is either the second 256 bits of MSK or PSK; or the first
1534 * 384 bits of MSK for FT-EAP-SHA384.
1535 * PMK-R0 = L(R0-Key-Data, 0, Q)
1536 * PMK-R0Name-Salt = L(R0-Key-Data, Q, 128)
1537 * Q = 384 for FT-EAP-SHA384; otherwise, 256
1539 if (ssid_len
> SSID_MAX_LEN
|| r0kh_id_len
> FT_R0KH_ID_MAX_LEN
)
1541 wpa_printf(MSG_DEBUG
, "FT: Derive PMK-R0 using KDF-%s",
1542 use_sha384
? "SHA384" : "SHA256");
1543 wpa_hexdump_key(MSG_DEBUG
, "FT: XXKey", xxkey
, xxkey_len
);
1544 wpa_hexdump_ascii(MSG_DEBUG
, "FT: SSID", ssid
, ssid_len
);
1545 wpa_hexdump(MSG_DEBUG
, "FT: MDID", mdid
, MOBILITY_DOMAIN_ID_LEN
);
1546 wpa_hexdump_ascii(MSG_DEBUG
, "FT: R0KH-ID", r0kh_id
, r0kh_id_len
);
1547 wpa_printf(MSG_DEBUG
, "FT: S0KH-ID: " MACSTR
, MAC2STR(s0kh_id
));
1550 os_memcpy(pos
, ssid
, ssid_len
);
1552 os_memcpy(pos
, mdid
, MOBILITY_DOMAIN_ID_LEN
);
1553 pos
+= MOBILITY_DOMAIN_ID_LEN
;
1554 *pos
++ = r0kh_id_len
;
1555 os_memcpy(pos
, r0kh_id
, r0kh_id_len
);
1557 os_memcpy(pos
, s0kh_id
, ETH_ALEN
);
1560 #ifdef CONFIG_SHA384
1562 if (xxkey_len
!= SHA384_MAC_LEN
) {
1563 wpa_printf(MSG_ERROR
,
1564 "FT: Unexpected XXKey length %d (expected %d)",
1565 (int) xxkey_len
, SHA384_MAC_LEN
);
1568 if (sha384_prf(xxkey
, xxkey_len
, "FT-R0", buf
, pos
- buf
,
1569 r0_key_data
, r0_key_data_len
) < 0)
1572 #endif /* CONFIG_SHA384 */
1574 if (xxkey_len
!= PMK_LEN
) {
1575 wpa_printf(MSG_ERROR
,
1576 "FT: Unexpected XXKey length %d (expected %d)",
1577 (int) xxkey_len
, PMK_LEN
);
1580 if (sha256_prf(xxkey
, xxkey_len
, "FT-R0", buf
, pos
- buf
,
1581 r0_key_data
, r0_key_data_len
) < 0)
1584 os_memcpy(pmk_r0
, r0_key_data
, q
);
1585 wpa_hexdump_key(MSG_DEBUG
, "FT: PMK-R0", pmk_r0
, q
);
1586 wpa_hexdump_key(MSG_DEBUG
, "FT: PMK-R0Name-Salt", &r0_key_data
[q
], 16);
1589 * PMKR0Name = Truncate-128(Hash("FT-R0N" || PMK-R0Name-Salt)
1591 addr
[0] = (const u8
*) "FT-R0N";
1593 addr
[1] = &r0_key_data
[q
];
1596 #ifdef CONFIG_SHA384
1597 if (use_sha384
&& sha384_vector(2, addr
, len
, hash
) < 0)
1599 #endif /* CONFIG_SHA384 */
1600 if (!use_sha384
&& sha256_vector(2, addr
, len
, hash
) < 0)
1602 os_memcpy(pmk_r0_name
, hash
, WPA_PMK_NAME_LEN
);
1603 os_memset(r0_key_data
, 0, sizeof(r0_key_data
));
1609 * wpa_derive_pmk_r1_name - Derive PMKR1Name
1611 * IEEE Std 802.11r-2008 - 8.5.1.5.4
1613 int wpa_derive_pmk_r1_name(const u8
*pmk_r0_name
, const u8
*r1kh_id
,
1614 const u8
*s1kh_id
, u8
*pmk_r1_name
, int use_sha384
)
1621 * PMKR1Name = Truncate-128(Hash("FT-R1N" || PMKR0Name ||
1622 * R1KH-ID || S1KH-ID))
1624 addr
[0] = (const u8
*) "FT-R1N";
1626 addr
[1] = pmk_r0_name
;
1627 len
[1] = WPA_PMK_NAME_LEN
;
1629 len
[2] = FT_R1KH_ID_LEN
;
1633 #ifdef CONFIG_SHA384
1634 if (use_sha384
&& sha384_vector(4, addr
, len
, hash
) < 0)
1636 #endif /* CONFIG_SHA384 */
1637 if (!use_sha384
&& sha256_vector(4, addr
, len
, hash
) < 0)
1639 os_memcpy(pmk_r1_name
, hash
, WPA_PMK_NAME_LEN
);
1645 * wpa_derive_pmk_r1 - Derive PMK-R1 and PMKR1Name from PMK-R0
1647 * IEEE Std 802.11r-2008 - 8.5.1.5.4
1649 int wpa_derive_pmk_r1(const u8
*pmk_r0
, size_t pmk_r0_len
,
1650 const u8
*pmk_r0_name
,
1651 const u8
*r1kh_id
, const u8
*s1kh_id
,
1652 u8
*pmk_r1
, u8
*pmk_r1_name
)
1654 u8 buf
[FT_R1KH_ID_LEN
+ ETH_ALEN
];
1657 /* PMK-R1 = KDF-256(PMK-R0, "FT-R1", R1KH-ID || S1KH-ID) */
1658 wpa_printf(MSG_DEBUG
, "FT: Derive PMK-R1 using KDF-%s",
1659 pmk_r0_len
== SHA384_MAC_LEN
? "SHA384" : "SHA256");
1660 wpa_hexdump_key(MSG_DEBUG
, "FT: PMK-R0", pmk_r0
, pmk_r0_len
);
1661 wpa_hexdump(MSG_DEBUG
, "FT: R1KH-ID", r1kh_id
, FT_R1KH_ID_LEN
);
1662 wpa_printf(MSG_DEBUG
, "FT: S1KH-ID: " MACSTR
, MAC2STR(s1kh_id
));
1664 os_memcpy(pos
, r1kh_id
, FT_R1KH_ID_LEN
);
1665 pos
+= FT_R1KH_ID_LEN
;
1666 os_memcpy(pos
, s1kh_id
, ETH_ALEN
);
1669 #ifdef CONFIG_SHA384
1670 if (pmk_r0_len
== SHA384_MAC_LEN
&&
1671 sha384_prf(pmk_r0
, pmk_r0_len
, "FT-R1",
1672 buf
, pos
- buf
, pmk_r1
, pmk_r0_len
) < 0)
1674 #endif /* CONFIG_SHA384 */
1675 if (pmk_r0_len
== PMK_LEN
&&
1676 sha256_prf(pmk_r0
, pmk_r0_len
, "FT-R1",
1677 buf
, pos
- buf
, pmk_r1
, pmk_r0_len
) < 0)
1679 if (pmk_r0_len
!= SHA384_MAC_LEN
&& pmk_r0_len
!= PMK_LEN
) {
1680 wpa_printf(MSG_ERROR
, "FT: Unexpected PMK-R0 length %d",
1684 wpa_hexdump_key(MSG_DEBUG
, "FT: PMK-R1", pmk_r1
, pmk_r0_len
);
1686 return wpa_derive_pmk_r1_name(pmk_r0_name
, r1kh_id
, s1kh_id
,
1688 pmk_r0_len
== SHA384_MAC_LEN
);
1693 * wpa_pmk_r1_to_ptk - Derive PTK and PTKName from PMK-R1
1695 * IEEE Std 802.11r-2008 - 8.5.1.5.5
1697 int wpa_pmk_r1_to_ptk(const u8
*pmk_r1
, size_t pmk_r1_len
,
1698 const u8
*snonce
, const u8
*anonce
,
1699 const u8
*sta_addr
, const u8
*bssid
,
1700 const u8
*pmk_r1_name
,
1701 struct wpa_ptk
*ptk
, u8
*ptk_name
, int akmp
, int cipher
)
1703 u8 buf
[2 * WPA_NONCE_LEN
+ 2 * ETH_ALEN
];
1707 u8 tmp
[2 * WPA_KCK_MAX_LEN
+ 2 * WPA_KEK_MAX_LEN
+ WPA_TK_MAX_LEN
];
1708 size_t ptk_len
, offset
;
1709 int use_sha384
= wpa_key_mgmt_sha384(akmp
);
1712 * PTK = KDF-PTKLen(PMK-R1, "FT-PTK", SNonce || ANonce ||
1713 * BSSID || STA-ADDR)
1715 wpa_printf(MSG_DEBUG
, "FT: Derive PTK using KDF-%s",
1716 use_sha384
? "SHA384" : "SHA256");
1717 wpa_hexdump_key(MSG_DEBUG
, "FT: PMK-R1", pmk_r1
, pmk_r1_len
);
1718 wpa_hexdump(MSG_DEBUG
, "FT: SNonce", snonce
, WPA_NONCE_LEN
);
1719 wpa_hexdump(MSG_DEBUG
, "FT: ANonce", anonce
, WPA_NONCE_LEN
);
1720 wpa_printf(MSG_DEBUG
, "FT: BSSID=" MACSTR
" STA-ADDR=" MACSTR
,
1721 MAC2STR(bssid
), MAC2STR(sta_addr
));
1723 os_memcpy(pos
, snonce
, WPA_NONCE_LEN
);
1724 pos
+= WPA_NONCE_LEN
;
1725 os_memcpy(pos
, anonce
, WPA_NONCE_LEN
);
1726 pos
+= WPA_NONCE_LEN
;
1727 os_memcpy(pos
, bssid
, ETH_ALEN
);
1729 os_memcpy(pos
, sta_addr
, ETH_ALEN
);
1732 ptk
->kck_len
= wpa_kck_len(akmp
, PMK_LEN
);
1733 ptk
->kck2_len
= wpa_kck2_len(akmp
);
1734 ptk
->kek_len
= wpa_kek_len(akmp
, PMK_LEN
);
1735 ptk
->kek2_len
= wpa_kek2_len(akmp
);
1736 ptk
->tk_len
= wpa_cipher_key_len(cipher
);
1737 ptk_len
= ptk
->kck_len
+ ptk
->kek_len
+ ptk
->tk_len
+
1738 ptk
->kck2_len
+ ptk
->kek2_len
;
1740 #ifdef CONFIG_SHA384
1742 if (pmk_r1_len
!= SHA384_MAC_LEN
) {
1743 wpa_printf(MSG_ERROR
,
1744 "FT: Unexpected PMK-R1 length %d (expected %d)",
1745 (int) pmk_r1_len
, SHA384_MAC_LEN
);
1748 if (sha384_prf(pmk_r1
, pmk_r1_len
, "FT-PTK",
1749 buf
, pos
- buf
, tmp
, ptk_len
) < 0)
1752 #endif /* CONFIG_SHA384 */
1754 if (pmk_r1_len
!= PMK_LEN
) {
1755 wpa_printf(MSG_ERROR
,
1756 "FT: Unexpected PMK-R1 length %d (expected %d)",
1757 (int) pmk_r1_len
, PMK_LEN
);
1760 if (sha256_prf(pmk_r1
, pmk_r1_len
, "FT-PTK",
1761 buf
, pos
- buf
, tmp
, ptk_len
) < 0)
1764 wpa_hexdump_key(MSG_DEBUG
, "FT: PTK", tmp
, ptk_len
);
1767 * PTKName = Truncate-128(SHA-256(PMKR1Name || "FT-PTKN" || SNonce ||
1768 * ANonce || BSSID || STA-ADDR))
1770 wpa_hexdump(MSG_DEBUG
, "FT: PMKR1Name", pmk_r1_name
, WPA_PMK_NAME_LEN
);
1771 addr
[0] = pmk_r1_name
;
1772 len
[0] = WPA_PMK_NAME_LEN
;
1773 addr
[1] = (const u8
*) "FT-PTKN";
1776 len
[2] = WPA_NONCE_LEN
;
1778 len
[3] = WPA_NONCE_LEN
;
1784 if (sha256_vector(6, addr
, len
, hash
) < 0)
1786 os_memcpy(ptk_name
, hash
, WPA_PMK_NAME_LEN
);
1788 os_memcpy(ptk
->kck
, tmp
, ptk
->kck_len
);
1789 offset
= ptk
->kck_len
;
1790 os_memcpy(ptk
->kek
, tmp
+ offset
, ptk
->kek_len
);
1791 offset
+= ptk
->kek_len
;
1792 os_memcpy(ptk
->tk
, tmp
+ offset
, ptk
->tk_len
);
1793 offset
+= ptk
->tk_len
;
1794 os_memcpy(ptk
->kck2
, tmp
+ offset
, ptk
->kck2_len
);
1795 offset
+= ptk
->kck2_len
;
1796 os_memcpy(ptk
->kek2
, tmp
+ offset
, ptk
->kek2_len
);
1798 wpa_hexdump_key(MSG_DEBUG
, "FT: KCK", ptk
->kck
, ptk
->kck_len
);
1799 wpa_hexdump_key(MSG_DEBUG
, "FT: KEK", ptk
->kek
, ptk
->kek_len
);
1801 wpa_hexdump_key(MSG_DEBUG
, "FT: KCK2",
1802 ptk
->kck2
, ptk
->kck2_len
);
1804 wpa_hexdump_key(MSG_DEBUG
, "FT: KEK2",
1805 ptk
->kek2
, ptk
->kek2_len
);
1806 wpa_hexdump_key(MSG_DEBUG
, "FT: TK", ptk
->tk
, ptk
->tk_len
);
1807 wpa_hexdump(MSG_DEBUG
, "FT: PTKName", ptk_name
, WPA_PMK_NAME_LEN
);
1809 os_memset(tmp
, 0, sizeof(tmp
));
1814 #endif /* CONFIG_IEEE80211R */
1818 * rsn_pmkid - Calculate PMK identifier
1819 * @pmk: Pairwise master key
1820 * @pmk_len: Length of pmk in bytes
1821 * @aa: Authenticator address
1822 * @spa: Supplicant address
1823 * @pmkid: Buffer for PMKID
1824 * @akmp: Negotiated key management protocol
1826 * IEEE Std 802.11-2016 - 12.7.1.3 Pairwise key hierarchy
1827 * AKM: 00-0F-AC:5, 00-0F-AC:6, 00-0F-AC:14, 00-0F-AC:16
1828 * PMKID = Truncate-128(HMAC-SHA-256(PMK, "PMK Name" || AA || SPA))
1830 * See rsn_pmkid_suite_b()
1832 * See rsn_pmkid_suite_b_192()
1833 * AKM: 00-0F-AC:13, 00-0F-AC:15, 00-0F-AC:17
1834 * PMKID = Truncate-128(HMAC-SHA-384(PMK, "PMK Name" || AA || SPA))
1836 * PMKID = Truncate-128(HMAC-SHA-1(PMK, "PMK Name" || AA || SPA))
1838 void rsn_pmkid(const u8
*pmk
, size_t pmk_len
, const u8
*aa
, const u8
*spa
,
1839 u8
*pmkid
, int akmp
)
1841 char *title
= "PMK Name";
1843 const size_t len
[3] = { 8, ETH_ALEN
, ETH_ALEN
};
1844 unsigned char hash
[SHA384_MAC_LEN
];
1846 addr
[0] = (u8
*) title
;
1851 #if defined(CONFIG_FILS) || defined(CONFIG_SHA384)
1852 } else if (wpa_key_mgmt_sha384(akmp
)) {
1853 wpa_printf(MSG_DEBUG
, "RSN: Derive PMKID using HMAC-SHA-384");
1854 hmac_sha384_vector(pmk
, pmk_len
, 3, addr
, len
, hash
);
1855 #endif /* CONFIG_FILS || CONFIG_SHA384 */
1856 #if defined(CONFIG_IEEE80211W) || defined(CONFIG_FILS)
1857 } else if (wpa_key_mgmt_sha256(akmp
)) {
1858 wpa_printf(MSG_DEBUG
, "RSN: Derive PMKID using HMAC-SHA-256");
1859 hmac_sha256_vector(pmk
, pmk_len
, 3, addr
, len
, hash
);
1860 #endif /* CONFIG_IEEE80211W || CONFIG_FILS */
1862 wpa_printf(MSG_DEBUG
, "RSN: Derive PMKID using HMAC-SHA-1");
1863 hmac_sha1_vector(pmk
, pmk_len
, 3, addr
, len
, hash
);
1865 wpa_hexdump(MSG_DEBUG
, "RSN: Derived PMKID", hash
, PMKID_LEN
);
1866 os_memcpy(pmkid
, hash
, PMKID_LEN
);
1870 #ifdef CONFIG_SUITEB
1872 * rsn_pmkid_suite_b - Calculate PMK identifier for Suite B AKM
1873 * @kck: Key confirmation key
1874 * @kck_len: Length of kck in bytes
1875 * @aa: Authenticator address
1876 * @spa: Supplicant address
1877 * @pmkid: Buffer for PMKID
1878 * Returns: 0 on success, -1 on failure
1880 * IEEE Std 802.11ac-2013 - 11.6.1.3 Pairwise key hierarchy
1881 * PMKID = Truncate(HMAC-SHA-256(KCK, "PMK Name" || AA || SPA))
1883 int rsn_pmkid_suite_b(const u8
*kck
, size_t kck_len
, const u8
*aa
,
1884 const u8
*spa
, u8
*pmkid
)
1886 char *title
= "PMK Name";
1888 const size_t len
[3] = { 8, ETH_ALEN
, ETH_ALEN
};
1889 unsigned char hash
[SHA256_MAC_LEN
];
1891 addr
[0] = (u8
*) title
;
1895 if (hmac_sha256_vector(kck
, kck_len
, 3, addr
, len
, hash
) < 0)
1897 os_memcpy(pmkid
, hash
, PMKID_LEN
);
1900 #endif /* CONFIG_SUITEB */
1903 #ifdef CONFIG_SUITEB192
1905 * rsn_pmkid_suite_b_192 - Calculate PMK identifier for Suite B AKM
1906 * @kck: Key confirmation key
1907 * @kck_len: Length of kck in bytes
1908 * @aa: Authenticator address
1909 * @spa: Supplicant address
1910 * @pmkid: Buffer for PMKID
1911 * Returns: 0 on success, -1 on failure
1913 * IEEE Std 802.11ac-2013 - 11.6.1.3 Pairwise key hierarchy
1914 * PMKID = Truncate(HMAC-SHA-384(KCK, "PMK Name" || AA || SPA))
1916 int rsn_pmkid_suite_b_192(const u8
*kck
, size_t kck_len
, const u8
*aa
,
1917 const u8
*spa
, u8
*pmkid
)
1919 char *title
= "PMK Name";
1921 const size_t len
[3] = { 8, ETH_ALEN
, ETH_ALEN
};
1922 unsigned char hash
[SHA384_MAC_LEN
];
1924 addr
[0] = (u8
*) title
;
1928 if (hmac_sha384_vector(kck
, kck_len
, 3, addr
, len
, hash
) < 0)
1930 os_memcpy(pmkid
, hash
, PMKID_LEN
);
1933 #endif /* CONFIG_SUITEB192 */
1937 * wpa_cipher_txt - Convert cipher suite to a text string
1938 * @cipher: Cipher suite (WPA_CIPHER_* enum)
1939 * Returns: Pointer to a text string of the cipher suite name
1941 const char * wpa_cipher_txt(int cipher
)
1944 case WPA_CIPHER_NONE
:
1946 case WPA_CIPHER_WEP40
:
1948 case WPA_CIPHER_WEP104
:
1950 case WPA_CIPHER_TKIP
:
1952 case WPA_CIPHER_CCMP
:
1954 case WPA_CIPHER_CCMP
| WPA_CIPHER_TKIP
:
1956 case WPA_CIPHER_GCMP
:
1958 case WPA_CIPHER_GCMP_256
:
1960 case WPA_CIPHER_CCMP_256
:
1962 case WPA_CIPHER_AES_128_CMAC
:
1964 case WPA_CIPHER_BIP_GMAC_128
:
1965 return "BIP-GMAC-128";
1966 case WPA_CIPHER_BIP_GMAC_256
:
1967 return "BIP-GMAC-256";
1968 case WPA_CIPHER_BIP_CMAC_256
:
1969 return "BIP-CMAC-256";
1970 case WPA_CIPHER_GTK_NOT_USED
:
1971 return "GTK_NOT_USED";
1979 * wpa_key_mgmt_txt - Convert key management suite to a text string
1980 * @key_mgmt: Key management suite (WPA_KEY_MGMT_* enum)
1981 * @proto: WPA/WPA2 version (WPA_PROTO_*)
1982 * Returns: Pointer to a text string of the key management suite name
1984 const char * wpa_key_mgmt_txt(int key_mgmt
, int proto
)
1987 case WPA_KEY_MGMT_IEEE8021X
:
1988 if (proto
== (WPA_PROTO_RSN
| WPA_PROTO_WPA
))
1989 return "WPA2+WPA/IEEE 802.1X/EAP";
1990 return proto
== WPA_PROTO_RSN
?
1991 "WPA2/IEEE 802.1X/EAP" : "WPA/IEEE 802.1X/EAP";
1992 case WPA_KEY_MGMT_PSK
:
1993 if (proto
== (WPA_PROTO_RSN
| WPA_PROTO_WPA
))
1994 return "WPA2-PSK+WPA-PSK";
1995 return proto
== WPA_PROTO_RSN
?
1996 "WPA2-PSK" : "WPA-PSK";
1997 case WPA_KEY_MGMT_NONE
:
1999 case WPA_KEY_MGMT_WPA_NONE
:
2001 case WPA_KEY_MGMT_IEEE8021X_NO_WPA
:
2002 return "IEEE 802.1X (no WPA)";
2003 #ifdef CONFIG_IEEE80211R
2004 case WPA_KEY_MGMT_FT_IEEE8021X
:
2006 case WPA_KEY_MGMT_FT_IEEE8021X_SHA384
:
2007 return "FT-EAP-SHA384";
2008 case WPA_KEY_MGMT_FT_PSK
:
2010 #endif /* CONFIG_IEEE80211R */
2011 #ifdef CONFIG_IEEE80211W
2012 case WPA_KEY_MGMT_IEEE8021X_SHA256
:
2013 return "WPA2-EAP-SHA256";
2014 case WPA_KEY_MGMT_PSK_SHA256
:
2015 return "WPA2-PSK-SHA256";
2016 #endif /* CONFIG_IEEE80211W */
2017 case WPA_KEY_MGMT_WPS
:
2019 case WPA_KEY_MGMT_SAE
:
2021 case WPA_KEY_MGMT_FT_SAE
:
2023 case WPA_KEY_MGMT_OSEN
:
2025 case WPA_KEY_MGMT_IEEE8021X_SUITE_B
:
2026 return "WPA2-EAP-SUITE-B";
2027 case WPA_KEY_MGMT_IEEE8021X_SUITE_B_192
:
2028 return "WPA2-EAP-SUITE-B-192";
2029 case WPA_KEY_MGMT_FILS_SHA256
:
2030 return "FILS-SHA256";
2031 case WPA_KEY_MGMT_FILS_SHA384
:
2032 return "FILS-SHA384";
2033 case WPA_KEY_MGMT_FT_FILS_SHA256
:
2034 return "FT-FILS-SHA256";
2035 case WPA_KEY_MGMT_FT_FILS_SHA384
:
2036 return "FT-FILS-SHA384";
2037 case WPA_KEY_MGMT_OWE
:
2039 case WPA_KEY_MGMT_DPP
:
2047 u32
wpa_akm_to_suite(int akm
)
2049 if (akm
& WPA_KEY_MGMT_FT_IEEE8021X_SHA384
)
2050 return RSN_AUTH_KEY_MGMT_FT_802_1X_SHA384
;
2051 if (akm
& WPA_KEY_MGMT_FT_IEEE8021X
)
2052 return RSN_AUTH_KEY_MGMT_FT_802_1X
;
2053 if (akm
& WPA_KEY_MGMT_FT_PSK
)
2054 return RSN_AUTH_KEY_MGMT_FT_PSK
;
2055 if (akm
& WPA_KEY_MGMT_IEEE8021X_SHA256
)
2056 return RSN_AUTH_KEY_MGMT_802_1X_SHA256
;
2057 if (akm
& WPA_KEY_MGMT_IEEE8021X
)
2058 return RSN_AUTH_KEY_MGMT_UNSPEC_802_1X
;
2059 if (akm
& WPA_KEY_MGMT_PSK_SHA256
)
2060 return RSN_AUTH_KEY_MGMT_PSK_SHA256
;
2061 if (akm
& WPA_KEY_MGMT_PSK
)
2062 return RSN_AUTH_KEY_MGMT_PSK_OVER_802_1X
;
2063 if (akm
& WPA_KEY_MGMT_CCKM
)
2064 return RSN_AUTH_KEY_MGMT_CCKM
;
2065 if (akm
& WPA_KEY_MGMT_OSEN
)
2066 return RSN_AUTH_KEY_MGMT_OSEN
;
2067 if (akm
& WPA_KEY_MGMT_IEEE8021X_SUITE_B
)
2068 return RSN_AUTH_KEY_MGMT_802_1X_SUITE_B
;
2069 if (akm
& WPA_KEY_MGMT_IEEE8021X_SUITE_B_192
)
2070 return RSN_AUTH_KEY_MGMT_802_1X_SUITE_B_192
;
2071 if (akm
& WPA_KEY_MGMT_FILS_SHA256
)
2072 return RSN_AUTH_KEY_MGMT_FILS_SHA256
;
2073 if (akm
& WPA_KEY_MGMT_FILS_SHA384
)
2074 return RSN_AUTH_KEY_MGMT_FILS_SHA384
;
2075 if (akm
& WPA_KEY_MGMT_FT_FILS_SHA256
)
2076 return RSN_AUTH_KEY_MGMT_FT_FILS_SHA256
;
2077 if (akm
& WPA_KEY_MGMT_FT_FILS_SHA384
)
2078 return RSN_AUTH_KEY_MGMT_FT_FILS_SHA384
;
2079 if (akm
& WPA_KEY_MGMT_SAE
)
2080 return RSN_AUTH_KEY_MGMT_SAE
;
2081 if (akm
& WPA_KEY_MGMT_FT_SAE
)
2082 return RSN_AUTH_KEY_MGMT_FT_SAE
;
2083 if (akm
& WPA_KEY_MGMT_OWE
)
2084 return RSN_AUTH_KEY_MGMT_OWE
;
2085 if (akm
& WPA_KEY_MGMT_DPP
)
2086 return RSN_AUTH_KEY_MGMT_DPP
;
2087 if (akm
& WPA_KEY_MGMT_OSEN
)
2088 return RSN_AUTH_KEY_MGMT_OSEN
;
2093 int wpa_compare_rsn_ie(int ft_initial_assoc
,
2094 const u8
*ie1
, size_t ie1len
,
2095 const u8
*ie2
, size_t ie2len
)
2097 if (ie1
== NULL
|| ie2
== NULL
)
2100 if (ie1len
== ie2len
&& os_memcmp(ie1
, ie2
, ie1len
) == 0)
2101 return 0; /* identical IEs */
2103 #ifdef CONFIG_IEEE80211R
2104 if (ft_initial_assoc
) {
2105 struct wpa_ie_data ie1d
, ie2d
;
2107 * The PMKID-List in RSN IE is different between Beacon/Probe
2108 * Response/(Re)Association Request frames and EAPOL-Key
2109 * messages in FT initial mobility domain association. Allow
2110 * for this, but verify that other parts of the RSN IEs are
2113 if (wpa_parse_wpa_ie_rsn(ie1
, ie1len
, &ie1d
) < 0 ||
2114 wpa_parse_wpa_ie_rsn(ie2
, ie2len
, &ie2d
) < 0)
2116 if (ie1d
.proto
== ie2d
.proto
&&
2117 ie1d
.pairwise_cipher
== ie2d
.pairwise_cipher
&&
2118 ie1d
.group_cipher
== ie2d
.group_cipher
&&
2119 ie1d
.key_mgmt
== ie2d
.key_mgmt
&&
2120 ie1d
.capabilities
== ie2d
.capabilities
&&
2121 ie1d
.mgmt_group_cipher
== ie2d
.mgmt_group_cipher
)
2124 #endif /* CONFIG_IEEE80211R */
2130 int wpa_insert_pmkid(u8
*ies
, size_t *ies_len
, const u8
*pmkid
)
2132 u8
*start
, *end
, *rpos
, *rend
;
2136 end
= ies
+ *ies_len
;
2138 while (start
< end
) {
2139 if (*start
== WLAN_EID_RSN
)
2141 start
+= 2 + start
[1];
2144 wpa_printf(MSG_ERROR
, "RSN: Could not find RSNE in IEs data");
2147 wpa_hexdump(MSG_DEBUG
, "RSN: RSNE before modification",
2148 start
, 2 + start
[1]);
2150 /* Find start of PMKID-Count */
2152 rend
= rpos
+ start
[1];
2154 /* Skip Version and Group Data Cipher Suite */
2156 /* Skip Pairwise Cipher Suite Count and List */
2157 rpos
+= 2 + WPA_GET_LE16(rpos
) * RSN_SELECTOR_LEN
;
2158 /* Skip AKM Suite Count and List */
2159 rpos
+= 2 + WPA_GET_LE16(rpos
) * RSN_SELECTOR_LEN
;
2162 /* Add RSN Capabilities */
2163 os_memmove(rpos
+ 2, rpos
, end
- rpos
);
2170 /* Skip RSN Capabilities */
2173 wpa_printf(MSG_ERROR
,
2174 "RSN: Could not parse RSNE in IEs data");
2180 /* No PMKID-Count field included; add it */
2181 os_memmove(rpos
+ 2 + PMKID_LEN
, rpos
, end
+ added
- rpos
);
2182 WPA_PUT_LE16(rpos
, 1);
2184 os_memcpy(rpos
, pmkid
, PMKID_LEN
);
2185 added
+= 2 + PMKID_LEN
;
2186 start
[1] += 2 + PMKID_LEN
;
2190 if (rend
- rpos
< 2)
2192 num_pmkid
= WPA_GET_LE16(rpos
);
2193 /* PMKID-Count was included; use it */
2194 if (num_pmkid
!= 0) {
2197 if (num_pmkid
* PMKID_LEN
> rend
- rpos
- 2)
2200 * PMKID may have been included in RSN IE in
2201 * (Re)Association Request frame, so remove the old
2202 * PMKID(s) first before adding the new one.
2204 wpa_printf(MSG_DEBUG
,
2205 "RSN: Remove %u old PMKID(s) from RSNE",
2207 after
= rpos
+ 2 + num_pmkid
* PMKID_LEN
;
2208 os_memmove(rpos
+ 2, after
, rend
- after
);
2209 start
[1] -= num_pmkid
* PMKID_LEN
;
2210 added
-= num_pmkid
* PMKID_LEN
;
2212 WPA_PUT_LE16(rpos
, 1);
2214 os_memmove(rpos
+ PMKID_LEN
, rpos
, end
+ added
- rpos
);
2215 os_memcpy(rpos
, pmkid
, PMKID_LEN
);
2217 start
[1] += PMKID_LEN
;
2220 wpa_hexdump(MSG_DEBUG
, "RSN: RSNE after modification (PMKID inserted)",
2221 start
, 2 + start
[1]);
2229 int wpa_cipher_key_len(int cipher
)
2232 case WPA_CIPHER_CCMP_256
:
2233 case WPA_CIPHER_GCMP_256
:
2234 case WPA_CIPHER_BIP_GMAC_256
:
2235 case WPA_CIPHER_BIP_CMAC_256
:
2237 case WPA_CIPHER_CCMP
:
2238 case WPA_CIPHER_GCMP
:
2239 case WPA_CIPHER_AES_128_CMAC
:
2240 case WPA_CIPHER_BIP_GMAC_128
:
2242 case WPA_CIPHER_TKIP
:
2250 int wpa_cipher_rsc_len(int cipher
)
2253 case WPA_CIPHER_CCMP_256
:
2254 case WPA_CIPHER_GCMP_256
:
2255 case WPA_CIPHER_CCMP
:
2256 case WPA_CIPHER_GCMP
:
2257 case WPA_CIPHER_TKIP
:
2265 enum wpa_alg
wpa_cipher_to_alg(int cipher
)
2268 case WPA_CIPHER_CCMP_256
:
2269 return WPA_ALG_CCMP_256
;
2270 case WPA_CIPHER_GCMP_256
:
2271 return WPA_ALG_GCMP_256
;
2272 case WPA_CIPHER_CCMP
:
2273 return WPA_ALG_CCMP
;
2274 case WPA_CIPHER_GCMP
:
2275 return WPA_ALG_GCMP
;
2276 case WPA_CIPHER_TKIP
:
2277 return WPA_ALG_TKIP
;
2278 case WPA_CIPHER_AES_128_CMAC
:
2279 return WPA_ALG_IGTK
;
2280 case WPA_CIPHER_BIP_GMAC_128
:
2281 return WPA_ALG_BIP_GMAC_128
;
2282 case WPA_CIPHER_BIP_GMAC_256
:
2283 return WPA_ALG_BIP_GMAC_256
;
2284 case WPA_CIPHER_BIP_CMAC_256
:
2285 return WPA_ALG_BIP_CMAC_256
;
2287 return WPA_ALG_NONE
;
2291 int wpa_cipher_valid_pairwise(int cipher
)
2293 return cipher
== WPA_CIPHER_CCMP_256
||
2294 cipher
== WPA_CIPHER_GCMP_256
||
2295 cipher
== WPA_CIPHER_CCMP
||
2296 cipher
== WPA_CIPHER_GCMP
||
2297 cipher
== WPA_CIPHER_TKIP
;
2301 u32
wpa_cipher_to_suite(int proto
, int cipher
)
2303 if (cipher
& WPA_CIPHER_CCMP_256
)
2304 return RSN_CIPHER_SUITE_CCMP_256
;
2305 if (cipher
& WPA_CIPHER_GCMP_256
)
2306 return RSN_CIPHER_SUITE_GCMP_256
;
2307 if (cipher
& WPA_CIPHER_CCMP
)
2308 return (proto
== WPA_PROTO_RSN
?
2309 RSN_CIPHER_SUITE_CCMP
: WPA_CIPHER_SUITE_CCMP
);
2310 if (cipher
& WPA_CIPHER_GCMP
)
2311 return RSN_CIPHER_SUITE_GCMP
;
2312 if (cipher
& WPA_CIPHER_TKIP
)
2313 return (proto
== WPA_PROTO_RSN
?
2314 RSN_CIPHER_SUITE_TKIP
: WPA_CIPHER_SUITE_TKIP
);
2315 if (cipher
& WPA_CIPHER_NONE
)
2316 return (proto
== WPA_PROTO_RSN
?
2317 RSN_CIPHER_SUITE_NONE
: WPA_CIPHER_SUITE_NONE
);
2318 if (cipher
& WPA_CIPHER_GTK_NOT_USED
)
2319 return RSN_CIPHER_SUITE_NO_GROUP_ADDRESSED
;
2320 if (cipher
& WPA_CIPHER_AES_128_CMAC
)
2321 return RSN_CIPHER_SUITE_AES_128_CMAC
;
2322 if (cipher
& WPA_CIPHER_BIP_GMAC_128
)
2323 return RSN_CIPHER_SUITE_BIP_GMAC_128
;
2324 if (cipher
& WPA_CIPHER_BIP_GMAC_256
)
2325 return RSN_CIPHER_SUITE_BIP_GMAC_256
;
2326 if (cipher
& WPA_CIPHER_BIP_CMAC_256
)
2327 return RSN_CIPHER_SUITE_BIP_CMAC_256
;
2332 int rsn_cipher_put_suites(u8
*start
, int ciphers
)
2336 if (ciphers
& WPA_CIPHER_CCMP_256
) {
2337 RSN_SELECTOR_PUT(pos
, RSN_CIPHER_SUITE_CCMP_256
);
2338 pos
+= RSN_SELECTOR_LEN
;
2340 if (ciphers
& WPA_CIPHER_GCMP_256
) {
2341 RSN_SELECTOR_PUT(pos
, RSN_CIPHER_SUITE_GCMP_256
);
2342 pos
+= RSN_SELECTOR_LEN
;
2344 if (ciphers
& WPA_CIPHER_CCMP
) {
2345 RSN_SELECTOR_PUT(pos
, RSN_CIPHER_SUITE_CCMP
);
2346 pos
+= RSN_SELECTOR_LEN
;
2348 if (ciphers
& WPA_CIPHER_GCMP
) {
2349 RSN_SELECTOR_PUT(pos
, RSN_CIPHER_SUITE_GCMP
);
2350 pos
+= RSN_SELECTOR_LEN
;
2352 if (ciphers
& WPA_CIPHER_TKIP
) {
2353 RSN_SELECTOR_PUT(pos
, RSN_CIPHER_SUITE_TKIP
);
2354 pos
+= RSN_SELECTOR_LEN
;
2356 if (ciphers
& WPA_CIPHER_NONE
) {
2357 RSN_SELECTOR_PUT(pos
, RSN_CIPHER_SUITE_NONE
);
2358 pos
+= RSN_SELECTOR_LEN
;
2361 return (pos
- start
) / RSN_SELECTOR_LEN
;
2365 int wpa_cipher_put_suites(u8
*start
, int ciphers
)
2369 if (ciphers
& WPA_CIPHER_CCMP
) {
2370 RSN_SELECTOR_PUT(pos
, WPA_CIPHER_SUITE_CCMP
);
2371 pos
+= WPA_SELECTOR_LEN
;
2373 if (ciphers
& WPA_CIPHER_TKIP
) {
2374 RSN_SELECTOR_PUT(pos
, WPA_CIPHER_SUITE_TKIP
);
2375 pos
+= WPA_SELECTOR_LEN
;
2377 if (ciphers
& WPA_CIPHER_NONE
) {
2378 RSN_SELECTOR_PUT(pos
, WPA_CIPHER_SUITE_NONE
);
2379 pos
+= WPA_SELECTOR_LEN
;
2382 return (pos
- start
) / RSN_SELECTOR_LEN
;
2386 int wpa_pick_pairwise_cipher(int ciphers
, int none_allowed
)
2388 if (ciphers
& WPA_CIPHER_CCMP_256
)
2389 return WPA_CIPHER_CCMP_256
;
2390 if (ciphers
& WPA_CIPHER_GCMP_256
)
2391 return WPA_CIPHER_GCMP_256
;
2392 if (ciphers
& WPA_CIPHER_CCMP
)
2393 return WPA_CIPHER_CCMP
;
2394 if (ciphers
& WPA_CIPHER_GCMP
)
2395 return WPA_CIPHER_GCMP
;
2396 if (ciphers
& WPA_CIPHER_TKIP
)
2397 return WPA_CIPHER_TKIP
;
2398 if (none_allowed
&& (ciphers
& WPA_CIPHER_NONE
))
2399 return WPA_CIPHER_NONE
;
2404 int wpa_pick_group_cipher(int ciphers
)
2406 if (ciphers
& WPA_CIPHER_CCMP_256
)
2407 return WPA_CIPHER_CCMP_256
;
2408 if (ciphers
& WPA_CIPHER_GCMP_256
)
2409 return WPA_CIPHER_GCMP_256
;
2410 if (ciphers
& WPA_CIPHER_CCMP
)
2411 return WPA_CIPHER_CCMP
;
2412 if (ciphers
& WPA_CIPHER_GCMP
)
2413 return WPA_CIPHER_GCMP
;
2414 if (ciphers
& WPA_CIPHER_GTK_NOT_USED
)
2415 return WPA_CIPHER_GTK_NOT_USED
;
2416 if (ciphers
& WPA_CIPHER_TKIP
)
2417 return WPA_CIPHER_TKIP
;
2422 int wpa_parse_cipher(const char *value
)
2425 char *start
, *end
, *buf
;
2427 buf
= os_strdup(value
);
2432 while (*start
!= '\0') {
2433 while (*start
== ' ' || *start
== '\t')
2438 while (*end
!= ' ' && *end
!= '\t' && *end
!= '\0')
2440 last
= *end
== '\0';
2442 if (os_strcmp(start
, "CCMP-256") == 0)
2443 val
|= WPA_CIPHER_CCMP_256
;
2444 else if (os_strcmp(start
, "GCMP-256") == 0)
2445 val
|= WPA_CIPHER_GCMP_256
;
2446 else if (os_strcmp(start
, "CCMP") == 0)
2447 val
|= WPA_CIPHER_CCMP
;
2448 else if (os_strcmp(start
, "GCMP") == 0)
2449 val
|= WPA_CIPHER_GCMP
;
2450 else if (os_strcmp(start
, "TKIP") == 0)
2451 val
|= WPA_CIPHER_TKIP
;
2452 else if (os_strcmp(start
, "WEP104") == 0)
2453 val
|= WPA_CIPHER_WEP104
;
2454 else if (os_strcmp(start
, "WEP40") == 0)
2455 val
|= WPA_CIPHER_WEP40
;
2456 else if (os_strcmp(start
, "NONE") == 0)
2457 val
|= WPA_CIPHER_NONE
;
2458 else if (os_strcmp(start
, "GTK_NOT_USED") == 0)
2459 val
|= WPA_CIPHER_GTK_NOT_USED
;
2460 else if (os_strcmp(start
, "AES-128-CMAC") == 0)
2461 val
|= WPA_CIPHER_AES_128_CMAC
;
2462 else if (os_strcmp(start
, "BIP-GMAC-128") == 0)
2463 val
|= WPA_CIPHER_BIP_GMAC_128
;
2464 else if (os_strcmp(start
, "BIP-GMAC-256") == 0)
2465 val
|= WPA_CIPHER_BIP_GMAC_256
;
2466 else if (os_strcmp(start
, "BIP-CMAC-256") == 0)
2467 val
|= WPA_CIPHER_BIP_CMAC_256
;
2483 int wpa_write_ciphers(char *start
, char *end
, int ciphers
, const char *delim
)
2488 if (ciphers
& WPA_CIPHER_CCMP_256
) {
2489 ret
= os_snprintf(pos
, end
- pos
, "%sCCMP-256",
2490 pos
== start
? "" : delim
);
2491 if (os_snprintf_error(end
- pos
, ret
))
2495 if (ciphers
& WPA_CIPHER_GCMP_256
) {
2496 ret
= os_snprintf(pos
, end
- pos
, "%sGCMP-256",
2497 pos
== start
? "" : delim
);
2498 if (os_snprintf_error(end
- pos
, ret
))
2502 if (ciphers
& WPA_CIPHER_CCMP
) {
2503 ret
= os_snprintf(pos
, end
- pos
, "%sCCMP",
2504 pos
== start
? "" : delim
);
2505 if (os_snprintf_error(end
- pos
, ret
))
2509 if (ciphers
& WPA_CIPHER_GCMP
) {
2510 ret
= os_snprintf(pos
, end
- pos
, "%sGCMP",
2511 pos
== start
? "" : delim
);
2512 if (os_snprintf_error(end
- pos
, ret
))
2516 if (ciphers
& WPA_CIPHER_TKIP
) {
2517 ret
= os_snprintf(pos
, end
- pos
, "%sTKIP",
2518 pos
== start
? "" : delim
);
2519 if (os_snprintf_error(end
- pos
, ret
))
2523 if (ciphers
& WPA_CIPHER_AES_128_CMAC
) {
2524 ret
= os_snprintf(pos
, end
- pos
, "%sAES-128-CMAC",
2525 pos
== start
? "" : delim
);
2526 if (os_snprintf_error(end
- pos
, ret
))
2530 if (ciphers
& WPA_CIPHER_BIP_GMAC_128
) {
2531 ret
= os_snprintf(pos
, end
- pos
, "%sBIP-GMAC-128",
2532 pos
== start
? "" : delim
);
2533 if (os_snprintf_error(end
- pos
, ret
))
2537 if (ciphers
& WPA_CIPHER_BIP_GMAC_256
) {
2538 ret
= os_snprintf(pos
, end
- pos
, "%sBIP-GMAC-256",
2539 pos
== start
? "" : delim
);
2540 if (os_snprintf_error(end
- pos
, ret
))
2544 if (ciphers
& WPA_CIPHER_BIP_CMAC_256
) {
2545 ret
= os_snprintf(pos
, end
- pos
, "%sBIP-CMAC-256",
2546 pos
== start
? "" : delim
);
2547 if (os_snprintf_error(end
- pos
, ret
))
2551 if (ciphers
& WPA_CIPHER_NONE
) {
2552 ret
= os_snprintf(pos
, end
- pos
, "%sNONE",
2553 pos
== start
? "" : delim
);
2554 if (os_snprintf_error(end
- pos
, ret
))
2563 int wpa_select_ap_group_cipher(int wpa
, int wpa_pairwise
, int rsn_pairwise
)
2567 /* Select group cipher based on the enabled pairwise cipher suites */
2569 pairwise
|= wpa_pairwise
;
2571 pairwise
|= rsn_pairwise
;
2573 if (pairwise
& WPA_CIPHER_TKIP
)
2574 return WPA_CIPHER_TKIP
;
2575 if ((pairwise
& (WPA_CIPHER_CCMP
| WPA_CIPHER_GCMP
)) == WPA_CIPHER_GCMP
)
2576 return WPA_CIPHER_GCMP
;
2577 if ((pairwise
& (WPA_CIPHER_GCMP_256
| WPA_CIPHER_CCMP
|
2578 WPA_CIPHER_GCMP
)) == WPA_CIPHER_GCMP_256
)
2579 return WPA_CIPHER_GCMP_256
;
2580 if ((pairwise
& (WPA_CIPHER_CCMP_256
| WPA_CIPHER_CCMP
|
2581 WPA_CIPHER_GCMP
)) == WPA_CIPHER_CCMP_256
)
2582 return WPA_CIPHER_CCMP_256
;
2583 return WPA_CIPHER_CCMP
;
2588 int fils_domain_name_hash(const char *domain
, u8
*hash
)
2590 char buf
[255], *wpos
= buf
;
2591 const char *pos
= domain
;
2594 u8 mac
[SHA256_MAC_LEN
];
2596 for (len
= 0; len
< sizeof(buf
) && *pos
; len
++) {
2597 if (isalpha(*pos
) && isupper(*pos
))
2598 *wpos
++ = tolower(*pos
);
2604 addr
[0] = (const u8
*) buf
;
2605 if (sha256_vector(1, addr
, &len
, mac
) < 0)
2607 os_memcpy(hash
, mac
, 2);
2610 #endif /* CONFIG_FILS */