[PATCH 09/10] PASN: SMD: Extend PTK to include SMD_KDK_bits for Per-AP MLD PTK mode
Pooventhiran G
pooventhiran.g at oss.qualcomm.com
Sat Nov 21 12:34:18 PST 2026
From: Sai Pratyusha Magam <sai.magam at oss.qualcomm.com>
Per IEEE802.11bn/D2.1, Section 12.7.1.3 (Pairwise key hierarchy), when a
PTK is derived at the time of (re)association to an SMD-ME using the
Per-AP MLD PTK mode, an SMD_KDK is also derived and the value of
SMD_KDK_bits is equal to PMK_bits.
Extend the PTK derivation APIs to include SMD_KDK_bits for Per-AP MLD
SMD PTK Mode.
Signed-off-by: Sai Pratyusha Magam <sai.magam at oss.qualcomm.com>
Signed-off-by: Pooventhiran G <pooventhiran.g at oss.qualcomm.com>
---
src/ap/ieee802_11.c | 7 ++--
src/ap/wpa_auth.c | 7 ++--
src/common/common_module_tests.c | 5 +--
src/common/wpa_common.c | 59 +++++++++++++++++++++++++++-----
src/common/wpa_common.h | 8 +++--
src/pasn/pasn_common.h | 1 +
src/pasn/pasn_initiator.c | 2 +-
src/pasn/pasn_responder.c | 2 +-
src/rsn_supp/wpa.c | 2 +-
wlantest/rx_eapol.c | 2 +-
10 files changed, 75 insertions(+), 20 deletions(-)
diff --git a/src/ap/ieee802_11.c b/src/ap/ieee802_11.c
index da04cd713678..58e302788241 100644
--- a/src/ap/ieee802_11.c
+++ b/src/ap/ieee802_11.c
@@ -4801,7 +4801,7 @@ static void pasn_fils_auth_resp(struct hostapd_data *hapd,
pasn_get_cipher(sta->pasn), sta->pasn->kdk_len,
sta->pasn->kek_len, &sta->pasn->hash_alg,
pasn->auth_alg == WLAN_AUTH_EPPKE,
- smd_identifier);
+ smd_identifier, false);
if (ret) {
wpa_printf(MSG_DEBUG, "PASN: FILS: Failed to derive PTK");
goto fail;
@@ -5451,8 +5451,11 @@ static void handle_auth_pasn(struct hostapd_data *hapd, struct sta_info *sta,
sta->pasn->sec_prof_used = true;
#ifdef CONFIG_IEEE80211BN
- if (ap_sta_is_smd(hapd, sta))
+ if (ap_sta_is_smd(hapd, sta)) {
sta->pasn->smd_identifier = hapd->conf->smd.identifier;
+ sta->pasn->include_smd_kdk =
+ hapd->conf->smd.capab.ptk_mode;
+ }
#endif /* CONFIG_IEEE80211BN */
hapd_pasn_update_params(hapd, sta, mgmt, len);
diff --git a/src/ap/wpa_auth.c b/src/ap/wpa_auth.c
index ee892c331499..ebca1a1c0964 100644
--- a/src/ap/wpa_auth.c
+++ b/src/ap/wpa_auth.c
@@ -3106,6 +3106,7 @@ static int wpa_derive_ptk(struct wpa_state_machine *sm, const u8 *snonce,
const u8 *z = NULL;
size_t z_len = 0, kdk_len;
const u8 *smd_identifier = NULL;
+ bool include_smd_kdk = false;
int akmp;
int ret;
@@ -3162,8 +3163,10 @@ static int wpa_derive_ptk(struct wpa_state_machine *sm, const u8 *snonce,
#endif /* CONFIG_DPP2 */
#ifdef CONFIG_IEEE80211BN
- if (sm->smd)
+ if (sm->smd) {
smd_identifier = sm->wpa_auth->conf.smd_identifier;
+ include_smd_kdk = sm->wpa_auth->conf.smd_ptk_mode;
+ }
#endif /* CONFIG_IEEE80211BN */
akmp = sm->wpa_key_mgmt;
@@ -3173,7 +3176,7 @@ static int wpa_derive_ptk(struct wpa_state_machine *sm, const u8 *snonce,
wpa_auth_get_aa(sm), wpa_auth_get_spa(sm),
sm->ANonce, snonce, ptk, akmp,
sm->pairwise, z, z_len, kdk_len,
- sm->pasn_group, smd_identifier);
+ sm->pasn_group, smd_identifier, include_smd_kdk);
if (ret) {
wpa_printf(MSG_DEBUG,
"WPA: PTK derivation failed");
diff --git a/src/common/common_module_tests.c b/src/common/common_module_tests.c
index 9be034a99295..351069251ff5 100644
--- a/src/common/common_module_tests.c
+++ b/src/common/common_module_tests.c
@@ -656,7 +656,8 @@ static int pasn_test_pasn_auth(void)
spa_addr, bssid,
dhss, sizeof(dhss),
&ptk, WPA_KEY_MGMT_PASN, WPA_CIPHER_CCMP,
- WPA_KDK_MAX_LEN, 0, &hash_alg, false, NULL);
+ WPA_KDK_MAX_LEN, 0, &hash_alg, false, NULL,
+ false);
if (ret)
return ret;
@@ -736,7 +737,7 @@ static int pasn_test_no_pasn_auth(void)
"Pairwise key expansion",
spa, aa, snonce, anonce,
&ptk, WPA_KEY_MGMT_SAE, WPA_CIPHER_CCMP,
- NULL, 0, WPA_KDK_MAX_LEN, 19, NULL);
+ NULL, 0, WPA_KDK_MAX_LEN, 19, NULL, false);
if (ret)
return ret;
diff --git a/src/common/wpa_common.c b/src/common/wpa_common.c
index 3c654d5a6d47..ec5de46b4879 100644
--- a/src/common/wpa_common.c
+++ b/src/common/wpa_common.c
@@ -597,6 +597,8 @@ int wpa_eapol_key_mic(const u8 *key, size_t key_len, int akmp,
* @z_len: Length of additional context data
* @kdk_len: The length in octets that should be derived for KDK
* @smd_identifier: SMD Identifier
+ * @include_smd_kdk: Indicates if the PTK derivation will include SMD_KDK_bits
+ * %true for Initial 802.11 association with the AP MLD, %false otherwise.
* Returns: 0 on success, -1 on failure
*
* IEEE Std 802.11i-2004 - 8.5.1.2 Pairwise key hierarchy
@@ -615,13 +617,13 @@ int wpa_pmk_to_ptk(const u8 *pmk, size_t pmk_len, const char *label,
const u8 *nonce1, const u8 *nonce2,
struct wpa_ptk *ptk, int akmp, int cipher,
const u8 *z, size_t z_len, size_t kdk_len, u16 pasn_group,
- const u8 *smd_identifier)
+ const u8 *smd_identifier, bool include_smd_kdk)
{
#define MAX_Z_LEN 66 /* with NIST P-521 */
u8 data[2 * ETH_ALEN + 2 * WPA_NONCE_LEN + MAX_Z_LEN + ETH_ALEN];
size_t data_len = 2 * ETH_ALEN + 2 * WPA_NONCE_LEN;
u8 tmp[WPA_KCK_MAX_LEN + WPA_KEK_MAX_LEN + WPA_TK_MAX_LEN +
- WPA_KDK_MAX_LEN];
+ WPA_KDK_MAX_LEN + WPA_SMD_KDK_MAX_LEN];
size_t ptk_len;
#ifdef CONFIG_OWE
int owe_ptk_workaround = 0;
@@ -689,7 +691,23 @@ int wpa_pmk_to_ptk(const u8 *pmk, size_t pmk_len, const char *label,
cipher);
return -1;
}
- ptk_len = ptk->kck_len + ptk->kek_len + ptk->tk_len + ptk->kdk_len;
+ ptk->smd_kdk_len = 0;
+#ifdef CONFIG_IEEE80211BN
+ if (include_smd_kdk) {
+ if (pmk_len > WPA_SMD_KDK_MAX_LEN) {
+ wpa_printf(MSG_ERROR,
+ "WPA: PMK len=%zu exceeds WPA_SMD_KDK_MAX_LEN",
+ pmk_len);
+ return -1;
+ }
+ ptk->smd_kdk_len = pmk_len;
+ wpa_printf(MSG_DEBUG,
+ "WPA: SMD_KDK len=%zu", ptk->smd_kdk_len);
+ }
+#endif /* CONFIG_IEEE80211BN */
+
+ ptk_len = ptk->kck_len + ptk->kek_len + ptk->tk_len + ptk->kdk_len +
+ ptk->smd_kdk_len;
if (wpa_key_mgmt_sha384(akmp)) {
#ifdef CONFIG_SHA384
@@ -826,6 +844,14 @@ int wpa_pmk_to_ptk(const u8 *pmk, size_t pmk_len, const char *label,
wpa_hexdump_key(MSG_DEBUG, "WPA: KDK", ptk->kdk, ptk->kdk_len);
}
+#ifdef CONFIG_IEEE80211BN
+ if (ptk->smd_kdk_len) {
+ os_memcpy(ptk->smd_kdk, tmp + ptk->kck_len + ptk->kek_len +
+ ptk->tk_len + ptk->kdk_len, ptk->smd_kdk_len);
+ wpa_hexdump_key(MSG_DEBUG, "WPA: SMD_KDK", ptk->smd_kdk,
+ ptk->smd_kdk_len);
+ }
+#endif /* CONFIG_IEEE80211BN */
ptk->kek2_len = 0;
ptk->kck2_len = 0;
@@ -1747,6 +1773,8 @@ static enum rsn_hash_alg pasn_select_hash_alg(int akmp, int cipher,
* @alg: Output variable for indicating the selected hash algorithm
* @is_eppke: EPPKE authentication
* @smd_identifier: SMD Identifier
+ * @include_smd_kdk: Indicates if the PTK derivation will include SMD_KDK_bits
+ * %true for Initial 802.11 association with the AP MLD, %false otherwise.
* Returns: 0 on success, -1 on failure
*/
int pasn_pmk_to_ptk(const u8 *pmk, size_t pmk_len,
@@ -1754,10 +1782,11 @@ int pasn_pmk_to_ptk(const u8 *pmk, size_t pmk_len,
const u8 *dhss, size_t dhss_len,
struct wpa_ptk *ptk, int akmp, int cipher,
size_t kdk_len, size_t kek_len, enum rsn_hash_alg *alg,
- bool is_eppke, const u8 *smd_identifier)
+ bool is_eppke, const u8 *smd_identifier,
+ bool include_smd_kdk)
{
u8 tmp[WPA_KCK_MAX_LEN + WPA_KEK_MAX_LEN + WPA_TK_MAX_LEN +
- WPA_KDK_MAX_LEN];
+ WPA_KDK_MAX_LEN + WPA_SMD_KDK_MAX_LEN];
const u8 *pos;
u8 *data;
size_t data_len, ptk_len;
@@ -1815,7 +1844,11 @@ int pasn_pmk_to_ptk(const u8 *pmk, size_t pmk_len,
ptk->kek_len = kek_len;
ptk->kek2_len = 0;
ptk->kck2_len = 0;
-
+ ptk->smd_kdk_len = 0;
+#ifdef CONFIG_IEEE80211BN
+ if (include_smd_kdk)
+ ptk->smd_kdk_len = pmk_len;
+#endif /* CONFIG_IEEE80211BN */
if (ptk->tk_len == 0) {
wpa_printf(MSG_ERROR,
"PASN: Unsupported cipher (0x%x) used in PTK derivation",
@@ -1823,7 +1856,8 @@ int pasn_pmk_to_ptk(const u8 *pmk, size_t pmk_len,
goto err;
}
- ptk_len = ptk->kck_len + ptk->tk_len + ptk->kdk_len + ptk->kek_len;
+ ptk_len = ptk->kck_len + ptk->tk_len + ptk->kdk_len + ptk->kek_len +
+ ptk->smd_kdk_len;
if (ptk_len > sizeof(tmp))
goto err;
@@ -1888,8 +1922,17 @@ int pasn_pmk_to_ptk(const u8 *pmk, size_t pmk_len,
os_memcpy(ptk->kdk, pos, ptk->kdk_len);
wpa_hexdump_key(MSG_DEBUG, "PASN: KDK:",
ptk->kdk, ptk->kdk_len);
+ pos += ptk->kdk_len;
}
+#ifdef CONFIG_IEEE80211BN
+ if (ptk->smd_kdk_len) {
+ os_memcpy(ptk->smd_kdk, pos, ptk->smd_kdk_len);
+ wpa_hexdump_key(MSG_DEBUG, "PASN: SMD_KDK:",
+ ptk->smd_kdk, ptk->smd_kdk_len);
+ }
+#endif /* CONFIG_IEEE80211BN */
+
ptk->ptk_len = ptk_len;
ptk->hash_alg = *alg;
forced_memzero(tmp, sizeof(tmp));
@@ -2169,7 +2212,7 @@ int wpa_auth_802_1x_pmk_to_ptk(const u8 *pmk, size_t pmk_len, const u8 *spa,
return wpa_pmk_to_ptk(pmk, pmk_len, "Pairwise key expansion",
spa, aa, snonce, anonce, ptk, akmp,
cipher, dhss, dhss_len, kdk_len,
- PASN_GROUP_NOT_SPECIFIED, NULL);
+ PASN_GROUP_NOT_SPECIFIED, NULL, false);
}
diff --git a/src/common/wpa_common.h b/src/common/wpa_common.h
index 920faa807dad..02138db90ac2 100644
--- a/src/common/wpa_common.h
+++ b/src/common/wpa_common.h
@@ -267,6 +267,7 @@ struct wpa_eapol_key {
#define FILS_FT_MAX_LEN 48
#define WPA_PASN_KCK_LEN 32
#define WPA_LTF_KEYSEED_MAX_LEN 48
+#define WPA_SMD_KDK_MAX_LEN PMK_LEN_MAX
/**
* struct wpa_ptk - WPA Pairwise Transient Key
@@ -280,6 +281,7 @@ struct wpa_ptk {
u8 kek2[WPA_KEK_MAX_LEN]; /* FT reassoc Key Encryption Key (KEK2) */
u8 kdk[WPA_KDK_MAX_LEN]; /* Key Derivation Key */
u8 ltf_keyseed[WPA_LTF_KEYSEED_MAX_LEN]; /* LTF Key seed */
+ u8 smd_kdk[WPA_SMD_KDK_MAX_LEN]; /* SMD Key Derivation Key */
size_t kck_len;
size_t kek_len;
size_t tk_len;
@@ -288,6 +290,7 @@ struct wpa_ptk {
size_t kdk_len;
size_t ptk_len;
size_t ltf_keyseed_len;
+ size_t smd_kdk_len;
enum rsn_hash_alg hash_alg;
int installed; /* 1 if key has already been installed to driver */
bool installed_rx; /* whether TK has been installed as the next TK
@@ -496,7 +499,7 @@ int wpa_pmk_to_ptk(const u8 *pmk, size_t pmk_len, const char *label,
const u8 *nonce1, const u8 *nonce2,
struct wpa_ptk *ptk, int akmp, int cipher,
const u8 *z, size_t z_len, size_t kdk_len, u16 pasn_group,
- const u8 *smd_identifier);
+ const u8 *smd_identifier, bool include_smd_kdk);
int fils_rmsk_to_pmk(int akmp, const u8 *rmsk, size_t rmsk_len,
const u8 *snonce, const u8 *anonce, const u8 *dh_ss,
size_t dh_ss_len, u8 *pmk, size_t *pmk_len);
@@ -816,7 +819,8 @@ int pasn_pmk_to_ptk(const u8 *pmk, size_t pmk_len,
const u8 *dhss, size_t dhss_len,
struct wpa_ptk *ptk, int akmp, int cipher,
size_t kdk_len, size_t kek_len, enum rsn_hash_alg *alg,
- bool is_eppke, const u8 *smd_identifier);
+ bool is_eppke, const u8 *smd_identifier,
+ bool include_smd_kdk);
size_t pasn_mic_len(enum rsn_hash_alg alg);
diff --git a/src/pasn/pasn_common.h b/src/pasn/pasn_common.h
index 27fd053a3a5e..f2843e11bebf 100644
--- a/src/pasn/pasn_common.h
+++ b/src/pasn/pasn_common.h
@@ -190,6 +190,7 @@ struct pasn_data {
bool sec_prof_used;
u8 *smd_identifier;
+ bool include_smd_kdk;
/**
* send_mgmt - Function handler to transmit a Management frame
diff --git a/src/pasn/pasn_initiator.c b/src/pasn/pasn_initiator.c
index 8b838759e0c5..a4f51b902b3b 100644
--- a/src/pasn/pasn_initiator.c
+++ b/src/pasn/pasn_initiator.c
@@ -1564,7 +1564,7 @@ int wpas_parse_pasn_frame(struct pasn_data *pasn, u16 auth_type,
&pasn->ptk, pasn->akmp, pasn->cipher,
pasn->kdk_len, pasn->kek_len, &pasn->hash_alg,
pasn->auth_alg == WLAN_AUTH_EPPKE,
- NULL);
+ NULL, false);
if (ret) {
wpa_printf(MSG_DEBUG, "PASN: Failed to derive PTK");
goto fail;
diff --git a/src/pasn/pasn_responder.c b/src/pasn/pasn_responder.c
index aecedbb86a80..87b6033b29f7 100644
--- a/src/pasn/pasn_responder.c
+++ b/src/pasn/pasn_responder.c
@@ -502,7 +502,7 @@ pasn_derive_keys(struct pasn_data *pasn,
pasn->cipher, pasn->kdk_len, pasn->kek_len,
&pasn->hash_alg,
pasn->auth_alg == WLAN_AUTH_EPPKE,
- pasn->smd_identifier);
+ pasn->smd_identifier, pasn->include_smd_kdk);
if (ret) {
wpa_printf(MSG_DEBUG, "PASN: Failed to derive PTK");
return -1;
diff --git a/src/rsn_supp/wpa.c b/src/rsn_supp/wpa.c
index 795535d0c60a..8f8bd08f7e1d 100644
--- a/src/rsn_supp/wpa.c
+++ b/src/rsn_supp/wpa.c
@@ -792,7 +792,7 @@ static int wpa_derive_ptk(struct wpa_sm *sm, const unsigned char *src_addr,
sm->own_addr, wpa_sm_get_auth_addr(sm), sm->snonce,
key->key_nonce, ptk, akmp,
sm->pairwise_cipher, z, z_len,
- kdk_len, sm->pasn_group, NULL);
+ kdk_len, sm->pasn_group, NULL, false);
if (ret) {
wpa_printf(MSG_ERROR, "WPA: PTK derivation failed");
return ret;
diff --git a/wlantest/rx_eapol.c b/wlantest/rx_eapol.c
index b9a966eb1414..78809fe9c47f 100644
--- a/wlantest/rx_eapol.c
+++ b/wlantest/rx_eapol.c
@@ -250,7 +250,7 @@ static int try_pmk(struct wlantest *wt, struct wlantest_bss *bss,
aa, sa, sta->anonce,
sta->snonce, &ptk, sta->key_mgmt,
sta->pairwise_cipher, NULL, 0, kdk_len,
- PASN_GROUP_NOT_SPECIFIED, NULL) < 0 ||
+ PASN_GROUP_NOT_SPECIFIED, NULL, false) < 0 ||
check_mic(sta, ptk.kck, ptk.kck_len, ver, data, len) < 0) {
return -1;
}
--
2.34.1
More information about the Hostap
mailing list