From patchwork Fri Nov 9 13:41:02 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masashi Honma X-Patchwork-Id: 198079 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from maxx.maxx.shmoo.com (maxx.shmoo.com [205.134.188.171]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "maxx.shmoo.com", Issuer "CA Cert Signing Authority" (not verified)) by ozlabs.org (Postfix) with ESMTPS id E6FA92C00DA for ; Sat, 10 Nov 2012 01:08:10 +1100 (EST) Received: from localhost (localhost [127.0.0.1]) by maxx.maxx.shmoo.com (Postfix) with ESMTP id C7C759C13C; Fri, 9 Nov 2012 09:08:07 -0500 (EST) X-Virus-Scanned: amavisd-new at maxx.shmoo.com Received: from maxx.maxx.shmoo.com ([127.0.0.1]) by localhost (maxx.shmoo.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id ChQv001D+HOa; Fri, 9 Nov 2012 09:08:07 -0500 (EST) Received: from maxx.shmoo.com (localhost [127.0.0.1]) by maxx.maxx.shmoo.com (Postfix) with ESMTP id 87BAF9C165; Fri, 9 Nov 2012 09:08:03 -0500 (EST) X-Original-To: mailman-post+hostap@maxx.shmoo.com Delivered-To: mailman-post+hostap@maxx.shmoo.com Received: from localhost (localhost [127.0.0.1]) by maxx.maxx.shmoo.com (Postfix) with ESMTP id 70B959C165 for ; Fri, 9 Nov 2012 09:08:02 -0500 (EST) X-Virus-Scanned: amavisd-new at maxx.shmoo.com Received: from maxx.maxx.shmoo.com ([127.0.0.1]) by localhost (maxx.shmoo.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id MfU+dnQrPaDJ for ; Fri, 9 Nov 2012 09:07:57 -0500 (EST) Received: from mail-ee0-f44.google.com (mail-ee0-f44.google.com [74.125.83.44]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority" (not verified)) by maxx.maxx.shmoo.com (Postfix) with ESMTPS id 5B90E9C163 for ; Fri, 9 Nov 2012 09:07:57 -0500 (EST) Received: by mail-ee0-f44.google.com with SMTP id d4so2815101eek.17 for ; Fri, 09 Nov 2012 06:07:56 -0800 (PST) MIME-Version: 1.0 Received: by 10.14.220.71 with SMTP id n47mr37706520eep.26.1352468462963; Fri, 09 Nov 2012 05:41:02 -0800 (PST) Received: by 10.14.175.4 with HTTP; Fri, 9 Nov 2012 05:41:02 -0800 (PST) Date: Fri, 9 Nov 2012 22:41:02 +0900 Message-ID: Subject: [PATCH] P2P: Reduce redundant PSK generation for GO From: Masashi Honma To: hostap ML X-BeenThere: hostap@lists.shmoo.com X-Mailman-Version: 2.1.9 Precedence: list List-Id: HostAP Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: hostap-bounces@lists.shmoo.com Errors-To: hostap-bounces@lists.shmoo.com The PSK generation done by pbkdf2_sha1() is one of the most longest CPU time user according to our profiling from boot to GO started. So I have reduced some steps. I could boot a GO by this command sequence. ------------- add_net set_network 0 ssid '"DIRECT-XX"' set_network 0 psk '"123456789012345678901234567890123456789012345678901234567890123"' set_network 0 proto RSN set_network 0 key_mgmt WPA-PSK set_network 0 pairwise CCMP set_network 0 auth_alg OPEN set_network 0 mode 3 set_network 0 disabled 2 p2p_group_add persistent=0 freq=2412 ------------- By this sequence, pbkdf2_sha1() was called third times. The pbkdf2_sha1() calculates same value on each three time. So I made this patch to reduce calling of pbkdf2_sha1() from 3 to 1. Signed-hostap: Masashi Honma wpa_printf(MSG_DEBUG, "P2P: Invalid passphrase in persistent " Regards, Masashi Honma. diff --git a/src/p2p/p2p.h b/src/p2p/p2p.h index 4d40a9f..767ce85 100644 --- a/src/p2p/p2p.h +++ b/src/p2p/p2p.h @@ -88,6 +88,16 @@ struct p2p_go_neg_results { size_t ssid_len; /** + * psk - WPA pre-shared key (256 bits) (GO only) + */ + u8 psk[32]; + + /** + * psk_set - Whether PSK field is configured (GO only) + */ + int psk_set; + + /** * passphrase - WPA2-Personal passphrase for the group (GO only) */ char passphrase[64]; diff --git a/wpa_supplicant/ap.c b/wpa_supplicant/ap.c index 088f57d..e261ef9 100644 --- a/wpa_supplicant/ap.c +++ b/wpa_supplicant/ap.c @@ -174,15 +174,15 @@ static int wpa_supplicant_conf_ap(struct wpa_supplicant *wpa_s, bss->wpa = ssid->proto; bss->wpa_key_mgmt = ssid->key_mgmt; bss->wpa_pairwise = ssid->pairwise_cipher; - if (ssid->passphrase) { - bss->ssid.wpa_passphrase = os_strdup(ssid->passphrase); - } else if (ssid->psk_set) { + if (ssid->psk_set) { os_free(bss->ssid.wpa_psk); bss->ssid.wpa_psk = os_zalloc(sizeof(struct hostapd_wpa_psk)); if (bss->ssid.wpa_psk == NULL) return -1; os_memcpy(bss->ssid.wpa_psk->psk, ssid->psk, PMK_LEN); bss->ssid.wpa_psk->group = 1; + } else if (ssid->passphrase) { + bss->ssid.wpa_passphrase = os_strdup(ssid->passphrase); } else if (ssid->wep_key_len[0] || ssid->wep_key_len[1] || ssid->wep_key_len[2] || ssid->wep_key_len[3]) { struct hostapd_wep_keys *wep = &bss->ssid.wep; diff --git a/wpa_supplicant/p2p_supplicant.c b/wpa_supplicant/p2p_supplicant.c index cf90fbd..78b0d20 100644 --- a/wpa_supplicant/p2p_supplicant.c +++ b/wpa_supplicant/p2p_supplicant.c @@ -888,7 +888,11 @@ static void wpas_start_wps_go(struct wpa_supplicant *wpa_s, wpa_config_remove_network(wpa_s->conf, ssid->id); return; } - wpa_config_update_psk(ssid); + ssid->psk_set = params->psk_set; + if (ssid->psk_set) + os_memcpy(ssid->psk, params->psk, sizeof(ssid->psk)); + else + wpa_config_update_psk(ssid); ssid->ap_max_inactivity = wpa_s->parent->conf->p2p_go_max_inactivity; wpa_s->ap_configured_cb = p2p_go_configured; @@ -4117,6 +4121,9 @@ int wpas_p2p_group_add_persistent(struct wpa_supplicant *wpa_s, return -1; params.role_go = 1; + params.psk_set = ssid->psk_set; + if (params.psk_set) + os_memcpy(params.psk, ssid->psk, sizeof(params.psk)); if (ssid->passphrase == NULL || os_strlen(ssid->passphrase) >= sizeof(params.passphrase)) {