WPS: Remove derivation of management keys
[libeap.git] / src / wps / wps_common.c
index 65b7d99..400d911 100644 (file)
@@ -15,7 +15,7 @@
 #include "includes.h"
 
 #include "common.h"
-#include "dh_groups.h"
+#include "dh_group5.h"
 #include "sha256.h"
 #include "aes_wrap.h"
 #include "crypto.h"
@@ -80,8 +80,9 @@ int wps_derive_keys(struct wps_data *wps)
                return -1;
        }
 
-       dh_shared = dh_derive_shared(pubkey, wps->dh_privkey,
-                                    dh_groups_get(WPS_DH_GROUP));
+       dh_shared = dh5_derive_shared(wps->dh_ctx, pubkey, wps->dh_privkey);
+       dh5_free(wps->dh_ctx);
+       wps->dh_ctx = NULL;
        dh_shared = wpabuf_zeropad(dh_shared, 192);
        if (dh_shared == NULL) {
                wpa_printf(MSG_DEBUG, "WPS: Failed to derive DH shared key");
@@ -128,56 +129,6 @@ int wps_derive_keys(struct wps_data *wps)
 }
 
 
-int wps_derive_mgmt_keys(struct wps_data *wps)
-{
-       u8 nonces[2 * WPS_NONCE_LEN];
-       u8 keys[WPS_MGMTAUTHKEY_LEN + WPS_MGMTENCKEY_LEN];
-       u8 hash[SHA256_MAC_LEN];
-       const u8 *addr[2];
-       size_t len[2];
-       const char *auth_label = "WFA-WLAN-Management-MgmtAuthKey";
-       const char *enc_label = "WFA-WLAN-Management-MgmtEncKey";
-
-       /* MgmtAuthKey || MgmtEncKey =
-        * kdf(EMSK, N1 || N2 || "WFA-WLAN-Management-Keys", 384) */
-       os_memcpy(nonces, wps->nonce_e, WPS_NONCE_LEN);
-       os_memcpy(nonces + WPS_NONCE_LEN, wps->nonce_r, WPS_NONCE_LEN);
-       wps_kdf(wps->emsk, nonces, sizeof(nonces), "WFA-WLAN-Management-Keys",
-               keys, sizeof(keys));
-       os_memcpy(wps->mgmt_auth_key, keys, WPS_MGMTAUTHKEY_LEN);
-       os_memcpy(wps->mgmt_enc_key, keys + WPS_MGMTAUTHKEY_LEN,
-                 WPS_MGMTENCKEY_LEN);
-
-       addr[0] = nonces;
-       len[0] = sizeof(nonces);
-
-       /* MgmtEncKeyID = first 128 bits of
-        * SHA-256(N1 || N2 || "WFA-WLAN-Management-MgmtAuthKey") */
-       addr[1] = (const u8 *) auth_label;
-       len[1] = os_strlen(auth_label);
-       sha256_vector(2, addr, len, hash);
-       os_memcpy(wps->mgmt_auth_key_id, hash, WPS_MGMT_KEY_ID_LEN);
-
-       /* MgmtEncKeyID = first 128 bits of
-        * SHA-256(N1 || N2 || "WFA-WLAN-Management-MgmtEncKey") */
-       addr[1] = (const u8 *) enc_label;
-       len[1] = os_strlen(enc_label);
-       sha256_vector(2, addr, len, hash);
-       os_memcpy(wps->mgmt_enc_key_id, hash, WPS_MGMT_KEY_ID_LEN);
-
-       wpa_hexdump_key(MSG_DEBUG, "WPS: MgmtAuthKey",
-                       wps->mgmt_auth_key, WPS_MGMTAUTHKEY_LEN);
-       wpa_hexdump(MSG_DEBUG, "WPS: MgmtAuthKeyID",
-                   wps->mgmt_auth_key_id, WPS_MGMT_KEY_ID_LEN);
-       wpa_hexdump_key(MSG_DEBUG, "WPS: MgmtEncKey",
-                       wps->mgmt_enc_key, WPS_MGMTENCKEY_LEN);
-       wpa_hexdump(MSG_DEBUG, "WPS: MgmtEncKeyID",
-                   wps->mgmt_enc_key_id, WPS_MGMT_KEY_ID_LEN);
-
-       return 0;
-}
-
-
 void wps_derive_psk(struct wps_data *wps, const u8 *dev_passwd,
                    size_t dev_passwd_len)
 {
@@ -337,6 +288,24 @@ void wps_pwd_auth_fail_event(struct wps_context *wps, int enrollee, int part)
 }
 
 
+void wps_pbc_overlap_event(struct wps_context *wps)
+{
+       if (wps->event_cb == NULL)
+               return;
+
+       wps->event_cb(wps->cb_ctx, WPS_EV_PBC_OVERLAP, NULL);
+}
+
+
+void wps_pbc_timeout_event(struct wps_context *wps)
+{
+       if (wps->event_cb == NULL)
+               return;
+
+       wps->event_cb(wps->cb_ctx, WPS_EV_PBC_TIMEOUT, NULL);
+}
+
+
 #ifdef CONFIG_WPS_OOB
 
 static struct wpabuf * wps_get_oob_cred(struct wps_context *wps)
@@ -496,25 +465,23 @@ int wps_process_oob(struct wps_context *wps, struct oob_device_data *oob_dev,
                        ret = -1;
        } else {
                data = oob_dev->read_func(oob_priv);
-               if (data == NULL) {
-                       oob_dev->deinit_func(oob_priv);
-                       return -1;
+               if (data == NULL)
+                       ret = -1;
+               else {
+                       if (oob_method == OOB_METHOD_CRED)
+                               ret = wps_parse_oob_cred(wps, data);
+                       else
+                               ret = wps_parse_oob_dev_pwd(wps, data);
                }
-
-               if (oob_method == OOB_METHOD_CRED)
-                       ret = wps_parse_oob_cred(wps, data);
-               else
-                       ret = wps_parse_oob_dev_pwd(wps, data);
        }
        wpabuf_free(data);
+       oob_dev->deinit_func(oob_priv);
+
        if (ret < 0) {
                wpa_printf(MSG_ERROR, "WPS: Failed to process OOB data");
-               oob_dev->deinit_func(oob_priv);
                return -1;
        }
 
-       oob_dev->deinit_func(oob_priv);
-
        return 0;
 }