Skip to content
/ src Public

Commit 2bfc484

Browse files
committed
Fix KDF sha256 inputs to match the implementation in w1.fi hostap.
Cross-checked with the 802.11 spec, which mentions the use of an extra zero byte in case of PFK and mentions nothing of the sort in case of KDF. I was led here by hints left behind by github user pigworlds in OpenIntelWireless/itlwm#676 ok kevlo@ sthen@
1 parent 58967c0 commit 2bfc484

1 file changed

Lines changed: 12 additions & 6 deletions

File tree

sys/net80211/ieee80211_crypto.c

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $OpenBSD: ieee80211_crypto.c,v 1.79 2024/04/14 03:26:25 jsg Exp $ */
1+
/* $OpenBSD: ieee80211_crypto.c,v 1.80 2025/12/01 16:02:36 stsp Exp $ */
22

33
/*-
44
* Copyright (c) 2008 Damien Bergamini <damien.bergamini@free.fr>
@@ -386,8 +386,6 @@ ieee80211_derive_ptk(enum ieee80211_akm akm, const u_int8_t *pmk,
386386
const u_int8_t *aa, const u_int8_t *spa, const u_int8_t *anonce,
387387
const u_int8_t *snonce, struct ieee80211_ptk *ptk)
388388
{
389-
void (*kdf)(const u_int8_t *, size_t, const u_int8_t *, size_t,
390-
const u_int8_t *, size_t, u_int8_t *, size_t);
391389
u_int8_t buf[2 * IEEE80211_ADDR_LEN + 2 * EAPOL_KEY_NONCE_LEN];
392390
int ret;
393391

@@ -401,9 +399,17 @@ ieee80211_derive_ptk(enum ieee80211_akm akm, const u_int8_t *pmk,
401399
memcpy(&buf[12], ret ? anonce : snonce, EAPOL_KEY_NONCE_LEN);
402400
memcpy(&buf[44], ret ? snonce : anonce, EAPOL_KEY_NONCE_LEN);
403401

404-
kdf = ieee80211_is_sha256_akm(akm) ? ieee80211_kdf : ieee80211_prf;
405-
(*kdf)(pmk, IEEE80211_PMK_LEN, "Pairwise key expansion", 23,
406-
buf, sizeof buf, (u_int8_t *)ptk, sizeof(*ptk));
402+
if (ieee80211_is_sha256_akm(akm)) {
403+
ieee80211_kdf(pmk, IEEE80211_PMK_LEN, "Pairwise key expansion",
404+
22 /* KDF omits \0 */, buf, sizeof buf, (u_int8_t *)ptk,
405+
/* expected output size of 48 is mixed into hash */
406+
MIN(48, sizeof(*ptk)));
407+
CTASSERT(sizeof(struct ieee80211_ptk) >= 48);
408+
} else {
409+
ieee80211_prf(pmk, IEEE80211_PMK_LEN, "Pairwise key expansion",
410+
23 /* PRF uses \0 */, buf, sizeof buf, (u_int8_t *)ptk,
411+
sizeof(*ptk));
412+
}
407413
}
408414

409415
static void

0 commit comments

Comments
 (0)