From 0f6685bf450e287dade252a2f8b3bc4997cec8ff Mon Sep 17 00:00:00 2001 From: Andrew Zaborowski Date: Sat, 15 Apr 2017 13:58:44 +0200 Subject: [PATCH] crypto: Add crypto_derive_pmkid Calculates the PMKID for given PMK --- src/crypto.c | 17 +++++++++++++++++ src/crypto.h | 4 ++++ 2 files changed, 21 insertions(+) diff --git a/src/crypto.c b/src/crypto.c index 6b12adb1..53d5cb4d 100644 --- a/src/crypto.c +++ b/src/crypto.c @@ -625,3 +625,20 @@ exit: return r; } + +/* Defined in 802.11-2012, Section 11.6.1.3 Pairwise Key Hierarchy */ +bool crypto_derive_pmkid(const uint8_t *pmk, + const uint8_t *addr1, const uint8_t *addr2, + uint8_t *out_pmkid, bool use_sha256) +{ + uint8_t data[20]; + + memcpy(data + 0, "PMK Name", 8); + memcpy(data + 8, addr2, 6); + memcpy(data + 14, addr1, 6); + + if (use_sha256) + return hmac_sha256(pmk, 32, data, 20, out_pmkid, 16); + else + return hmac_sha1(pmk, 32, data, 20, out_pmkid, 16); +} diff --git a/src/crypto.h b/src/crypto.h index 472408bc..e1d17a5a 100644 --- a/src/crypto.h +++ b/src/crypto.h @@ -108,3 +108,7 @@ bool crypto_derive_ft_ptk(const uint8_t *pmk_r1, const uint8_t *pmk_r1_name, const uint8_t *nonce1, const uint8_t *nonce2, struct crypto_ptk *out_ptk, size_t ptk_len, uint8_t *out_ptk_name); + +bool crypto_derive_pmkid(const uint8_t *pmk, + const uint8_t *addr1, const uint8_t *addr2, + uint8_t *out_pmkid, bool use_sha256);