[PATCH 15/55] FT: Add MIC calculation for the second FT protocol message
Ilan Peer
ilan.peer at intel.com
Thu Dec 3 02:44:14 PST 2026
Draft IEEE P802.11bi/D6.0, 12.16.8.2 protects the second message of
the FT protocol with a MIC in the FTE when both the FTO and the FTR
support association frame encryption. The MIC uses the same key,
algorithm, and size as the FT reassociation MIC, but is calculated
over different input.
Move the algorithm selection of wpa_ft_mic() into a helper and add
wpa_ft_msg2_mic() on top of it.
Signed-off-by: Ilan Peer <ilan.peer at intel.com>
---
src/common/wpa_common.c | 114 +++++++++++++++++++++++++++++-----------
src/common/wpa_common.h | 5 ++
2 files changed, 88 insertions(+), 31 deletions(-)
diff --git a/src/common/wpa_common.c b/src/common/wpa_common.c
index 9ecb00302ad3..25606a33adac 100644
--- a/src/common/wpa_common.c
+++ b/src/common/wpa_common.c
@@ -1128,6 +1128,39 @@ int fils_key_auth_sk(const u8 *ick, size_t ick_len, const u8 *snonce,
#ifdef CONFIG_IEEE80211R
+
+static int wpa_ft_mic_vector(int key_mgmt, const u8 *kck, size_t kck_len,
+ size_t num_elem, const u8 *addr[],
+ const size_t *len, u8 *mic)
+{
+ u8 hash[SHA512_MAC_LEN];
+ int res = -1;
+
+#ifdef CONFIG_SHA512
+ if (kck_len == 32)
+ res = hmac_sha512_vector(kck, kck_len, num_elem, addr, len,
+ hash);
+#endif /* CONFIG_SHA512 */
+#ifdef CONFIG_SHA384
+ if (kck_len == 24)
+ res = hmac_sha384_vector(kck, kck_len, num_elem, addr, len,
+ hash);
+#endif /* CONFIG_SHA384 */
+ if (kck_len == 16 && key_mgmt == WPA_KEY_MGMT_FT_SAE_EXT_KEY)
+ res = hmac_sha256_vector(kck, kck_len, num_elem, addr, len,
+ hash);
+ else if (kck_len == 16)
+ res = omac1_aes_128_vector(kck, num_elem, addr, len, hash);
+
+ if (!res)
+ os_memcpy(mic, hash, kck_len);
+
+ forced_memzero(hash, sizeof(hash));
+
+ return res ? -1 : 0;
+}
+
+
int wpa_ft_mic(int key_mgmt, const u8 *kck, size_t kck_len, const u8 *sta_addr,
const u8 *ap_addr, u8 transaction_seqnum,
const u8 *mdie, size_t mdie_len,
@@ -1143,7 +1176,6 @@ int wpa_ft_mic(int key_mgmt, const u8 *kck, size_t kck_len, const u8 *sta_addr,
size_t i, num_elem = 0;
u8 zero_mic[32];
size_t mic_len, fte_fixed_len;
- int res;
if (kck_len == 16) {
mic_len = 16;
@@ -1225,41 +1257,61 @@ int wpa_ft_mic(int key_mgmt, const u8 *kck, size_t kck_len, const u8 *sta_addr,
for (i = 0; i < num_elem; i++)
wpa_hexdump(MSG_MSGDUMP, "FT: MIC data", addr[i], len[i]);
- res = -1;
-#ifdef CONFIG_SHA512
- if (kck_len == 32) {
- u8 hash[SHA512_MAC_LEN];
- if (hmac_sha512_vector(kck, kck_len, num_elem, addr, len, hash))
- return -1;
- os_memcpy(mic, hash, 32);
- res = 0;
- }
-#endif /* CONFIG_SHA384 */
-#ifdef CONFIG_SHA384
- if (kck_len == 24) {
- u8 hash[SHA384_MAC_LEN];
+ return wpa_ft_mic_vector(key_mgmt, kck, kck_len, num_elem, addr, len,
+ mic);
+}
- if (hmac_sha384_vector(kck, kck_len, num_elem, addr, len, hash))
- return -1;
- os_memcpy(mic, hash, 24);
- res = 0;
- }
-#endif /* CONFIG_SHA384 */
- if (kck_len == 16 && key_mgmt == WPA_KEY_MGMT_FT_SAE_EXT_KEY) {
- u8 hash[SHA256_MAC_LEN];
- if (hmac_sha256_vector(kck, kck_len, num_elem, addr, len, hash))
- return -1;
- os_memcpy(mic, hash, 16);
- res = 0;
- }
- if (kck_len == 16 && key_mgmt != WPA_KEY_MGMT_FT_SAE_EXT_KEY &&
- omac1_aes_128_vector(kck, num_elem, addr, len, mic) == 0)
- res = 0;
+#ifdef CONFIG_ENC_ASSOC
+/**
+ * wpa_ft_msg2_mic - Calculate the MIC of the second FT protocol message
+ * @key_mgmt: Negotiated FT AKM
+ * @kck: PTK-KCK
+ * @kck_len: Length of the KCK in octets
+ * @fto_addr: FTO MAC address
+ * @ftr_addr: FTR MAC address
+ * @rsne: RSNE in the Beacon frames of the FTR (including the header)
+ * @rsne_len: Length of the RSNE
+ * @rsnxe: RSNXE in the Beacon frames of the FTR (including the header)
+ * @rsnxe_len: Length of the RSNXE
+ * @body: Frame Body of the second message with the FTE MIC field set to 0
+ * @body_len: Length of the Frame Body
+ * @mic: Buffer for the MIC (kck_len octets)
+ * Returns: 0 on success, -1 on failure
+ *
+ * See Draft IEEE P802.11bi/D6.0, 12.16.8.2 (FT protocol)
+ */
+int wpa_ft_msg2_mic(int key_mgmt, const u8 *kck, size_t kck_len,
+ const u8 *fto_addr, const u8 *ftr_addr,
+ const u8 *rsne, size_t rsne_len,
+ const u8 *rsnxe, size_t rsnxe_len,
+ const u8 *body, size_t body_len, u8 *mic)
+{
+ const u8 *addr[5];
+ size_t len[5];
+ size_t num_elem = 0;
- return res;
+ if (!rsne || !rsnxe)
+ return -1;
+
+ addr[num_elem] = fto_addr;
+ len[num_elem++] = ETH_ALEN;
+ addr[num_elem] = ftr_addr;
+ len[num_elem++] = ETH_ALEN;
+ addr[num_elem] = rsne;
+ len[num_elem++] = rsne_len;
+ addr[num_elem] = rsnxe;
+ len[num_elem++] = rsnxe_len;
+ addr[num_elem] = body;
+ len[num_elem++] = body_len;
+
+ wpa_hexdump(MSG_MSGDUMP, "FT: Message 2 MIC body", body, body_len);
+
+ return wpa_ft_mic_vector(key_mgmt, kck, kck_len, num_elem, addr, len,
+ mic);
}
+#endif /* CONFIG_ENC_ASSOC */
static int wpa_ft_parse_ftie(const u8 *ie, size_t ie_len,
diff --git a/src/common/wpa_common.h b/src/common/wpa_common.h
index cb8e5dc3369c..9e6125c0d3b6 100644
--- a/src/common/wpa_common.h
+++ b/src/common/wpa_common.h
@@ -524,6 +524,11 @@ int wpa_ft_mic(int key_mgmt, const u8 *kck, size_t kck_len, const u8 *sta_addr,
const u8 *rsnxe, size_t rsnxe_len,
const struct wpabuf *extra,
u8 *mic);
+int wpa_ft_msg2_mic(int key_mgmt, const u8 *kck, size_t kck_len,
+ const u8 *fto_addr, const u8 *ftr_addr,
+ const u8 *rsne, size_t rsne_len,
+ const u8 *rsnxe, size_t rsnxe_len,
+ const u8 *body, size_t body_len, u8 *mic);
int wpa_derive_pmk_r0(const u8 *xxkey, size_t xxkey_len,
const u8 *ssid, size_t ssid_len,
const u8 *mdid, const u8 *r0kh_id, size_t r0kh_id_len,
--
2.55.0
More information about the Hostap
mailing list