1 /*
2 * WPA definitions shared between hostapd and wpa_supplicant
3 * Copyright (c) 2002-2018, Jouni Malinen <j@w1.fi>
4 *
5 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
7 */
8
9 #ifndef WPA_COMMON_H
10 #define WPA_COMMON_H
11
12 /* IEEE 802.11i */
13 #define PMKID_LEN 16
14 #define PMK_LEN 32
15 #define PMK_LEN_SUITE_B_192 48
16 #define PMK_LEN_MAX 64
17 #define WPA_REPLAY_COUNTER_LEN 8
18 #define WPA_NONCE_LEN 32
19 #define WPA_KEY_RSC_LEN 8
20 #define WPA_GMK_LEN 32
21 #define WPA_GTK_MAX_LEN 32
22 #define WPA_PASN_PMK_LEN 32
23 #define WPA_PASN_MAX_MIC_LEN 24
24 #define WPA_MAX_RSNXE_LEN 4
25
26 #define OWE_DH_GROUP 19
27
28 #include "utils/common.h"
29
30 #ifdef CONFIG_NO_TKIP
31 #define WPA_ALLOWED_PAIRWISE_CIPHERS \
32 (WPA_CIPHER_CCMP | WPA_CIPHER_GCMP | WPA_CIPHER_NONE | \
33 WPA_CIPHER_GCMP_256 | WPA_CIPHER_CCMP_256)
34 #define WPA_ALLOWED_GROUP_CIPHERS \
35 (WPA_CIPHER_CCMP | WPA_CIPHER_GCMP | \
36 WPA_CIPHER_GCMP_256 | WPA_CIPHER_CCMP_256 | \
37 WPA_CIPHER_GTK_NOT_USED)
38 #else /* CONFIG_NO_TKIP */
39 #define WPA_ALLOWED_PAIRWISE_CIPHERS \
40 (WPA_CIPHER_CCMP | WPA_CIPHER_GCMP | WPA_CIPHER_TKIP | WPA_CIPHER_NONE | \
41 WPA_CIPHER_GCMP_256 | WPA_CIPHER_CCMP_256)
42 #define WPA_ALLOWED_GROUP_CIPHERS \
43 (WPA_CIPHER_CCMP | WPA_CIPHER_GCMP | WPA_CIPHER_TKIP | \
44 WPA_CIPHER_GCMP_256 | WPA_CIPHER_CCMP_256 | \
45 WPA_CIPHER_GTK_NOT_USED)
46 #endif /* CONFIG_NO_TKIP */
47 #define WPA_ALLOWED_GROUP_MGMT_CIPHERS \
48 (WPA_CIPHER_AES_128_CMAC | WPA_CIPHER_BIP_GMAC_128 | WPA_CIPHER_BIP_GMAC_256 | \
49 WPA_CIPHER_BIP_CMAC_256)
50
51 #define WPA_SELECTOR_LEN 4
52 #define WPA_VERSION 1
53 #define RSN_SELECTOR_LEN 4
54 #define RSN_VERSION 1
55
56 #define RSN_SELECTOR(a, b, c, d) \
57 ((((u32) (a)) << 24) | (((u32) (b)) << 16) | (((u32) (c)) << 8) | \
58 (u32) (d))
59
60 #define WPA_AUTH_KEY_MGMT_NONE RSN_SELECTOR(0x00, 0x50, 0xf2, 0)
61 #define WPA_AUTH_KEY_MGMT_UNSPEC_802_1X RSN_SELECTOR(0x00, 0x50, 0xf2, 1)
62 #define WPA_AUTH_KEY_MGMT_PSK_OVER_802_1X RSN_SELECTOR(0x00, 0x50, 0xf2, 2)
63 #define WPA_AUTH_KEY_MGMT_CCKM RSN_SELECTOR(0x00, 0x40, 0x96, 0)
64 #define WPA_CIPHER_SUITE_NONE RSN_SELECTOR(0x00, 0x50, 0xf2, 0)
65 #define WPA_CIPHER_SUITE_TKIP RSN_SELECTOR(0x00, 0x50, 0xf2, 2)
66 #define WPA_CIPHER_SUITE_CCMP RSN_SELECTOR(0x00, 0x50, 0xf2, 4)
67
68
69 #define RSN_AUTH_KEY_MGMT_UNSPEC_802_1X RSN_SELECTOR(0x00, 0x0f, 0xac, 1)
70 #define RSN_AUTH_KEY_MGMT_PSK_OVER_802_1X RSN_SELECTOR(0x00, 0x0f, 0xac, 2)
71 #define RSN_AUTH_KEY_MGMT_FT_802_1X RSN_SELECTOR(0x00, 0x0f, 0xac, 3)
72 #define RSN_AUTH_KEY_MGMT_FT_PSK RSN_SELECTOR(0x00, 0x0f, 0xac, 4)
73 #define RSN_AUTH_KEY_MGMT_802_1X_SHA256 RSN_SELECTOR(0x00, 0x0f, 0xac, 5)
74 #define RSN_AUTH_KEY_MGMT_PSK_SHA256 RSN_SELECTOR(0x00, 0x0f, 0xac, 6)
75 #define RSN_AUTH_KEY_MGMT_TPK_HANDSHAKE RSN_SELECTOR(0x00, 0x0f, 0xac, 7)
76 #define RSN_AUTH_KEY_MGMT_SAE RSN_SELECTOR(0x00, 0x0f, 0xac, 8)
77 #define RSN_AUTH_KEY_MGMT_FT_SAE RSN_SELECTOR(0x00, 0x0f, 0xac, 9)
78 #define RSN_AUTH_KEY_MGMT_802_1X_SUITE_B RSN_SELECTOR(0x00, 0x0f, 0xac, 11)
79 #define RSN_AUTH_KEY_MGMT_802_1X_SUITE_B_192 RSN_SELECTOR(0x00, 0x0f, 0xac, 12)
80 #define RSN_AUTH_KEY_MGMT_FT_802_1X_SHA384 RSN_SELECTOR(0x00, 0x0f, 0xac, 13)
81 #define RSN_AUTH_KEY_MGMT_FILS_SHA256 RSN_SELECTOR(0x00, 0x0f, 0xac, 14)
82 #define RSN_AUTH_KEY_MGMT_FILS_SHA384 RSN_SELECTOR(0x00, 0x0f, 0xac, 15)
83 #define RSN_AUTH_KEY_MGMT_FT_FILS_SHA256 RSN_SELECTOR(0x00, 0x0f, 0xac, 16)
84 #define RSN_AUTH_KEY_MGMT_FT_FILS_SHA384 RSN_SELECTOR(0x00, 0x0f, 0xac, 17)
85 #define RSN_AUTH_KEY_MGMT_OWE RSN_SELECTOR(0x00, 0x0f, 0xac, 18)
86
87 #define RSN_AUTH_KEY_MGMT_PASN RSN_SELECTOR(0x00, 0x0f, 0xac, 21)
88
89 #define RSN_AUTH_KEY_MGMT_CCKM RSN_SELECTOR(0x00, 0x40, 0x96, 0x00)
90 #define RSN_AUTH_KEY_MGMT_OSEN RSN_SELECTOR(0x50, 0x6f, 0x9a, 0x01)
91 #define RSN_AUTH_KEY_MGMT_DPP RSN_SELECTOR(0x50, 0x6f, 0x9a, 0x02)
92
93 #define RSN_CIPHER_SUITE_NONE RSN_SELECTOR(0x00, 0x0f, 0xac, 0)
94 #define RSN_CIPHER_SUITE_WEP40 RSN_SELECTOR(0x00, 0x0f, 0xac, 1)
95 #define RSN_CIPHER_SUITE_TKIP RSN_SELECTOR(0x00, 0x0f, 0xac, 2)
96 #if 0
97 #define RSN_CIPHER_SUITE_WRAP RSN_SELECTOR(0x00, 0x0f, 0xac, 3)
98 #endif
99 #define RSN_CIPHER_SUITE_CCMP RSN_SELECTOR(0x00, 0x0f, 0xac, 4)
100 #define RSN_CIPHER_SUITE_WEP104 RSN_SELECTOR(0x00, 0x0f, 0xac, 5)
101 #define RSN_CIPHER_SUITE_AES_128_CMAC RSN_SELECTOR(0x00, 0x0f, 0xac, 6)
102 #define RSN_CIPHER_SUITE_NO_GROUP_ADDRESSED RSN_SELECTOR(0x00, 0x0f, 0xac, 7)
103 #define RSN_CIPHER_SUITE_GCMP RSN_SELECTOR(0x00, 0x0f, 0xac, 8)
104 #define RSN_CIPHER_SUITE_GCMP_256 RSN_SELECTOR(0x00, 0x0f, 0xac, 9)
105 #define RSN_CIPHER_SUITE_CCMP_256 RSN_SELECTOR(0x00, 0x0f, 0xac, 10)
106 #define RSN_CIPHER_SUITE_BIP_GMAC_128 RSN_SELECTOR(0x00, 0x0f, 0xac, 11)
107 #define RSN_CIPHER_SUITE_BIP_GMAC_256 RSN_SELECTOR(0x00, 0x0f, 0xac, 12)
108 #define RSN_CIPHER_SUITE_BIP_CMAC_256 RSN_SELECTOR(0x00, 0x0f, 0xac, 13)
109 #define RSN_CIPHER_SUITE_SMS4 RSN_SELECTOR(0x00, 0x14, 0x72, 1)
110 #define RSN_CIPHER_SUITE_CKIP RSN_SELECTOR(0x00, 0x40, 0x96, 0)
111 #define RSN_CIPHER_SUITE_CKIP_CMIC RSN_SELECTOR(0x00, 0x40, 0x96, 1)
112 #define RSN_CIPHER_SUITE_CMIC RSN_SELECTOR(0x00, 0x40, 0x96, 2)
113 /* KRK is defined for nl80211 use only */
114 #define RSN_CIPHER_SUITE_KRK RSN_SELECTOR(0x00, 0x40, 0x96, 255)
115 #ifdef CONFIG_WAPI
116 #define WLAN_CIPHER_SUITE_SMS4 0x00147201
117 #endif
118
119 /* EAPOL-Key Key Data Encapsulation
120 * GroupKey and PeerKey require encryption, otherwise, encryption is optional.
121 */
122 #define RSN_KEY_DATA_GROUPKEY RSN_SELECTOR(0x00, 0x0f, 0xac, 1)
123 #if 0
124 #define RSN_KEY_DATA_STAKEY RSN_SELECTOR(0x00, 0x0f, 0xac, 2)
125 #endif
126 #define RSN_KEY_DATA_MAC_ADDR RSN_SELECTOR(0x00, 0x0f, 0xac, 3)
127 #define RSN_KEY_DATA_PMKID RSN_SELECTOR(0x00, 0x0f, 0xac, 4)
128 #define RSN_KEY_DATA_IGTK RSN_SELECTOR(0x00, 0x0f, 0xac, 9)
129 #define RSN_KEY_DATA_KEYID RSN_SELECTOR(0x00, 0x0f, 0xac, 10)
130 #define RSN_KEY_DATA_MULTIBAND_GTK RSN_SELECTOR(0x00, 0x0f, 0xac, 11)
131 #define RSN_KEY_DATA_MULTIBAND_KEYID RSN_SELECTOR(0x00, 0x0f, 0xac, 12)
132 #define RSN_KEY_DATA_OCI RSN_SELECTOR(0x00, 0x0f, 0xac, 13)
133 #define RSN_KEY_DATA_BIGTK RSN_SELECTOR(0x00, 0x0f, 0xac, 14)
134
135 #define WFA_KEY_DATA_IP_ADDR_REQ RSN_SELECTOR(0x50, 0x6f, 0x9a, 4)
136 #define WFA_KEY_DATA_IP_ADDR_ALLOC RSN_SELECTOR(0x50, 0x6f, 0x9a, 5)
137 #define WFA_KEY_DATA_TRANSITION_DISABLE RSN_SELECTOR(0x50, 0x6f, 0x9a, 0x20)
138 #define WFA_KEY_DATA_DPP RSN_SELECTOR(0x50, 0x6f, 0x9a, 0x21)
139
140 #define WPA_OUI_TYPE RSN_SELECTOR(0x00, 0x50, 0xf2, 1)
141
142 #define RSN_SELECTOR_PUT(a, val) WPA_PUT_BE32((u8 *) (a), (val))
143 #define RSN_SELECTOR_GET(a) WPA_GET_BE32((const u8 *) (a))
144
145 #define RSN_NUM_REPLAY_COUNTERS_1 0
146 #define RSN_NUM_REPLAY_COUNTERS_2 1
147 #define RSN_NUM_REPLAY_COUNTERS_4 2
148 #define RSN_NUM_REPLAY_COUNTERS_16 3
149
150
151 #ifdef _MSC_VER
152 #pragma pack(push, 1)
153 #endif /* _MSC_VER */
154
155 #define WPA_IGTK_LEN 16
156 #define WPA_IGTK_MAX_LEN 32
157 #define WPA_BIGTK_LEN 16
158 #define WPA_BIGTK_MAX_LEN 32
159
160
161 /* IEEE 802.11, 7.3.2.25.3 RSN Capabilities */
162 #define WPA_CAPABILITY_PREAUTH BIT(0)
163 #define WPA_CAPABILITY_NO_PAIRWISE BIT(1)
164 /* B2-B3: PTKSA Replay Counter */
165 /* B4-B5: GTKSA Replay Counter */
166 #define WPA_CAPABILITY_MFPR BIT(6)
167 #define WPA_CAPABILITY_MFPC BIT(7)
168 /* B8: Reserved */
169 #define WPA_CAPABILITY_PEERKEY_ENABLED BIT(9)
170 #define WPA_CAPABILITY_SPP_A_MSDU_CAPABLE BIT(10)
171 #define WPA_CAPABILITY_SPP_A_MSDU_REQUIRED BIT(11)
172 #define WPA_CAPABILITY_PBAC BIT(12)
173 #define WPA_CAPABILITY_EXT_KEY_ID_FOR_UNICAST BIT(13)
174 #define WPA_CAPABILITY_OCVC BIT(14)
175 /* B15: Reserved */
176
177
178 /* IEEE 802.11r */
179 #define MOBILITY_DOMAIN_ID_LEN 2
180 #define FT_R0KH_ID_MAX_LEN 48
181 #define FT_R1KH_ID_LEN 6
182 #define WPA_PMK_NAME_LEN 16
183
184
185 /* IEEE 802.11, 8.5.2 EAPOL-Key frames */
186 #define WPA_KEY_INFO_TYPE_MASK ((u16) (BIT(0) | BIT(1) | BIT(2)))
187 #define WPA_KEY_INFO_TYPE_AKM_DEFINED 0
188 #define WPA_KEY_INFO_TYPE_HMAC_MD5_RC4 BIT(0)
189 #define WPA_KEY_INFO_TYPE_HMAC_SHA1_AES BIT(1)
190 #define WPA_KEY_INFO_TYPE_AES_128_CMAC 3
191 #define WPA_KEY_INFO_KEY_TYPE BIT(3) /* 1 = Pairwise, 0 = Group key */
192 /* bit4..5 is used in WPA, but is reserved in IEEE 802.11i/RSN */
193 #define WPA_KEY_INFO_KEY_INDEX_MASK (BIT(4) | BIT(5))
194 #define WPA_KEY_INFO_KEY_INDEX_SHIFT 4
195 #define WPA_KEY_INFO_INSTALL BIT(6) /* pairwise */
196 #define WPA_KEY_INFO_TXRX BIT(6) /* group */
197 #define WPA_KEY_INFO_ACK BIT(7)
198 #define WPA_KEY_INFO_MIC BIT(8)
199 #define WPA_KEY_INFO_SECURE BIT(9)
200 #define WPA_KEY_INFO_ERROR BIT(10)
201 #define WPA_KEY_INFO_REQUEST BIT(11)
202 #define WPA_KEY_INFO_ENCR_KEY_DATA BIT(12) /* IEEE 802.11i/RSN only */
203 #define WPA_KEY_INFO_SMK_MESSAGE BIT(13)
204
205
206 struct wpa_eapol_key {
207 u8 type;
208 /* Note: key_info, key_length, and key_data_length are unaligned */
209 u8 key_info[2]; /* big endian */
210 u8 key_length[2]; /* big endian */
211 u8 replay_counter[WPA_REPLAY_COUNTER_LEN];
212 u8 key_nonce[WPA_NONCE_LEN];
213 u8 key_iv[16];
214 u8 key_rsc[WPA_KEY_RSC_LEN];
215 u8 key_id[8]; /* Reserved in IEEE 802.11i/RSN */
216 /* variable length Key MIC field */
217 /* big endian 2-octet Key Data Length field */
218 /* followed by Key Data Length bytes of Key Data */
219 } STRUCT_PACKED;
220
221 #define WPA_EAPOL_KEY_MIC_MAX_LEN 32
222 #define WPA_KCK_MAX_LEN 32
223 #define WPA_KEK_MAX_LEN 64
224 #define WPA_TK_MAX_LEN 32
225 #define WPA_KDK_MAX_LEN 32
226 #define FILS_ICK_MAX_LEN 48
227 #define FILS_FT_MAX_LEN 48
228 #define WPA_PASN_KCK_LEN 32
229 #define WPA_PASN_MIC_MAX_LEN 24
230
231 /**
232 * struct wpa_ptk - WPA Pairwise Transient Key
233 * IEEE Std 802.11i-2004 - 8.5.1.2 Pairwise key hierarchy
234 */
235 struct wpa_ptk {
236 u8 kck[WPA_KCK_MAX_LEN]; /* EAPOL-Key Key Confirmation Key (KCK) */
237 u8 kek[WPA_KEK_MAX_LEN]; /* EAPOL-Key Key Encryption Key (KEK) */
238 u8 tk[WPA_TK_MAX_LEN]; /* Temporal Key (TK) */
239 u8 kck2[WPA_KCK_MAX_LEN]; /* FT reasoc Key Confirmation Key (KCK2) */
240 u8 kek2[WPA_KEK_MAX_LEN]; /* FT reassoc Key Encryption Key (KEK2) */
241 u8 kdk[WPA_KDK_MAX_LEN]; /* Key Derivation Key */
242 size_t kck_len;
243 size_t kek_len;
244 size_t tk_len;
245 size_t kck2_len;
246 size_t kek2_len;
247 size_t kdk_len;
248 int installed; /* 1 if key has already been installed to driver */
249 };
250
251 struct wpa_gtk {
252 u8 gtk[WPA_GTK_MAX_LEN];
253 size_t gtk_len;
254 };
255
256 struct wpa_igtk {
257 u8 igtk[WPA_IGTK_MAX_LEN];
258 size_t igtk_len;
259 };
260
261 struct wpa_bigtk {
262 u8 bigtk[WPA_BIGTK_MAX_LEN];
263 size_t bigtk_len;
264 };
265
266 /* WPA IE version 1
267 * 00-50-f2:1 (OUI:OUI type)
268 * 0x01 0x00 (version; little endian)
269 * (all following fields are optional:)
270 * Group Suite Selector (4 octets) (default: TKIP)
271 * Pairwise Suite Count (2 octets, little endian) (default: 1)
272 * Pairwise Suite List (4 * n octets) (default: TKIP)
273 * Authenticated Key Management Suite Count (2 octets, little endian)
274 * (default: 1)
275 * Authenticated Key Management Suite List (4 * n octets)
276 * (default: unspec 802.1X)
277 * WPA Capabilities (2 octets, little endian) (default: 0)
278 */
279
280 struct wpa_ie_hdr {
281 u8 elem_id;
282 u8 len;
283 u8 oui[4]; /* 24-bit OUI followed by 8-bit OUI type */
284 u8 version[2]; /* little endian */
285 } STRUCT_PACKED;
286
287
288 /* 1/4: PMKID
289 * 2/4: RSN IE
290 * 3/4: one or two RSN IEs + GTK IE (encrypted)
291 * 4/4: empty
292 * 1/2: GTK IE (encrypted)
293 * 2/2: empty
294 */
295
296 /* RSN IE version 1
297 * 0x01 0x00 (version; little endian)
298 * (all following fields are optional:)
299 * Group Suite Selector (4 octets) (default: CCMP)
300 * Pairwise Suite Count (2 octets, little endian) (default: 1)
301 * Pairwise Suite List (4 * n octets) (default: CCMP)
302 * Authenticated Key Management Suite Count (2 octets, little endian)
303 * (default: 1)
304 * Authenticated Key Management Suite List (4 * n octets)
305 * (default: unspec 802.1X)
306 * RSN Capabilities (2 octets, little endian) (default: 0)
307 * PMKID Count (2 octets) (default: 0)
308 * PMKID List (16 * n octets)
309 * Management Group Cipher Suite (4 octets) (default: AES-128-CMAC)
310 */
311
312 struct rsn_ie_hdr {
313 u8 elem_id; /* WLAN_EID_RSN */
314 u8 len;
315 u8 version[2]; /* little endian */
316 } STRUCT_PACKED;
317
318
319 struct rsn_error_kde {
320 be16 mui;
321 be16 error_type;
322 } STRUCT_PACKED;
323
324 #define WPA_IGTK_KDE_PREFIX_LEN (2 + 6)
325 struct wpa_igtk_kde {
326 u8 keyid[2];
327 u8 pn[6];
328 u8 igtk[WPA_IGTK_MAX_LEN];
329 } STRUCT_PACKED;
330
331 #define WPA_BIGTK_KDE_PREFIX_LEN (2 + 6)
332 struct wpa_bigtk_kde {
333 u8 keyid[2];
334 u8 pn[6];
335 u8 bigtk[WPA_BIGTK_MAX_LEN];
336 } STRUCT_PACKED;
337
338 struct rsn_mdie {
339 u8 mobility_domain[MOBILITY_DOMAIN_ID_LEN];
340 u8 ft_capab;
341 } STRUCT_PACKED;
342
343 #define RSN_FT_CAPAB_FT_OVER_DS BIT(0)
344 #define RSN_FT_CAPAB_FT_RESOURCE_REQ_SUPP BIT(1)
345
346 struct rsn_ftie {
347 u8 mic_control[2];
348 u8 mic[16];
349 u8 anonce[WPA_NONCE_LEN];
350 u8 snonce[WPA_NONCE_LEN];
351 /* followed by optional parameters */
352 } STRUCT_PACKED;
353
354 struct rsn_ftie_sha384 {
355 u8 mic_control[2];
356 u8 mic[24];
357 u8 anonce[WPA_NONCE_LEN];
358 u8 snonce[WPA_NONCE_LEN];
359 /* followed by optional parameters */
360 } STRUCT_PACKED;
361
362 #define FTIE_SUBELEM_R1KH_ID 1
363 #define FTIE_SUBELEM_GTK 2
364 #define FTIE_SUBELEM_R0KH_ID 3
365 #define FTIE_SUBELEM_IGTK 4
366 #define FTIE_SUBELEM_OCI 5
367 #define FTIE_SUBELEM_BIGTK 6
368
369 struct rsn_rdie {
370 u8 id;
371 u8 descr_count;
372 le16 status_code;
373 } STRUCT_PACKED;
374
375 /* WFA Transition Disable KDE (using OUI_WFA) */
376 /* Transition Disable Bitmap bits */
377 #define TRANSITION_DISABLE_WPA3_PERSONAL BIT(0)
378 #define TRANSITION_DISABLE_SAE_PK BIT(1)
379 #define TRANSITION_DISABLE_WPA3_ENTERPRISE BIT(2)
380 #define TRANSITION_DISABLE_ENHANCED_OPEN BIT(3)
381
382 /* DPP KDE Flags */
383 #define DPP_KDE_PFS_ALLOWED BIT(0)
384 #define DPP_KDE_PFS_REQUIRED BIT(1)
385
386 #ifdef _MSC_VER
387 #pragma pack(pop)
388 #endif /* _MSC_VER */
389
390
391 int wpa_eapol_key_mic(const u8 *key, size_t key_len, int akmp, int ver,
392 const u8 *buf, size_t len, u8 *mic);
393 int wpa_pmk_to_ptk(const u8 *pmk, size_t pmk_len, const char *label,
394 const u8 *addr1, const u8 *addr2,
395 const u8 *nonce1, const u8 *nonce2,
396 struct wpa_ptk *ptk, int akmp, int cipher,
397 const u8 *z, size_t z_len, size_t kdk_len);
398 int fils_rmsk_to_pmk(int akmp, const u8 *rmsk, size_t rmsk_len,
399 const u8 *snonce, const u8 *anonce, const u8 *dh_ss,
400 size_t dh_ss_len, u8 *pmk, size_t *pmk_len);
401 int fils_pmkid_erp(int akmp, const u8 *reauth, size_t reauth_len,
402 u8 *pmkid);
403 int fils_pmk_to_ptk(const u8 *pmk, size_t pmk_len, const u8 *spa, const u8 *aa,
404 const u8 *snonce, const u8 *anonce, const u8 *dhss,
405 size_t dhss_len, struct wpa_ptk *ptk,
406 u8 *ick, size_t *ick_len, int akmp, int cipher,
407 u8 *fils_ft, size_t *fils_ft_len, size_t kdk_len);
408 int fils_key_auth_sk(const u8 *ick, size_t ick_len, const u8 *snonce,
409 const u8 *anonce, const u8 *sta_addr, const u8 *bssid,
410 const u8 *g_sta, size_t g_sta_len,
411 const u8 *g_ap, size_t g_ap_len,
412 int akmp, u8 *key_auth_sta, u8 *key_auth_ap,
413 size_t *key_auth_len);
414
415 #ifdef CONFIG_IEEE80211R
416 int wpa_ft_mic(const u8 *kck, size_t kck_len, const u8 *sta_addr,
417 const u8 *ap_addr, u8 transaction_seqnum,
418 const u8 *mdie, size_t mdie_len,
419 const u8 *ftie, size_t ftie_len,
420 const u8 *rsnie, size_t rsnie_len,
421 const u8 *ric, size_t ric_len,
422 const u8 *rsnxe, size_t rsnxe_len,
423 u8 *mic);
424 int wpa_derive_pmk_r0(const u8 *xxkey, size_t xxkey_len,
425 const u8 *ssid, size_t ssid_len,
426 const u8 *mdid, const u8 *r0kh_id, size_t r0kh_id_len,
427 const u8 *s0kh_id, u8 *pmk_r0, u8 *pmk_r0_name,
428 int use_sha384);
429 int wpa_derive_pmk_r1_name(const u8 *pmk_r0_name, const u8 *r1kh_id,
430 const u8 *s1kh_id, u8 *pmk_r1_name, int use_sha384);
431 int wpa_derive_pmk_r1(const u8 *pmk_r0, size_t pmk_r0_len,
432 const u8 *pmk_r0_name,
433 const u8 *r1kh_id, const u8 *s1kh_id,
434 u8 *pmk_r1, u8 *pmk_r1_name);
435 int wpa_pmk_r1_to_ptk(const u8 *pmk_r1, size_t pmk_r1_len, const u8 *snonce,
436 const u8 *anonce, const u8 *sta_addr, const u8 *bssid,
437 const u8 *pmk_r1_name,
438 struct wpa_ptk *ptk, u8 *ptk_name, int akmp, int cipher,
439 size_t kdk_len);
440 #endif /* CONFIG_IEEE80211R */
441
442 struct wpa_ie_data {
443 int proto;
444 int pairwise_cipher;
445 int has_pairwise;
446 int group_cipher;
447 int has_group;
448 int key_mgmt;
449 int capabilities;
450 size_t num_pmkid;
451 const u8 *pmkid;
452 int mgmt_group_cipher;
453 };
454
455
456 int wpa_parse_wpa_ie_rsn(const u8 *rsn_ie, size_t rsn_ie_len,
457 struct wpa_ie_data *data);
458 int wpa_parse_wpa_ie_wpa(const u8 *wpa_ie, size_t wpa_ie_len,
459 struct wpa_ie_data *data);
460 int wpa_default_rsn_cipher(int freq);
461
462 void rsn_pmkid(const u8 *pmk, size_t pmk_len, const u8 *aa, const u8 *spa,
463 u8 *pmkid, int akmp);
464 #ifdef CONFIG_SUITEB
465 int rsn_pmkid_suite_b(const u8 *kck, size_t kck_len, const u8 *aa,
466 const u8 *spa, u8 *pmkid);
467 #else /* CONFIG_SUITEB */
rsn_pmkid_suite_b(const u8 * kck,size_t kck_len,const u8 * aa,const u8 * spa,u8 * pmkid)468 static inline int rsn_pmkid_suite_b(const u8 *kck, size_t kck_len, const u8 *aa,
469 const u8 *spa, u8 *pmkid)
470 {
471 return -1;
472 }
473 #endif /* CONFIG_SUITEB */
474 #ifdef CONFIG_SUITEB192
475 int rsn_pmkid_suite_b_192(const u8 *kck, size_t kck_len, const u8 *aa,
476 const u8 *spa, u8 *pmkid);
477 #else /* CONFIG_SUITEB192 */
rsn_pmkid_suite_b_192(const u8 * kck,size_t kck_len,const u8 * aa,const u8 * spa,u8 * pmkid)478 static inline int rsn_pmkid_suite_b_192(const u8 *kck, size_t kck_len,
479 const u8 *aa, const u8 *spa, u8 *pmkid)
480 {
481 return -1;
482 }
483 #endif /* CONFIG_SUITEB192 */
484
485 const char * wpa_cipher_txt(int cipher);
486 const char * wpa_key_mgmt_txt(int key_mgmt, int proto);
487 u32 wpa_akm_to_suite(int akm);
488 int wpa_compare_rsn_ie(int ft_initial_assoc,
489 const u8 *ie1, size_t ie1len,
490 const u8 *ie2, size_t ie2len);
491 int wpa_insert_pmkid(u8 *ies, size_t *ies_len, const u8 *pmkid);
492
493 struct wpa_ft_ies {
494 const u8 *mdie;
495 size_t mdie_len;
496 const u8 *ftie;
497 size_t ftie_len;
498 const u8 *r1kh_id;
499 const u8 *gtk;
500 size_t gtk_len;
501 const u8 *r0kh_id;
502 size_t r0kh_id_len;
503 const u8 *fte_anonce;
504 const u8 *fte_snonce;
505 const u8 *rsn;
506 size_t rsn_len;
507 u16 rsn_capab;
508 const u8 *rsn_pmkid;
509 const u8 *tie;
510 size_t tie_len;
511 const u8 *igtk;
512 size_t igtk_len;
513 const u8 *bigtk;
514 size_t bigtk_len;
515 #ifdef CONFIG_OCV
516 const u8 *oci;
517 size_t oci_len;
518 #endif /* CONFIG_OCV */
519 const u8 *ric;
520 size_t ric_len;
521 int key_mgmt;
522 int pairwise_cipher;
523 const u8 *rsnxe;
524 size_t rsnxe_len;
525 };
526
527 /* IEEE P802.11az/D2.6 - 9.4.2.303 PASN Parameters element */
528 #define WPA_PASN_CTRL_COMEBACK_INFO_PRESENT BIT(0)
529 #define WPA_PASN_CTRL_GROUP_AND_KEY_PRESENT BIT(1)
530
531 #define WPA_PASN_WRAPPED_DATA_NO 0
532 #define WPA_PASN_WRAPPED_DATA_FT 1
533 #define WPA_PASN_WRAPPED_DATA_FILS_SK 2
534 #define WPA_PASN_WRAPPED_DATA_SAE 3
535
536 struct pasn_parameter_ie {
537 u8 id;
538 u8 len;
539 u8 id_ext;
540 u8 control; /* WPA_PASN_CTRL_* */
541 u8 wrapped_data_format; /* WPA_PASN_WRAPPED_DATA_* */
542 } STRUCT_PACKED;
543
544 struct wpa_pasn_params_data {
545 u8 wrapped_data_format;
546 u16 after;
547 u8 comeback_len;
548 const u8 *comeback;
549 u16 group;
550 u8 pubkey_len;
551 const u8 *pubkey;
552 };
553
554 /* See RFC 5480 section 2.2 */
555 #define WPA_PASN_PUBKEY_COMPRESSED_0 0x02
556 #define WPA_PASN_PUBKEY_COMPRESSED_1 0x03
557 #define WPA_PASN_PUBKEY_UNCOMPRESSED 0x04
558
559 int wpa_ft_parse_ies(const u8 *ies, size_t ies_len, struct wpa_ft_ies *parse,
560 int use_sha384);
561
562 struct wpa_eapol_ie_parse {
563 const u8 *wpa_ie;
564 size_t wpa_ie_len;
565 const u8 *rsn_ie;
566 size_t rsn_ie_len;
567 const u8 *pmkid;
568 const u8 *key_id;
569 const u8 *gtk;
570 size_t gtk_len;
571 const u8 *mac_addr;
572 size_t mac_addr_len;
573 const u8 *igtk;
574 size_t igtk_len;
575 const u8 *bigtk;
576 size_t bigtk_len;
577 const u8 *mdie;
578 size_t mdie_len;
579 const u8 *ftie;
580 size_t ftie_len;
581 const u8 *ip_addr_req;
582 const u8 *ip_addr_alloc;
583 const u8 *transition_disable;
584 size_t transition_disable_len;
585 const u8 *dpp_kde;
586 size_t dpp_kde_len;
587 const u8 *oci;
588 size_t oci_len;
589 const u8 *osen;
590 size_t osen_len;
591 const u8 *rsnxe;
592 size_t rsnxe_len;
593 const u8 *reassoc_deadline;
594 const u8 *key_lifetime;
595 const u8 *lnkid;
596 size_t lnkid_len;
597 const u8 *ext_capab;
598 size_t ext_capab_len;
599 const u8 *supp_rates;
600 size_t supp_rates_len;
601 const u8 *ext_supp_rates;
602 size_t ext_supp_rates_len;
603 const u8 *ht_capabilities;
604 const u8 *vht_capabilities;
605 const u8 *he_capabilities;
606 size_t he_capab_len;
607 const u8 *he_6ghz_capabilities;
608 const u8 *supp_channels;
609 size_t supp_channels_len;
610 const u8 *supp_oper_classes;
611 size_t supp_oper_classes_len;
612 u8 qosinfo;
613 u16 aid;
614 const u8 *wmm;
615 size_t wmm_len;
616 };
617
618 int wpa_parse_kde_ies(const u8 *buf, size_t len, struct wpa_eapol_ie_parse *ie);
wpa_supplicant_parse_ies(const u8 * buf,size_t len,struct wpa_eapol_ie_parse * ie)619 static inline int wpa_supplicant_parse_ies(const u8 *buf, size_t len,
620 struct wpa_eapol_ie_parse *ie)
621 {
622 return wpa_parse_kde_ies(buf, len, ie);
623 }
624
625
626 int wpa_cipher_key_len(int cipher);
627 int wpa_cipher_rsc_len(int cipher);
628 enum wpa_alg wpa_cipher_to_alg(int cipher);
629 int wpa_cipher_valid_group(int cipher);
630 int wpa_cipher_valid_pairwise(int cipher);
631 int wpa_cipher_valid_mgmt_group(int cipher);
632 u32 wpa_cipher_to_suite(int proto, int cipher);
633 int rsn_cipher_put_suites(u8 *pos, int ciphers);
634 int wpa_cipher_put_suites(u8 *pos, int ciphers);
635 int wpa_pick_pairwise_cipher(int ciphers, int none_allowed);
636 int wpa_pick_group_cipher(int ciphers);
637 int wpa_parse_cipher(const char *value);
638 int wpa_write_ciphers(char *start, char *end, int ciphers, const char *delim);
639 int wpa_select_ap_group_cipher(int wpa, int wpa_pairwise, int rsn_pairwise);
640 unsigned int wpa_mic_len(int akmp, size_t pmk_len);
641 int wpa_use_akm_defined(int akmp);
642 int wpa_use_cmac(int akmp);
643 int wpa_use_aes_key_wrap(int akmp);
644 int fils_domain_name_hash(const char *domain, u8 *hash);
645
646 int pasn_pmk_to_ptk(const u8 *pmk, size_t pmk_len,
647 const u8 *spa, const u8 *bssid,
648 const u8 *dhss, size_t dhss_len,
649 struct wpa_ptk *ptk, int akmp, int cipher,
650 size_t kdk_len);
651
652 u8 pasn_mic_len(int akmp, int cipher);
653
654 int pasn_mic(const u8 *kck, int akmp, int cipher,
655 const u8 *addr1, const u8 *addr2,
656 const u8 *data, size_t data_len,
657 const u8 *frame, size_t frame_len, u8 *mic);
658
659 int pasn_auth_frame_hash(int akmp, int cipher, const u8 *data, size_t len,
660 u8 *hash);
661
662 void wpa_pasn_build_auth_header(struct wpabuf *buf, const u8 *bssid,
663 const u8 *src, const u8 *dst,
664 u8 trans_seq, u16 status);
665
666 int wpa_pasn_add_rsne(struct wpabuf *buf, const u8 *pmkid,
667 int akmp, int cipher);
668
669 void wpa_pasn_add_parameter_ie(struct wpabuf *buf, u16 pasn_group,
670 u8 wrapped_data_format,
671 const struct wpabuf *pubkey, bool compressed,
672 const struct wpabuf *comeback, int after);
673
674 int wpa_pasn_add_wrapped_data(struct wpabuf *buf,
675 struct wpabuf *wrapped_data_buf);
676
677 int wpa_pasn_validate_rsne(const struct wpa_ie_data *data);
678 int wpa_pasn_parse_parameter_ie(const u8 *data, u8 len, bool from_ap,
679 struct wpa_pasn_params_data *pasn_params);
680
681 void wpa_pasn_add_rsnxe(struct wpabuf *buf, u16 capab);
682
683 #endif /* WPA_COMMON_H */
684