[PATCH 54/55] wpa_supplicant: Support PTK rekeying with the PQC AKMs

Ilan Peer ilan.peer at intel.com
Thu Dec 3 02:44:53 PST 2026


IEEE P802.11bt/D1.1, 12.7.6.2/3: When EAPOL-Key msg 1/4 of a PTK rekey
with the PQC AKMs carries the Authenticator's PQC Parameter element,
respond with the Supplicant's PQC Parameter element in msg 2/4 and
derive the PTK from the shared secrets and the transcript of msg 1/4
and msg 2/4 (12.17.4) before computing the Key MIC of msg 2/4. The IKM
is the PMK, or the PMK-R1 with FT.

Signed-off-by: Ilan Peer <ilan.peer at intel.com>
---
 src/rsn_supp/wpa.c   | 150 ++++++++++++++++++++++++++++++++++++++++++-
 src/rsn_supp/wpa_i.h |   6 ++
 2 files changed, 153 insertions(+), 3 deletions(-)

diff --git a/src/rsn_supp/wpa.c b/src/rsn_supp/wpa.c
index b848230f552b..b64e662989c5 100644
--- a/src/rsn_supp/wpa.c
+++ b/src/rsn_supp/wpa.c
@@ -544,6 +544,73 @@ static int wpa_supplicant_get_pmk(struct wpa_sm *sm,
 }
 
 
+#ifdef CONFIG_PQC
+
+static bool wpa_sm_pqc_rekey(struct wpa_sm *sm)
+{
+	return wpa_key_mgmt_pqc(sm->key_mgmt) && sm->ptk_set &&
+		sm->security_profile;
+}
+
+
+/*
+ * IEEE P802.11bt/D1.1, 12.7.6.2: Derive the PTK of a PQC PTK rekey from the
+ * shared secrets and the transcript of msg 1/4 and msg 2/4 with the Key MIC
+ * field of msg 2/4 set to 0.
+ */
+static int wpa_pqc_rekey_derive_ptk(struct wpa_sm *sm, const u8 *msg2,
+				    size_t msg2_len, size_t mic_offset,
+				    size_t mic_len, struct wpa_ptk *ptk)
+{
+	const struct ieee80211_pqc_profile *profile;
+	const u8 *ikm = sm->pmk, *ap_rsnxe;
+	size_t ikm_len = sm->pmk_len, kdk_len, ap_rsnxe_len;
+	u8 t[SHA512_MAC_LEN];
+	size_t t_len = sizeof(t);
+	int ret;
+
+	profile = pqc_profile_get(sm->security_profile->number);
+	if (!profile)
+		return -1;
+
+#ifdef CONFIG_IEEE80211R
+	if (wpa_key_mgmt_ft(sm->key_mgmt)) {
+		ikm = sm->pmk_r1;
+		ikm_len = sm->pmk_r1_len;
+	}
+#endif /* CONFIG_IEEE80211R */
+
+	ap_rsnxe = wpa_sm_get_ap_rsnxe(sm, &ap_rsnxe_len);
+	if (sm->force_kdk_derivation ||
+	    (sm->secure_ltf &&
+	     ieee802_11_rsnx_capab(ap_rsnxe, WLAN_RSNX_CAPAB_SECURE_LTF)))
+		kdk_len = WPA_KDK_MAX_LEN;
+	else
+		kdk_len = 0;
+
+	if (pqc_transcript_2msg(profile->hash,
+				wpabuf_head(sm->pqc_rekey_msg1),
+				wpabuf_len(sm->pqc_rekey_msg1),
+				msg2, msg2_len, mic_offset, mic_len,
+				t, &t_len) < 0)
+		return -1;
+
+	ret = pqc_pmk_to_ptk(ikm, ikm_len, sm->own_addr,
+			     wpa_sm_get_auth_addr(sm), profile->hash,
+			     sm->pairwise_cipher,
+			     sm->pqc_rekey_dhss ?
+			     wpabuf_head(sm->pqc_rekey_dhss) : NULL,
+			     sm->pqc_rekey_dhss ?
+			     wpabuf_len(sm->pqc_rekey_dhss) : 0,
+			     wpabuf_head(sm->pqc_rekey_ml_kem_ss), t, t_len,
+			     ptk, kdk_len);
+	forced_memzero(t, sizeof(t));
+	return ret;
+}
+
+#endif /* CONFIG_PQC */
+
+
 /**
  * wpa_supplicant_send_2_of_4 - Send message 2 of WPA/RSN 4-Way Handshake
  * @sm: Pointer to WPA state machine data from wpa_sm_init()
@@ -743,6 +810,19 @@ int wpa_supplicant_send_2_of_4(struct wpa_sm *sm, const unsigned char *dst,
 
 	os_memcpy(reply->key_nonce, nonce, WPA_NONCE_LEN);
 
+#ifdef CONFIG_PQC
+	if (sm->pqc_rekey_msg1) {
+		/* The Key MIC field is still 0 */
+		if (wpa_pqc_rekey_derive_ptk(sm, rbuf, rlen, key_mic - rbuf,
+					     mic_len, ptk) < 0) {
+			wpa_printf(MSG_INFO,
+				   "RSN: PQC PTK derivation for PTK rekeying failed");
+			os_free(rbuf);
+			return -1;
+		}
+	}
+#endif /* CONFIG_PQC */
+
 	wpa_dbg(sm->ctx->msg_ctx, MSG_DEBUG, "WPA: Sending EAPOL-Key 2/4");
 	return wpa_eapol_key_send(sm, ptk, ver, dst, ETH_P_EAPOL, rbuf, rlen,
 				  key_mic);
@@ -990,6 +1070,7 @@ failed:
 static void wpa_supplicant_process_1_of_4(struct wpa_sm *sm,
 					  const unsigned char *src_addr,
 					  const struct wpa_eapol_key *key,
+					  const u8 *pdu, size_t pdu_len,
 					  u16 ver, const u8 *key_data,
 					  size_t key_data_len,
 					  enum frame_encryption encrypted)
@@ -1000,6 +1081,11 @@ static void wpa_supplicant_process_1_of_4(struct wpa_sm *sm,
 	u8 *kde, *kde_buf = NULL;
 	size_t kde_len;
 	size_t mlo_kde_len = 0;
+#ifdef CONFIG_PQC
+	struct wpabuf *pqc_elem = NULL, *pqc_msg1 = NULL;
+	struct wpabuf *pqc_dhss = NULL, *pqc_ml_kem_ss = NULL;
+	bool pqc_rekey = wpa_sm_pqc_rekey(sm);
+#endif /* CONFIG_PQC */
 
 	if (encrypted == FRAME_NOT_ENCRYPTED && sm->tk_set &&
 	    wpa_sm_pmf_enabled(sm)) {
@@ -1072,6 +1158,30 @@ static void wpa_supplicant_process_1_of_4(struct wpa_sm *sm,
 	/* Calculate PTK which will be stored as a temporary PTK until it has
 	 * been verified when processing message 3/4. */
 	ptk = &sm->tptk;
+#ifdef CONFIG_PQC
+	if (pqc_rekey) {
+		if (ie.num_pqc_parameter != 1) {
+			wpa_printf(MSG_INFO,
+				   "RSN: Invalid number of PQC Parameter elements (%u) in EAPOL-Key msg 1/4 of PTK rekeying",
+				   ie.num_pqc_parameter);
+			goto failed;
+		}
+		pqc_elem = pqc_rekey_respond(sm->security_profile->number,
+					     ie.pqc_parameter,
+					     ie.pqc_parameter_len,
+					     &pqc_dhss, &pqc_ml_kem_ss);
+		pqc_msg1 = wpabuf_alloc_copy(pdu, pdu_len);
+		if (!pqc_elem || !pqc_msg1)
+			goto failed;
+		/*
+		 * The PTK is derived once msg 2/4 has been built. The hash
+		 * algorithm is needed before that for the Key MIC length.
+		 */
+		os_memset(ptk, 0, sizeof(*ptk));
+		ptk->hash_alg = pqc_profile_get(
+			sm->security_profile->number)->hash;
+	} else
+#endif /* CONFIG_PQC */
 	if (wpa_derive_ptk(sm, src_addr, key, ptk) < 0)
 		goto failed;
 	if (sm->pairwise_cipher == WPA_CIPHER_TKIP)
@@ -1090,7 +1200,11 @@ static void wpa_supplicant_process_1_of_4(struct wpa_sm *sm,
 			    2 + RSN_SELECTOR_LEN + 3 +
 			    sm->assoc_rsnxe_len +
 			    2 + RSN_SELECTOR_LEN + 1 +
-			    2 + RSN_SELECTOR_LEN + 2 + mlo_kde_len);
+			    2 + RSN_SELECTOR_LEN + 2 + mlo_kde_len
+#ifdef CONFIG_PQC
+			    + (pqc_elem ? wpabuf_len(pqc_elem) : 0)
+#endif /* CONFIG_PQC */
+			    );
 
 	if (!kde_buf)
 		goto failed;
@@ -1180,16 +1294,45 @@ static void wpa_supplicant_process_1_of_4(struct wpa_sm *sm,
 		kde_len = pos - kde;
 	}
 
-	if (wpa_supplicant_send_2_of_4(sm, wpa_sm_get_auth_addr(sm), key, ver,
-				       sm->snonce, kde, kde_len, ptk) < 0)
+#ifdef CONFIG_PQC
+	if (pqc_elem) {
+		os_memcpy(kde + kde_len, wpabuf_head(pqc_elem),
+			  wpabuf_len(pqc_elem));
+		kde_len += wpabuf_len(pqc_elem);
+		sm->pqc_rekey_msg1 = pqc_msg1;
+		sm->pqc_rekey_dhss = pqc_dhss;
+		sm->pqc_rekey_ml_kem_ss = pqc_ml_kem_ss;
+	}
+#endif /* CONFIG_PQC */
+
+	res = wpa_supplicant_send_2_of_4(sm, wpa_sm_get_auth_addr(sm), key, ver,
+					 sm->snonce, kde, kde_len, ptk);
+#ifdef CONFIG_PQC
+	sm->pqc_rekey_msg1 = NULL;
+	sm->pqc_rekey_dhss = NULL;
+	sm->pqc_rekey_ml_kem_ss = NULL;
+#endif /* CONFIG_PQC */
+	if (res < 0)
 		goto failed;
 
 	os_free(kde_buf);
 	os_memcpy(sm->anonce, key->key_nonce, WPA_NONCE_LEN);
+#ifdef CONFIG_PQC
+	wpabuf_free(pqc_elem);
+	wpabuf_free(pqc_msg1);
+	wpabuf_clear_free(pqc_dhss);
+	wpabuf_clear_free(pqc_ml_kem_ss);
+#endif /* CONFIG_PQC */
 	return;
 
 failed:
 	os_free(kde_buf);
+#ifdef CONFIG_PQC
+	wpabuf_free(pqc_elem);
+	wpabuf_free(pqc_msg1);
+	wpabuf_clear_free(pqc_dhss);
+	wpabuf_clear_free(pqc_ml_kem_ss);
+#endif /* CONFIG_PQC */
 	wpa_sm_deauthenticate(sm, WLAN_REASON_UNSPECIFIED);
 }
 
@@ -4323,6 +4466,7 @@ int wpa_sm_rx_eapol(struct wpa_sm *sm, const u8 *src_addr,
 		} else {
 			/* 1/4 4-Way Handshake */
 			wpa_supplicant_process_1_of_4(sm, src_addr, key,
+						      tmp, data_len,
 						      ver, key_data,
 						      key_data_len,
 						      encrypted);
diff --git a/src/rsn_supp/wpa_i.h b/src/rsn_supp/wpa_i.h
index 9c81299cd83e..e53faf88bc5b 100644
--- a/src/rsn_supp/wpa_i.h
+++ b/src/rsn_supp/wpa_i.h
@@ -212,6 +212,12 @@ struct wpa_sm {
 	struct wpabuf *ft_msg1;
 #endif /* CONFIG_PQC */
 #endif /* CONFIG_ENC_ASSOC */
+#ifdef CONFIG_PQC
+	/* PQC PTK rekey: inputs for the PTK derivation once msg 2/4 is built */
+	const struct wpabuf *pqc_rekey_msg1;
+	const struct wpabuf *pqc_rekey_dhss;
+	const struct wpabuf *pqc_rekey_ml_kem_ss;
+#endif /* CONFIG_PQC */
 #ifdef CONFIG_PASN
 	/*
 	 * Currently, the WPA state machine stores the PMK-R1, PMK-R1-Name and
-- 
2.55.0




More information about the Hostap mailing list