Received: by 10.223.185.116 with SMTP id b49csp2650416wrg; Sun, 18 Feb 2018 03:38:34 -0800 (PST) X-Google-Smtp-Source: AH8x225vIvKL7BRHwoAjQtb0wM9ygu+kV7KSnC/YMfBAKXwb18lIJ/lzAGFhDBr1vB8HIMA7k+4R X-Received: by 2002:a17:902:66e5:: with SMTP id e92-v6mr283262plk.111.1518953914071; Sun, 18 Feb 2018 03:38:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518953914; cv=none; d=google.com; s=arc-20160816; b=gPGBEW+Ug55NmUwmqG0U87+wVxEXZnFjNMciy7zZoRysA5qJUgyM7zjZ5g6MGERBUN fK5chM9SC7t7i/dyel7FKts6q/iXBff/qnX5GEgoYSIx8rXUyfa6g4SORNfBAhuh27OD kbCEi+J8nPlsgHhhlMXNk0+GSSnzICDOkfbRtlxXnfk2a64kEHaRIc5Y1VrO/pmUHcoy U04/dcucv0+JRweaYRLK5qj4Hv7+iXzemJA9IN+t3P35NcBBRUzH3GAj3qpGgqkjIvfu lJ33+CxN+CiS9hSRWNiCQMpUsfNY938nglO3Vra4pJwyixNgAKDqn6Vl6angpK3Qop5x erZQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=C1wSa6Edi9lzeEZRMqeJGlD2jSBbF4ofKWoOaKD7CQE=; b=HhQNo/C+OdOSiQZ1kQfU3zoszlF4o4y4d7DDdmrkx2Vue+MpGb+TNVqnjC6DTUvyWh Ui+kAvYlUVpf2vD6NgYA8lqR3kUskc/Okhit8zqsgr4sp6mLVWSCCSpD4H7z1Zh/Zfil rIE2W0qQABuCnl8A72PQ0VzUbGutraF8Fq9EGW63emB8kGG/wbGFeQ7s89mxuJFHjMXd iIuwSusxp0fuG9IfZJJO4pZ28NvSWPa/4N5MAg4CJmHNw+3uMN/Jh4Q4Nm7Ge+gpo+y6 hA8Dmrht+iwDSD80JH6lhH0Sa2JdXKa6GJx70Aj5N/5I7CKf2ue7sjcBfN5BhHMpBHL4 FZmw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=EG0JHeXX; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x20si4283819pfi.200.2018.02.18.03.38.13; Sun, 18 Feb 2018 03:38:34 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=EG0JHeXX; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751365AbeBRLhc (ORCPT + 99 others); Sun, 18 Feb 2018 06:37:32 -0500 Received: from mail-lf0-f65.google.com ([209.85.215.65]:39137 "EHLO mail-lf0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751025AbeBRLha (ORCPT ); Sun, 18 Feb 2018 06:37:30 -0500 Received: by mail-lf0-f65.google.com with SMTP id h78so9523375lfg.6 for ; Sun, 18 Feb 2018 03:37:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=C1wSa6Edi9lzeEZRMqeJGlD2jSBbF4ofKWoOaKD7CQE=; b=EG0JHeXXHZApb3vbowNhBV9f3aTocp6629COaJLFOXqWXiUy0zHI51HKNlJaa3n8JW y1vvHNI8OOZgvLC+FZo86qbKmOa41yRUs1R4qjDcAuy2EARog/mkax5rkDwvGGSyxDRD QAXHZqITn7zAMbE8z0KH+inAnXEuGlYO8eXbJyOuBdlUrp5qhb2lw/Vgz7Q2ZUOTX7/d zbrxpkJ3Yq4u+n8FHf3+l0rczs6QU5XA+mvSjyj/GskvgxIPy2lGqHRDnTCVFtVEjPHJ 3xm5AguVJuAh1I8tBVMmuqrTycLTPrPuIR8zJoPDeRJK5+cNB82NIQ7ca1PdQuOe3pp0 fFSg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=C1wSa6Edi9lzeEZRMqeJGlD2jSBbF4ofKWoOaKD7CQE=; b=AM3c+MtYLYNtA3WE2xln6aLLHqADWNFe2VgBAuxeuNcrS6q+MbmxG2MkzTBBVydMsO 91cGh2rhMVGCfvMrVe7unoJnIOxBVji0ys/pnpUHVRuZZoxVfx5nrledkiOp23JZII57 pSrwVt5E5wySR5ZNsdocJ/V4wUWyI0O5L/6QZymCmQgN/RW3WWntGBqK6qUFwwIdbOeb L/q5h9GsJSQw4F8SceiL2CguMwU1IwtdFP/lvhGi5hs4SDzQ9tZMTq6pbknpaidAtgje cuT46rKqWcn4B2FR+HZLNXRRKZ3ZqhkDvq07Z7VgGTr0t+z9gufvL/np/WZ/fTUPLb8B +u5Q== X-Gm-Message-State: APf1xPC9DgIY3T0jT59BLxEAALYSYr903bFv97MKHw5Ry0AtImkKzsJY hf/20agdkYWHhJVwVZ/lvCoNCQ== X-Received: by 10.25.242.4 with SMTP id q4mr8290804lfh.51.1518953849138; Sun, 18 Feb 2018 03:37:29 -0800 (PST) Received: from alpha (ppp89-110-0-230.pppoe.avangarddsl.ru. [89.110.0.230]) by smtp.gmail.com with ESMTPSA id o28sm1342225lfc.63.2018.02.18.03.37.28 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sun, 18 Feb 2018 03:37:28 -0800 (PST) Received: (nullmailer pid 32734 invoked by uid 1000); Sun, 18 Feb 2018 11:38:11 -0000 From: Ivan Safonov To: Greg Kroah-Hartman Cc: Hans de Goede , Georgiana Chelu , Janani Sankara Babu , Aastha Gupta , devel@driverdev.osuosl.org, linux-kernel@vger.kernel.org, Ivan Safonov Subject: [PATCH] staging:r8188eu: Use lib80211 to decrypt WEP-frames Date: Sun, 18 Feb 2018 14:37:38 +0300 Message-Id: <20180218113738.32689-1-insafonov@gmail.com> X-Mailer: git-send-email 2.16.1 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Use native lib80211 WEP decrypt instead of custom implementation. Signed-off-by: Ivan Safonov --- drivers/staging/rtl8188eu/Kconfig | 2 + drivers/staging/rtl8188eu/core/rtw_recv.c | 2 +- drivers/staging/rtl8188eu/core/rtw_security.c | 80 +++++++++++++----------- drivers/staging/rtl8188eu/include/rtw_security.h | 2 +- 4 files changed, 49 insertions(+), 37 deletions(-) diff --git a/drivers/staging/rtl8188eu/Kconfig b/drivers/staging/rtl8188eu/Kconfig index cb836c59d564..d787a091d3c1 100644 --- a/drivers/staging/rtl8188eu/Kconfig +++ b/drivers/staging/rtl8188eu/Kconfig @@ -4,6 +4,8 @@ config R8188EU depends on m select WIRELESS_EXT select WEXT_PRIV + select LIB80211 + select LIB80211_CRYPT_WEP ---help--- This option adds the Realtek RTL8188EU USB device such as TP-Link TL-WN725N. If built as a module, it will be called r8188eu. diff --git a/drivers/staging/rtl8188eu/core/rtw_recv.c b/drivers/staging/rtl8188eu/core/rtw_recv.c index 6506a1587df0..fe31ebbf36fb 100644 --- a/drivers/staging/rtl8188eu/core/rtw_recv.c +++ b/drivers/staging/rtl8188eu/core/rtw_recv.c @@ -404,7 +404,7 @@ static struct recv_frame *decryptor(struct adapter *padapter, switch (prxattrib->encrypt) { case _WEP40_: case _WEP104_: - rtw_wep_decrypt(padapter, (u8 *)precv_frame); + res = rtw_wep_decrypt(padapter, (u8 *)precv_frame); break; case _TKIP_: res = rtw_tkip_decrypt(padapter, (u8 *)precv_frame); diff --git a/drivers/staging/rtl8188eu/core/rtw_security.c b/drivers/staging/rtl8188eu/core/rtw_security.c index 5b1ef229df2a..72da86fdd264 100644 --- a/drivers/staging/rtl8188eu/core/rtw_security.c +++ b/drivers/staging/rtl8188eu/core/rtw_security.c @@ -18,6 +18,7 @@ #include #include #include +#include /* WEP related ===== */ @@ -195,48 +196,57 @@ void rtw_wep_encrypt(struct adapter *padapter, u8 *pxmitframe) } -void rtw_wep_decrypt(struct adapter *padapter, u8 *precvframe) +int rtw_wep_decrypt(struct adapter *padapter, u8 *precvframe) { - /* exclude ICV */ - u8 crc[4]; - struct arc4context mycontext; - int length; - u32 keylength; - u8 *pframe, *payload, *iv, wepkey[16]; - u8 keyindex; struct rx_pkt_attrib *prxattrib = &(((struct recv_frame *)precvframe)->attrib); - struct security_priv *psecuritypriv = &padapter->securitypriv; + if ((prxattrib->encrypt == _WEP40_) || (prxattrib->encrypt == _WEP104_)) { + struct security_priv *psecuritypriv = &padapter->securitypriv; + struct sk_buff *skb = ((struct recv_frame *)precvframe)->pkt; + u8 *pframe = skb->data; + void *crypto_private = NULL; + int status = _SUCCESS; + const int keyindex = prxattrib->key_index; + struct lib80211_crypto_ops *crypto_ops = try_then_request_module(lib80211_get_crypto_ops("WEP"), "lib80211_crypt_wep"); + char iv[4], icv[4]; + + if (!crypto_ops) { + status = _FAIL; + goto exit; + } - pframe = (unsigned char *)((struct recv_frame *)precvframe)->pkt->data; + memcpy(iv, pframe + prxattrib->hdrlen, 4); + memcpy(icv, pframe + skb->len - 4, 4); - /* start to decrypt recvframe */ - if ((prxattrib->encrypt == _WEP40_) || (prxattrib->encrypt == _WEP104_)) { - iv = pframe+prxattrib->hdrlen; - keyindex = prxattrib->key_index; - keylength = psecuritypriv->dot11DefKeylen[keyindex]; - memcpy(&wepkey[0], iv, 3); - memcpy(&wepkey[3], &psecuritypriv->dot11DefKey[keyindex].skey[0], keylength); - length = ((struct recv_frame *)precvframe)->pkt->len-prxattrib->hdrlen-prxattrib->iv_len; - - payload = pframe+prxattrib->iv_len+prxattrib->hdrlen; - - /* decrypt payload include icv */ - arcfour_init(&mycontext, wepkey, 3+keylength); - arcfour_encrypt(&mycontext, payload, payload, length); - - /* calculate icv and compare the icv */ - *((__le32 *)crc) = getcrc32(payload, length - 4); - - if (crc[3] != payload[length-1] || - crc[2] != payload[length-2] || - crc[1] != payload[length-3] || - crc[0] != payload[length-4]) { - RT_TRACE(_module_rtl871x_security_c_, _drv_err_, - ("rtw_wep_decrypt:icv error crc (%4ph)!=payload (%4ph)\n", - &crc, &payload[length-4])); + crypto_private = crypto_ops->init(keyindex); + if (!crypto_private) { + status = _FAIL; + goto exit; + } + if (crypto_ops->set_key(psecuritypriv->dot11DefKey[keyindex].skey, + psecuritypriv->dot11DefKeylen[keyindex], NULL, crypto_private) < 0) { + status = _FAIL; + goto exit; } + if (crypto_ops->decrypt_mpdu(skb, prxattrib->hdrlen, crypto_private)) { + status = _FAIL; + goto exit; + } + + memmove(pframe, pframe + 4, prxattrib->hdrlen); + skb_push(skb, 4); + skb_put(skb, 4); + + memcpy(pframe + prxattrib->hdrlen, iv, 4); + memcpy(pframe + skb->len - 4, icv, 4); + +exit: + if (crypto_ops && crypto_private) + crypto_ops->deinit(crypto_private); + return status; } + + return _FAIL; } /* 3 ===== TKIP related ===== */ diff --git a/drivers/staging/rtl8188eu/include/rtw_security.h b/drivers/staging/rtl8188eu/include/rtw_security.h index a0c6cf706218..b1883ca852af 100644 --- a/drivers/staging/rtl8188eu/include/rtw_security.h +++ b/drivers/staging/rtl8188eu/include/rtw_security.h @@ -308,6 +308,6 @@ u32 rtw_tkip_encrypt(struct adapter *padapter, u8 *pxmitframe); void rtw_wep_encrypt(struct adapter *padapter, u8 *pxmitframe); u32 rtw_aes_decrypt(struct adapter *padapter, u8 *precvframe); u32 rtw_tkip_decrypt(struct adapter *padapter, u8 *precvframe); -void rtw_wep_decrypt(struct adapter *padapter, u8 *precvframe); +int rtw_wep_decrypt(struct adapter *padapter, u8 *precvframe); #endif /* __RTL871X_SECURITY_H_ */ -- 2.16.1