[RFC 06/30] common: Extend wpa_auth_802_1x_pmk_to_ptk()

Ilan Peer ilan.peer at intel.com
Wed Oct 21 06:43:24 PDT 2026


As a preparation to support SMD ID in the PMK to PTK
derivation, extend the function wpa_auth_802_1x_pmk_to_ptk()
with an additional argument 'smd_id' and had the logic
to handle it as part of the 'Z' data.

Signed-off-by: Ilan Peer <ilan.peer at intel.com>
---
 src/ap/ieee802_11.c     |  2 +-
 src/common/wpa_common.c | 24 ++++++++++++++++++++++--
 src/common/wpa_common.h |  3 ++-
 wpa_supplicant/sme.c    |  2 +-
 4 files changed, 26 insertions(+), 5 deletions(-)

diff --git a/src/ap/ieee802_11.c b/src/ap/ieee802_11.c
index 10b127760c4f..4dce610ee6f1 100644
--- a/src/ap/ieee802_11.c
+++ b/src/ap/ieee802_11.c
@@ -3575,7 +3575,7 @@ static int ieee80211_802_1x_derive_ptk(struct hostapd_data *hapd,
 		    sta->eap_auth_data.cipher,
 		    wpabuf_head_u8(sta->eap_auth_data.dhss),
 		    wpabuf_len(sta->eap_auth_data.dhss),
-		    &sta->eap_auth_data.ptk, kdk_len, 0)) {
+		    &sta->eap_auth_data.ptk, kdk_len, 0, NULL)) {
 		wpa_printf(MSG_INFO, "Failed to derive the PTK");
 		return -1;
 	}
diff --git a/src/common/wpa_common.c b/src/common/wpa_common.c
index d3edb0eeb588..efaf0cff8015 100644
--- a/src/common/wpa_common.c
+++ b/src/common/wpa_common.c
@@ -2160,11 +2160,31 @@ int wpa_auth_802_1x_pmk_to_ptk(const u8 *pmk, size_t pmk_len, const u8 *spa,
 			       const u8 *aa, const u8 *snonce, const u8 *anonce,
 			       int akmp, int cipher, const u8 *dhss,
 			       size_t dhss_len, struct wpa_ptk *ptk,
-			       size_t kdk_len, size_t smd_kdk_len)
+			       size_t kdk_len, size_t smd_kdk_len,
+			       const u8 *smd_id)
 {
+	u8 z_buf[WPA_MAX_Z_LEN];
+	const u8 *z = dhss;
+	size_t z_len = dhss_len;
+
+	if (smd_id) {
+		if (dhss_len > WPA_MAX_Z_LEN - ETH_ALEN) {
+			wpa_printf(MSG_DEBUG,
+				   "WPA: DHss too long (%zu) for SMD", dhss_len);
+			return -1;
+		}
+
+		if (dhss_len)
+			os_memcpy(z_buf, dhss, dhss_len);
+
+		os_memcpy(z_buf + dhss_len, smd_id, ETH_ALEN);
+		z = z_buf;
+		z_len = dhss_len + ETH_ALEN;
+	}
+
 	return wpa_pmk_to_ptk(pmk, pmk_len, "Pairwise key expansion",
 			      spa, aa, snonce, anonce, ptk, akmp,
-			      cipher, dhss, dhss_len, kdk_len,
+			      cipher, z, z_len, kdk_len,
 			      PASN_GROUP_NOT_SPECIFIED, smd_kdk_len);
 }
 
diff --git a/src/common/wpa_common.h b/src/common/wpa_common.h
index 2c301601174d..58201250b6ba 100644
--- a/src/common/wpa_common.h
+++ b/src/common/wpa_common.h
@@ -881,7 +881,8 @@ int wpa_auth_802_1x_pmk_to_ptk(const u8 *pmk, size_t pmk_len, const u8 *spa,
 			       const u8 *aa, const u8 *snonce, const u8 *anonce,
 			       int akmp, int cipher, const u8 *dhss,
 			       size_t dhss_len, struct wpa_ptk *ptk,
-			       size_t kdk_len, size_t smd_kdk_len);
+			       size_t kdk_len, size_t smd_kdk_len,
+			       const u8 *smd_id);
 void wpa_add_supported_groups(struct wpabuf *buf, const int *groups);
 
 /* Security Profile entry (IEEE P802.11bn/D2.0) */
diff --git a/wpa_supplicant/sme.c b/wpa_supplicant/sme.c
index c107947033ee..802ca8bc6ca2 100644
--- a/wpa_supplicant/sme.c
+++ b/wpa_supplicant/sme.c
@@ -4627,7 +4627,7 @@ static int sme_802_1x_derive_ptk_and_install(struct wpa_supplicant *wpa_s,
 				       key_mgmt, pairwise_cipher,
 				       wpabuf_head(auth_1x->dhss),
 				       wpabuf_len(auth_1x->dhss),
-				       &ptk, kdk_len, 0) < 0) {
+				       &ptk, kdk_len, 0, NULL) < 0) {
 		wpa_msg(wpa_s, MSG_INFO, "SME: PTK derivation failed");
 		forced_memzero(pmk, PMK_LEN_MAX);
 		return -1;
-- 
2.55.0




More information about the Hostap mailing list