[PATCH 53/55] AP: Support PTK rekeying with the PQC AKMs
Ilan Peer
ilan.peer at intel.com
Thu Dec 3 02:44:52 PST 2026
With the PQC AKMs, EAPOL-Key msg 1/4 and 2/4 of a PTK rekey include a
PQC Parameter element.
Add the element to msg 1/4 and derive the PTK based on msg 2/4. As the
IKM with FT is the PMK-R1, also store it after FT initial mobility
domain association over IEEE 802.1X Authentication frames.
Signed-off-by: Ilan Peer <ilan.peer at intel.com>
---
src/ap/wpa_auth.c | 154 ++++++++++++++++++++++++++++++++++++++++++-
src/ap/wpa_auth_ft.c | 2 +
src/ap/wpa_auth_i.h | 4 ++
3 files changed, 158 insertions(+), 2 deletions(-)
diff --git a/src/ap/wpa_auth.c b/src/ap/wpa_auth.c
index 02fc5adcd1f4..4947d60d100d 100644
--- a/src/ap/wpa_auth.c
+++ b/src/ap/wpa_auth.c
@@ -1210,6 +1210,9 @@ static void wpa_free_sta_sm(struct wpa_state_machine *sm)
wpabuf_clear_free(sm->ft_ml_kem_ss);
#endif /* CONFIG_PQC */
#endif /* CONFIG_IEEE80211R_AP */
+#ifdef CONFIG_PQC
+ pqc_rekey_deinit(&sm->pqc_rekey);
+#endif /* CONFIG_PQC */
os_free(sm->last_rx_eapol_key);
os_free(sm->wpa_ie);
os_free(sm->rsnxe);
@@ -2356,6 +2359,14 @@ void __wpa_send_eapol(struct wpa_authenticator *wpa_auth,
#endif /* CONFIG_TESTING_OPTIONS */
}
+#ifdef CONFIG_PQC
+ /* EAPOL-Key msg 1/4 of a PQC PTK rekey is part of the transcript */
+ if (sm->pqc_rekey.elem && pairwise && !(key_info & WPA_KEY_INFO_MIC)) {
+ wpabuf_free(sm->pqc_rekey.msg1);
+ sm->pqc_rekey.msg1 = wpabuf_alloc_copy(hdr, len);
+ }
+#endif /* CONFIG_PQC */
+
wpa_auth_set_eapol(wpa_auth, sm->addr, WPA_EAPOL_inc_EapolFramesTx, 1);
wpa_hexdump(MSG_DEBUG, "Send EAPOL-Key msg", hdr, len);
wpa_auth_send_eapol(wpa_auth, sm->addr, (u8 *) hdr, len,
@@ -2665,6 +2676,9 @@ SM_STATE(WPA_PTK, INITIALIZE)
}
sm->keycount = 0;
+#ifdef CONFIG_PQC
+ pqc_rekey_deinit(&sm->pqc_rekey);
+#endif /* CONFIG_PQC */
if (sm->GUpdateStationKeys)
wpa_gkeydone_sta(sm);
if (sm->wpa == WPA_VERSION_WPA)
@@ -2955,6 +2969,9 @@ SM_STATE(WPA_PTK, PTKSTART)
#ifdef CONFIG_TESTING_OPTIONS
struct wpa_auth_config *conf = &sm->wpa_auth->conf;
#endif /* CONFIG_TESTING_OPTIONS */
+#ifdef CONFIG_PQC
+ struct wpabuf *pqc_elem = NULL;
+#endif /* CONFIG_PQC */
SM_ENTRY_MA(WPA_PTK, PTKSTART, wpa_ptk);
sm->PTKRequest = false;
@@ -2977,10 +2994,34 @@ SM_STATE(WPA_PTK, PTKSTART)
if (conf->eapol_m1_elements)
buf_len += wpabuf_len(conf->eapol_m1_elements);
#endif /* CONFIG_TESTING_OPTIONS */
+#ifdef CONFIG_PQC
+ /*
+ * With a PQC AKM, the initial PTK is derived during authentication, so
+ * the 4-way handshake is only used for PTK rekeying.
+ */
+ if (wpa_key_mgmt_pqc(sm->wpa_key_mgmt) && sm->security_profile) {
+ if (sm->TimeoutCtr == 1 || !sm->pqc_rekey.elem)
+ pqc_elem = pqc_rekey_init(&sm->pqc_rekey,
+ sm->security_profile->number);
+ else
+ pqc_elem = wpabuf_dup(sm->pqc_rekey.elem);
+ if (!pqc_elem) {
+ wpa_printf(MSG_DEBUG,
+ "RSN: Failed to build PQC Parameter for PTK rekeying");
+ return;
+ }
+ buf_len += wpabuf_len(pqc_elem);
+ }
+#endif /* CONFIG_PQC */
buf = os_zalloc(buf_len);
- if (!buf)
+ if (!buf) {
+#ifdef CONFIG_PQC
+ wpabuf_free(pqc_elem);
+#endif /* CONFIG_PQC */
+
return;
+ }
wpa_auth_logger(sm->wpa_auth, wpa_auth_get_spa(sm), LOGGER_DEBUG,
"sending 1/4 msg of 4-Way Handshake");
@@ -3093,6 +3134,15 @@ SM_STATE(WPA_PTK, PTKSTART)
}
#endif /* CONFIG_TESTING_OPTIONS */
+#ifdef CONFIG_PQC
+ if (pqc_elem) {
+ os_memcpy(buf + kde_len, wpabuf_head(pqc_elem),
+ wpabuf_len(pqc_elem));
+ kde_len += wpabuf_len(pqc_elem);
+ wpabuf_free(pqc_elem);
+ }
+#endif /* CONFIG_PQC */
+
key_info = WPA_KEY_INFO_ACK | WPA_KEY_INFO_KEY_TYPE;
if (sm->pairwise_set && sm->wpa != WPA_VERSION_WPA)
key_info |= WPA_KEY_INFO_SECURE;
@@ -3876,6 +3926,89 @@ static int wpa_auth_validate_ml_kdes_m2(struct wpa_state_machine *sm,
}
+#ifdef CONFIG_PQC
+
+static int wpa_pqc_rekey_derive_ptk(struct wpa_state_machine *sm,
+ struct wpa_ptk *ptk)
+{
+ struct ieee802_1x_hdr *hdr;
+ struct wpa_eapol_ie_parse kde;
+ struct wpabuf *dhss = NULL, *ml_kem_ss = NULL;
+ const u8 *ikm, *key_data, *mic;
+ size_t ikm_len, mic_len, msg2_len, kdk_len;
+ u8 t[SHA512_MAC_LEN];
+ size_t t_len = sizeof(t);
+ u16 key_data_len;
+ int ret = -1;
+
+ if (!sm->pqc_rekey.msg1)
+ return -1;
+
+ mic_len = wpa_mic_len(sm->wpa_key_mgmt, sm->pmk_len, sm->hash_alg,
+ sm->pasn_group);
+ hdr = (struct ieee802_1x_hdr *) sm->last_rx_eapol_key;
+ msg2_len = sm->last_rx_eapol_key_len;
+ mic = (const u8 *) (hdr + 1) + sizeof(struct wpa_eapol_key);
+ key_data = mic + mic_len + 2;
+ key_data_len = WPA_GET_BE16(mic + mic_len);
+
+ if (key_data_len > msg2_len - sizeof(*hdr) -
+ sizeof(struct wpa_eapol_key) - mic_len - 2 ||
+ wpa_parse_kde_ies(key_data, key_data_len, &kde) < 0 ||
+ kde.num_pqc_parameter != 1) {
+ wpa_printf(MSG_DEBUG,
+ "RSN: No valid PQC Parameter in EAPOL-Key msg 2/4");
+ return -1;
+ }
+
+ ikm = sm->PMK;
+ ikm_len = sm->pmk_len;
+
+#ifdef CONFIG_IEEE80211R_AP
+ if (wpa_key_mgmt_ft(sm->wpa_key_mgmt)) {
+ ikm = sm->pmk_r1;
+ ikm_len = sm->pmk_r1_len;
+ }
+#endif /* CONFIG_IEEE80211R_AP */
+
+ if (sm->wpa_auth->conf.force_kdk_derivation ||
+ (sm->wpa_auth->conf.secure_ltf &&
+ ieee802_11_rsnx_capab(sm->rsnxe, WLAN_RSNX_CAPAB_SECURE_LTF)))
+ kdk_len = WPA_KDK_MAX_LEN;
+ else
+ kdk_len = 0;
+
+ /*
+ * Derive the PTK from the shared secrets of the PQC Parameter element
+ * of msg 2/4 and the transcript (see Section 12.7.6.3 in Draft IEEE
+ * P802.11bt/D1.1).
+ */
+ if (pqc_rekey_finish(&sm->pqc_rekey, kde.pqc_parameter,
+ kde.pqc_parameter_len, &dhss, &ml_kem_ss) < 0 ||
+ pqc_transcript_2msg(sm->pqc_rekey.profile->hash,
+ wpabuf_head(sm->pqc_rekey.msg1),
+ wpabuf_len(sm->pqc_rekey.msg1),
+ (const u8 *) hdr, msg2_len,
+ mic - (const u8 *) hdr, mic_len,
+ t, &t_len) < 0 ||
+ pqc_pmk_to_ptk(ikm, ikm_len, wpa_auth_get_spa(sm),
+ wpa_auth_get_aa(sm), sm->pqc_rekey.profile->hash,
+ sm->pairwise, dhss ? wpabuf_head(dhss) : NULL,
+ dhss ? wpabuf_len(dhss) : 0,
+ wpabuf_head(ml_kem_ss), t, t_len, ptk, kdk_len) < 0)
+ goto out;
+
+ ret = 0;
+out:
+ wpabuf_clear_free(dhss);
+ wpabuf_clear_free(ml_kem_ss);
+ forced_memzero(t, sizeof(t));
+ return ret;
+}
+
+#endif /* CONFIG_PQC */
+
+
SM_STATE(WPA_PTK, PTKCALCNEGOTIATING)
{
struct wpa_authenticator *wpa_auth = sm->wpa_auth;
@@ -3914,6 +4047,18 @@ SM_STATE(WPA_PTK, PTKCALCNEGOTIATING)
* WPA-PSK: iterate through possible PSKs and select the one matching
* the packet */
for (;;) {
+#ifdef CONFIG_PQC
+ if (sm->pqc_rekey.elem) {
+ ok = wpa_pqc_rekey_derive_ptk(sm, &PTK) == 0 &&
+ wpa_verify_key_mic(sm->wpa_key_mgmt,
+ sm->pmk_len, &PTK,
+ sm->last_rx_eapol_key,
+ sm->last_rx_eapol_key_len,
+ sm->pasn_group) == 0;
+ break;
+ }
+#endif /* CONFIG_PQC */
+
if (wpa_key_mgmt_wpa_psk(sm->wpa_key_mgmt) &&
!wpa_key_mgmt_sae(sm->wpa_key_mgmt)) {
pmk = wpa_auth_get_psk(sm->wpa_auth, sm->addr,
@@ -4260,7 +4405,9 @@ SM_STATE(WPA_PTK, PTKCALCNEGOTIATING)
sm->MICVerified = true;
#ifdef CONFIG_IEEE80211R_AP
- if (wpa_key_mgmt_ft(sm->wpa_key_mgmt) && !sm->ft_completed) {
+ /* A PQC PTK rekey does not derive new PMK-R0/PMK-R1 */
+ if (wpa_key_mgmt_ft(sm->wpa_key_mgmt) && !sm->ft_completed &&
+ !wpa_key_mgmt_pqc(sm->wpa_key_mgmt)) {
wpa_printf(MSG_DEBUG, "FT: Store PMK-R0/PMK-R1");
wpa_auth_ft_store_keys(sm, pmk_r0, pmk_r1, pmk_r0_name,
key_len);
@@ -5512,6 +5659,9 @@ SM_STATE(WPA_PTK, PTKINITDONE)
{
SM_ENTRY_MA(WPA_PTK, PTKINITDONE, wpa_ptk);
sm->EAPOLKeyReceived = false;
+#ifdef CONFIG_PQC
+ pqc_rekey_deinit(&sm->pqc_rekey);
+#endif /* CONFIG_PQC */
if (wpa_auth_validate_ml_kdes_m4(sm) < 0) {
wpa_sta_disconnect(sm->wpa_auth, sm->addr,
diff --git a/src/ap/wpa_auth_ft.c b/src/ap/wpa_auth_ft.c
index 0b016ef1515d..3c6f958ffa31 100644
--- a/src/ap/wpa_auth_ft.c
+++ b/src/ap/wpa_auth_ft.c
@@ -2733,6 +2733,8 @@ int wpa_auth_802_1x_ft_pmk_to_ptk(struct wpa_state_machine *sm,
if (res < 0)
goto out;
+ os_memcpy(sm->pmk_r1, pmk_r1, key_len);
+ sm->pmk_r1_len = key_len;
wpa_auth_ft_store_keys(sm, pmk_r0, pmk_r1, pmk_r0_name, key_len);
ret = 0;
out:
diff --git a/src/ap/wpa_auth_i.h b/src/ap/wpa_auth_i.h
index 90507a789141..ca40ce9af197 100644
--- a/src/ap/wpa_auth_i.h
+++ b/src/ap/wpa_auth_i.h
@@ -174,6 +174,10 @@ struct wpa_state_machine {
int pending_1_of_4_timeout;
+#ifdef CONFIG_PQC
+ struct pqc_rekey pqc_rekey;
+#endif /* CONFIG_PQC */
+
#ifdef CONFIG_P2P
u8 ip_addr[4];
unsigned int ip_addr_bit;
--
2.55.0
More information about the Hostap
mailing list