]> git.ipfire.org Git - thirdparty/hostap.git/commitdiff
SAE: Maintain EC group context in struct sae_data
authorJouni Malinen <j@w1.fi>
Tue, 1 Jan 2013 09:29:53 +0000 (11:29 +0200)
committerJouni Malinen <j@w1.fi>
Sat, 12 Jan 2013 15:51:52 +0000 (17:51 +0200)
This can be used to share same EC group context through the SAE
exchange.

Signed-hostap: Jouni Malinen <j@w1.fi>

src/ap/sta_info.c
src/common/sae.c
src/common/sae.h
wpa_supplicant/sme.c

index 84973b6e1d809b79cfed138ef4a87012b4f341de..8ada121817a83814a4bf86d464da8d41de1d6c4e 100644 (file)
@@ -12,6 +12,7 @@
 #include "utils/eloop.h"
 #include "common/ieee802_11_defs.h"
 #include "common/wpa_ctrl.h"
+#include "common/sae.h"
 #include "radius/radius.h"
 #include "radius/radius_client.h"
 #include "drivers/driver.h"
@@ -241,6 +242,7 @@ void ap_free_sta(struct hostapd_data *hapd, struct sta_info *sta)
        os_free(sta->radius_cui);
 
 #ifdef CONFIG_SAE
+       sae_clear_data(sta->sae);
        os_free(sta->sae);
 #endif /* CONFIG_SAE */
 
index 8058167de8b1afb85740e1a1b5b1a87e1e31b9d8..951db9d943cedd1e7637ed1e57755bd5f9f01e7b 100644 (file)
@@ -31,6 +31,29 @@ static const u8 group19_order[] = {
 };
 
 
+int sae_set_group(struct sae_data *sae, int group)
+{
+       crypto_ec_deinit(sae->ec);
+       sae->ec = crypto_ec_init(group);
+       if (!sae->ec)
+               return -1;
+
+       sae->group = group;
+       sae->prime_len = crypto_ec_prime_len(sae->ec);
+
+       return 0;
+}
+
+
+void sae_clear_data(struct sae_data *sae)
+{
+       if (sae == NULL)
+               return;
+       crypto_ec_deinit(sae->ec);
+       os_memset(sae, 0, sizeof(*sae));
+}
+
+
 static int val_zero_or_one(const u8 *val, size_t len)
 {
        size_t i;
@@ -416,7 +439,7 @@ int sae_process_commit(struct sae_data *sae)
 void sae_write_commit(struct sae_data *sae, struct wpabuf *buf,
                      const struct wpabuf *token)
 {
-       wpabuf_put_le16(buf, 19); /* Finite Cyclic Group */
+       wpabuf_put_le16(buf, sae->group); /* Finite Cyclic Group */
        if (token)
                wpabuf_put_buf(buf, token);
        wpabuf_put_data(buf, sae->own_commit_scalar, 32);
@@ -429,6 +452,7 @@ u16 sae_parse_commit(struct sae_data *sae, const u8 *data, size_t len,
 {
        const u8 *pos = data, *end = data + len;
        size_t val_len;
+       u16 group;
 
        wpa_hexdump(MSG_DEBUG, "SAE: Commit fields", data, len);
        if (token)
@@ -439,9 +463,14 @@ u16 sae_parse_commit(struct sae_data *sae, const u8 *data, size_t len,
        /* Check Finite Cyclic Group */
        if (pos + 2 > end)
                return WLAN_STATUS_UNSPECIFIED_FAILURE;
-       if (WPA_GET_LE16(pos) != 19) {
+       group = WPA_GET_LE16(pos);
+       if (sae->state == SAE_COMMITTED && group != sae->group) {
+               wpa_printf(MSG_DEBUG, "SAE: Do not allow group to be changed");
+               return WLAN_STATUS_FINITE_CYCLIC_GROUP_NOT_SUPPORTED;
+       }
+       if (group != sae->group && sae_set_group(sae, group) < 0) {
                wpa_printf(MSG_DEBUG, "SAE: Unsupported Finite Cyclic Group %u",
-                          WPA_GET_LE16(pos));
+                          group);
                return WLAN_STATUS_FINITE_CYCLIC_GROUP_NOT_SUPPORTED;
        }
        pos += 2;
index 0559eb1894cb35f0089a7e1f90ea38b5d15054b5..37b9d541f226891ff793dfd0362fb199fa98a532 100644 (file)
@@ -23,8 +23,14 @@ struct sae_data {
        u8 peer_commit_element[2 * 32];
        u8 pwe[2 * 32];
        u8 sae_rand[32];
+       int group;
+       struct crypto_ec *ec;
+       int prime_len;
 };
 
+int sae_set_group(struct sae_data *sae, int group);
+void sae_clear_data(struct sae_data *sae);
+
 int sae_prepare_commit(const u8 *addr1, const u8 *addr2,
                       const u8 *password, size_t password_len,
                       struct sae_data *sae);
index 3aabe17c88f4abcac19315a7f3bd3c7c0c79cacb..112c80f787933e6d38afb618d01fe56c6484029f 100644 (file)
@@ -54,6 +54,9 @@ static struct wpabuf * sme_auth_build_sae_commit(struct wpa_supplicant *wpa_s,
                return NULL;
        }
 
+       if (sae_set_group(&wpa_s->sme.sae, 19) < 0)
+               return NULL;
+
        if (sae_prepare_commit(wpa_s->own_addr, bssid,
                               (u8 *) ssid->passphrase,
                               os_strlen(ssid->passphrase),
@@ -815,6 +818,7 @@ void sme_deinit(struct wpa_supplicant *wpa_s)
 #ifdef CONFIG_SAE
        wpabuf_free(wpa_s->sme.sae_token);
        wpa_s->sme.sae_token = NULL;
+       sae_clear_data(&wpa_s->sme.sae);
 #endif /* CONFIG_SAE */
 
        eloop_cancel_timeout(sme_assoc_timer, wpa_s, NULL);