From: John Brandt <brandtwjohn@gmail.com>
To: iwd@lists.linux.dev
Cc: John Brandt <brandtwjohn@gmail.com>
Subject: [PATCH v2 12/18] eapol: encrypt key data for AKM-defined ciphers
Date: Sun, 5 May 2024 17:30:35 -0700 [thread overview]
Message-ID: <20240506003518.320176-13-brandtwjohn@gmail.com> (raw)
In-Reply-To: <20240506003518.320176-1-brandtwjohn@gmail.com>
Support encrypting key data when the cipher is AKM-defined. This is
needed to support SAE in AP mode.
---
src/eapol.c | 51 ++++++++++++++++++++++++++++++++++++---------------
1 file changed, 36 insertions(+), 15 deletions(-)
diff --git a/src/eapol.c b/src/eapol.c
index a9b4f3ba..524a26c9 100644
--- a/src/eapol.c
+++ b/src/eapol.c
@@ -387,6 +387,23 @@ error:
return NULL;
}
+static int padded_aes_wrap(const uint8_t *kek, uint8_t *key_data,
+ size_t *key_data_len,
+ struct eapol_key *out_frame, size_t mic_len)
+{
+ if (*key_data_len < 16 || *key_data_len % 8)
+ key_data[(*key_data_len)++] = 0xdd;
+ while (*key_data_len < 16 || *key_data_len % 8)
+ key_data[(*key_data_len)++] = 0x00;
+
+ if (!aes_wrap(kek, key_data, *key_data_len,
+ EAPOL_KEY_DATA(out_frame, mic_len)))
+ return -ENOPROTOOPT;
+
+ *key_data_len += 8;
+ return 0;
+}
+
/*
* Pad and encrypt the plaintext Key Data contents in @key_data using
* the encryption scheme required by @out_frame->key_descriptor_version,
@@ -395,12 +412,12 @@ error:
* Note that for efficiency @key_data is being modified, including in
* case of failure, so it must be sufficiently larger than @key_data_len.
*/
-static int eapol_encrypt_key_data(const uint8_t *kek, uint8_t *key_data,
- size_t key_data_len,
+static int eapol_encrypt_key_data(enum ie_rsn_akm_suite akm, const uint8_t *kek,
+ uint8_t *key_data, size_t key_data_len,
struct eapol_key *out_frame, size_t mic_len)
{
uint8_t key[32];
- bool ret;
+ int ret;
switch (out_frame->key_descriptor_version) {
case EAPOL_KEY_DESCRIPTOR_VERSION_HMAC_MD5_ARC4:
@@ -426,18 +443,21 @@ static int eapol_encrypt_key_data(const uint8_t *kek, uint8_t *key_data,
break;
case EAPOL_KEY_DESCRIPTOR_VERSION_HMAC_SHA1_AES:
case EAPOL_KEY_DESCRIPTOR_VERSION_AES_128_CMAC_AES:
- if (key_data_len < 16 || key_data_len % 8)
- key_data[key_data_len++] = 0xdd;
- while (key_data_len < 16 || key_data_len % 8)
- key_data[key_data_len++] = 0x00;
-
- if (!aes_wrap(kek, key_data, key_data_len,
- EAPOL_KEY_DATA(out_frame, mic_len)))
- return -ENOPROTOOPT;
-
- key_data_len += 8;
+ ret = padded_aes_wrap(kek, key_data, &key_data_len, out_frame, mic_len);
+ if (ret < 0)
+ return ret;
break;
+ case EAPOL_KEY_DESCRIPTOR_VERSION_AKM_DEFINED:
+ switch (akm) {
+ case IE_RSN_AKM_SUITE_SAE_SHA256:
+ ret = padded_aes_wrap(kek, key_data, &key_data_len, out_frame, mic_len);
+ if (ret < 0)
+ return ret;
+ break;
+ default:
+ return -ENOTSUP;
+ }
}
l_put_be16(key_data_len, EAPOL_KEY_DATA(out_frame, mic_len) - 2);
@@ -1467,8 +1487,9 @@ static void eapol_send_ptk_3_of_4(struct eapol_sm *sm)
}
kek = handshake_state_get_kek(sm->handshake);
- key_data_len = eapol_encrypt_key_data(kek, key_data_buf,
- key_data_len, ek, sm->mic_len);
+ key_data_len = eapol_encrypt_key_data(sm->handshake->akm_suite, kek,
+ key_data_buf, key_data_len, ek,
+ sm->mic_len);
explicit_bzero(key_data_buf, sizeof(key_data_buf));
if (key_data_len < 0)
--
2.45.0
next prev parent reply other threads:[~2024-05-06 0:50 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-05-06 0:30 [PATCH v2 00/18] Basic WPA3 support in AP mode John Brandt
2024-05-06 0:30 ` [PATCH v2 01/18] ap: ability to advertise PSK and SAE John Brandt
2024-05-06 0:30 ` [PATCH v2 02/18] ap: accept PSK/SAE in auth depending on config John Brandt
2024-05-07 15:07 ` Denis Kenzior
2024-05-06 0:30 ` [PATCH v2 03/18] unit: fix SAE unit tests John Brandt
2024-05-07 15:51 ` Denis Kenzior
2024-05-06 0:30 ` [PATCH v2 04/18] sae: add function sae_set_group John Brandt
2024-05-07 14:53 ` Denis Kenzior
2024-05-06 0:30 ` [PATCH v2 05/18] sae: refactor and add function sae_calculate_keys John Brandt
2024-05-07 15:13 ` Denis Kenzior
2024-05-06 0:30 ` [PATCH v2 06/18] sae: make sae_process_commit callable in AP mode John Brandt
2024-05-06 0:30 ` [PATCH v2 07/18] sae: verify offered group " John Brandt
2024-05-07 15:11 ` Denis Kenzior
2024-05-06 0:30 ` [PATCH v2 08/18] sae: support reception of Confirm frame by AP John Brandt
2024-05-07 15:51 ` Denis Kenzior
2024-05-06 0:30 ` [PATCH v2 09/18] ap: add support to handle SAE authentication John Brandt
2024-05-07 15:44 ` Denis Kenzior
2024-05-06 0:30 ` [PATCH v2 10/18] ap: enable start of 4-way HS after SAE John Brandt
2024-05-06 0:30 ` [PATCH v2 11/18] eapol: support PTK derivation with SHA256 John Brandt
2024-05-07 15:52 ` Denis Kenzior
2024-05-06 0:30 ` John Brandt [this message]
2024-05-07 16:04 ` [PATCH v2 12/18] eapol: encrypt key data for AKM-defined ciphers Denis Kenzior
2024-05-06 0:30 ` [PATCH v2 13/18] unit: add unit test for SAE AP mode John Brandt
2024-05-06 0:30 ` [PATCH v2 14/18] ap: move toward requiring MFP when using SAE John Brandt
2024-05-07 16:12 ` Denis Kenzior
2024-05-06 0:30 ` [PATCH v2 15/18] handshake: add functions to save and set IGTK John Brandt
2024-05-07 16:20 ` Denis Kenzior
2024-05-06 0:30 ` [PATCH v2 16/18] eapol: include IGTK in 4-way handshake as AP John Brandt
2024-05-07 16:20 ` Denis Kenzior
2024-05-06 0:30 ` [PATCH v2 17/18] ap: generate IGTK on startup if MFP is enabled John Brandt
2024-05-06 0:30 ` [PATCH v2 18/18] ap: propogate IGTK and RSC to handshake John Brandt
2024-05-07 16:23 ` [PATCH v2 00/18] Basic WPA3 support in AP mode Denis Kenzior
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240506003518.320176-13-brandtwjohn@gmail.com \
--to=brandtwjohn@gmail.com \
--cc=iwd@lists.linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox