]> git.ipfire.org Git - thirdparty/hostap.git/commitdiff
PASN: Store selected hash algorithm when deriving PTK from PMK
authorJouni Malinen <jouni.malinen@oss.qualcomm.com>
Wed, 17 Dec 2025 19:28:01 +0000 (21:28 +0200)
committerJouni Malinen <j@w1.fi>
Thu, 18 Dec 2025 10:08:24 +0000 (12:08 +0200)
This makes it more convenient to be able to select the appropriate hash
algorithm for operations using PTK.

Signed-off-by: Jouni Malinen <jouni.malinen@oss.qualcomm.com>
src/ap/ieee802_11.c
src/common/common_module_tests.c
src/common/wpa_common.c
src/common/wpa_common.h
src/pasn/pasn_common.h
src/pasn/pasn_initiator.c
src/pasn/pasn_responder.c

index 940e37335369f61de7b96ee80797af56f15fdd03..515ff832d90c3632f95b88cfaaa829be7fe3cc7f 100644 (file)
@@ -2815,7 +2815,7 @@ static void pasn_fils_auth_resp(struct hostapd_data *hapd,
                              wpabuf_len(pasn->secret),
                              pasn_get_ptk(sta->pasn), pasn_get_akmp(sta->pasn),
                              pasn_get_cipher(sta->pasn), sta->pasn->kdk_len,
-                             sta->pasn->kek_len);
+                             sta->pasn->kek_len, &sta->pasn->hash_alg);
        if (ret) {
                wpa_printf(MSG_DEBUG, "PASN: FILS: Failed to derive PTK");
                goto fail;
index edbdbfa1a119b4b36f682dc27ee08206ceb06e15..6b528eabdcdb487ba2b85ee2bfd1871f1ea0639d 100644 (file)
@@ -649,12 +649,13 @@ static int pasn_test_pasn_auth(void)
        };
        struct wpa_ptk ptk;
        int ret;
+       enum rsn_hash_alg hash_alg;
 
        ret = pasn_pmk_to_ptk(pmk, sizeof(pmk),
                              spa_addr, bssid,
                              dhss, sizeof(dhss),
                              &ptk, WPA_KEY_MGMT_PASN, WPA_CIPHER_CCMP,
-                             WPA_KDK_MAX_LEN, 0);
+                             WPA_KDK_MAX_LEN, 0, &hash_alg);
 
        if (ret)
                return ret;
index ee8084c4210e50bd0f397b5aaffffa63953001c4..d62512b2304bd5cf617efb8ba244506ea4780606 100644 (file)
@@ -1546,13 +1546,14 @@ bool pasn_use_sha384(int akmp, int cipher)
  * @cipher: Negotiated pairwise cipher
  * @kdk_len: the length in octets that should be derived for HTLK. Can be zero.
  * @kek_len: The length in octets that should be derived for KEK. Can be zero.
+ * @alg: Output variable for indicating the selected hash algorithm
  * Returns: 0 on success, -1 on failure
  */
 int pasn_pmk_to_ptk(const u8 *pmk, size_t pmk_len,
                    const u8 *spa, const u8 *bssid,
                    const u8 *dhss, size_t dhss_len,
                    struct wpa_ptk *ptk, int akmp, int cipher,
-                   size_t kdk_len, size_t kek_len)
+                   size_t kdk_len, size_t kek_len, enum rsn_hash_alg *alg)
 {
        u8 tmp[WPA_KCK_MAX_LEN + WPA_KEK_MAX_LEN + WPA_TK_MAX_LEN +
               WPA_KDK_MAX_LEN];
@@ -1606,6 +1607,9 @@ int pasn_pmk_to_ptk(const u8 *pmk, size_t pmk_len,
        if (ptk_len > sizeof(tmp))
                goto err;
 
+       *alg = pasn_use_sha384(akmp, cipher) ? RSN_HASH_SHA384 :
+               RSN_HASH_SHA256;
+
        if (pasn_use_sha384(akmp, cipher)) {
                wpa_printf(MSG_DEBUG, "PASN: PTK derivation using SHA384");
 
index 0296bd36ee5d4044b7a368a288239e1bbd6303c3..dbcaef93ee870b35effaa4f0a03f10fe6558d9af 100644 (file)
 
 #define OWE_DH_GROUP 19
 
+enum rsn_hash_alg {
+       RSN_HASH_SHA256,
+       RSN_HASH_SHA384,
+       RSN_HASH_SHA512,
+};
+
 #ifdef CONFIG_NO_TKIP
 #define WPA_ALLOWED_PAIRWISE_CIPHERS \
 (WPA_CIPHER_CCMP | WPA_CIPHER_GCMP | WPA_CIPHER_NONE | \
@@ -774,7 +780,7 @@ int pasn_pmk_to_ptk(const u8 *pmk, size_t pmk_len,
                    const u8 *spa, const u8 *bssid,
                    const u8 *dhss, size_t dhss_len,
                    struct wpa_ptk *ptk, int akmp, int cipher,
-                   size_t kdk_len, size_t kek_len);
+                   size_t kdk_len, size_t kek_len, enum rsn_hash_alg *alg);
 
 u8 pasn_mic_len(int akmp, int cipher);
 
index ef28a0525a39d0975474e773e08dadb0fa098b8d..f6520630e6dd763c4d1c5503d44e05cfcb8733a0 100644 (file)
@@ -84,6 +84,7 @@ struct pasn_data {
        size_t pmk_len;
        u8 pmk[PMK_LEN_MAX];
        bool using_pmksa;
+       enum rsn_hash_alg hash_alg;
 
        u8 hash[SHA384_MAC_LEN];
 
index 2de1a731493f2ff9a648479812d9aebf4da26877..d16ad62cd943d2a06210c24405530b783478ec3c 100644 (file)
@@ -1316,7 +1316,7 @@ int wpa_pasn_auth_rx(struct pasn_data *pasn, const u8 *data, size_t len,
                              pasn->own_addr, pasn->peer_addr,
                              wpabuf_head(secret), wpabuf_len(secret),
                              &pasn->ptk, pasn->akmp, pasn->cipher,
-                             pasn->kdk_len, pasn->kek_len);
+                             pasn->kdk_len, pasn->kek_len, &pasn->hash_alg);
        if (ret) {
                wpa_printf(MSG_DEBUG, "PASN: Failed to derive PTK");
                goto fail;
index 17960e922b5a25f870ac559064f3a025b144c638..aafbedf776520bb8af7ba5eb249fc91086dbd44e 100644 (file)
@@ -412,7 +412,8 @@ pasn_derive_keys(struct pasn_data *pasn,
        ret = pasn_pmk_to_ptk(pmk, pmk_len, peer_addr, own_addr,
                              wpabuf_head(secret), wpabuf_len(secret),
                              &pasn->ptk, pasn->akmp,
-                             pasn->cipher, pasn->kdk_len, pasn->kek_len);
+                             pasn->cipher, pasn->kdk_len, pasn->kek_len,
+                             &pasn->hash_alg);
        if (ret) {
                wpa_printf(MSG_DEBUG, "PASN: Failed to derive PTK");
                return -1;