Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp2016568imm; Sun, 27 May 2018 23:18:31 -0700 (PDT) X-Google-Smtp-Source: AB8JxZreEFxmj+ptn3ndx74YRrLUoQMjmoU5HhosLv41XtUCZwsdq8UkPinFpzxPjDAQ+DTAL1Ou X-Received: by 2002:a17:902:8685:: with SMTP id g5-v6mr12132256plo.302.1527488311588; Sun, 27 May 2018 23:18:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527488311; cv=none; d=google.com; s=arc-20160816; b=UOn7X0GuVn1IbrAlGipFd9/rgPlCmZ6RbiwxOpwartuplJyv3m2KRxfohiMAxEjXF6 OOX9X4HUkYQXposXFEN77D5cDY3LGQXJhBXnmnB+bKSbW+6EXHAq0uFJkjc/7gOQPQmC EB1S/Tm/wpAtyelN3/H0YTdZADGty5Gruuw6mXuV0tm+XeHHykarLFsT/YvkaF8CPGRc m9oeqOCc7cFRSB1Lksq2askowOeLjkGxQLpryLLHs4TPp1qL2UwXkmK3LAVo2gLhVlKE 3vKeZLeWIOSuSOe0suVoPXrjzdCVp1MHLIXAFChYWlKsK53r/VcwIkGW7Wc+rzUCdGJU HAWQ== 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=RsrFZr9kt2kpVp1toxf5Cb6JanAFqZgxU1U1OMioA3k=; b=f/RexrjXd9dC2QlfwAx9WODJRUZulKiFQWehlUGCf/8Pntc2SP422kQziG7wE/MRJn C9NfzlPiQ3mNv5mNfdX1XKnnPkjJj0naROlCTcPBEnU7EMLNTpasoV6i9sIgipCssWTJ u5JdXV4eqGluxspS+VdndOxDvzFczBv6JkvPj4nHeerl4vpjVKGEjjcW57fqjzzBBizN O9l7++zZuSEvVuyMMZX9Sly8NamHsO8A7Uk9xkqsmon3duKu6FwwzSPuL9ppHu0Vw51N fNxRM9u/4XwczuhNjjweltmR2EmfwXO2/16p3glzfXLR+t4BetY227gX4kULh0u9T2iy hr7w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=jYh8Q0Nu; 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 32-v6si28818773plc.252.2018.05.27.23.18.17; Sun, 27 May 2018 23:18:31 -0700 (PDT) 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=jYh8Q0Nu; 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 S1753394AbeE1GRu (ORCPT + 99 others); Mon, 28 May 2018 02:17:50 -0400 Received: from mail-wm0-f65.google.com ([74.125.82.65]:52409 "EHLO mail-wm0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753197AbeE1GRs (ORCPT ); Mon, 28 May 2018 02:17:48 -0400 Received: by mail-wm0-f65.google.com with SMTP id 18-v6so23457004wml.2 for ; Sun, 27 May 2018 23:17:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=RsrFZr9kt2kpVp1toxf5Cb6JanAFqZgxU1U1OMioA3k=; b=jYh8Q0NuHB6lWo2kEOKebtJjxJD379r03zCZuFURWp9VXsJicQkNWETPT4rl2tXA8K vHvT7BZK1ikQDwgW/SkB4H4RCgEbikbeKv3+Jy3yX0+9Du6Zwtn8IqQ279RUrpyqXMdb RS4sU371/gy1ZoxSuC3eY6USGDlvsl6A7zfIhPWu/InFWVjqUgIMhu19MRpuAPUclI2U Ni+uMZixgJTvpbtLjApKMPJqbQMZSHJnlM6yoEfZAqtx4IuxUYCN6DMnuFSd3mevpgaI 9oy1WVkXqJC9ZhKR8ANKKofbqbmblxPtwKmkNpu3QWSkkdVZ4Fz4kkv7zKbDkD+qheaJ 1q1A== 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=RsrFZr9kt2kpVp1toxf5Cb6JanAFqZgxU1U1OMioA3k=; b=MvX7CqqbS++kfc8kjfP1zMb/jCikJB7XrG3pJzyD1N7BVpf+7bgkZqu18iaeuf720A HF0buEWSpxFSC6kYtJAhQdAr8rB951Lenrs4wddK4/XHYjVnGc+RXJIkLmXsW+RyM2UV 1HLAhb7b4NUspjHXHdxiSBsQ48Q9Ngq/pdbHGnPk/T5WqrrA24Upx2gmhSF2vOLE7AmP xDkHotsxtRFuv2LlwELe3aJjgj8wgprvBdpF6/XO/DnZ38F3vC8zikixMZWVmZZlwU1N gsiLow9yaHiZPSQLVRoga6h1mANum7mVZrw90eUritJRpVOm+tNc/xbtKV+CqJBl14NI 8qmg== X-Gm-Message-State: ALKqPwdJ8M/tckAGo+p1X7JQ2B0/jBR0ZRKoe6RNR9clXN/yzgdCWSRJ rgTTAlPeH3zMwbtqLqO3ERo= X-Received: by 2002:a2e:29cf:: with SMTP id p76-v6mr3215236ljp.12.1527488267632; Sun, 27 May 2018 23:17:47 -0700 (PDT) Received: from alpha ([178.71.211.192]) by smtp.gmail.com with ESMTPSA id x10-v6sm4348913lfe.39.2018.05.27.23.17.46 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sun, 27 May 2018 23:17:46 -0700 (PDT) Received: (nullmailer pid 26993 invoked by uid 1000); Mon, 28 May 2018 06:18:43 -0000 From: Ivan Safonov To: Greg Kroah-Hartman Cc: Santha Meena Ramamoorthy , Janani Sankara Babu , devel@driverdev.osuosl.org, linux-kernel@vger.kernel.org, Ivan Safonov Subject: [PATCH] staging:r8188eu: Use lib80211 to encrypt (WEP) tx frames Date: Mon, 28 May 2018 09:18:21 +0300 Message-Id: <20180528061821.26948-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 Put data to skb, decrypt with lib80211_crypt_wep, and place back to tx buffer. Signed-off-by: Ivan Safonov --- drivers/staging/rtl8188eu/core/rtw_security.c | 72 ++++++++++++++++----------- 1 file changed, 43 insertions(+), 29 deletions(-) diff --git a/drivers/staging/rtl8188eu/core/rtw_security.c b/drivers/staging/rtl8188eu/core/rtw_security.c index bfe0b217e679..80d7569a3108 100644 --- a/drivers/staging/rtl8188eu/core/rtw_security.c +++ b/drivers/staging/rtl8188eu/core/rtw_security.c @@ -139,17 +139,11 @@ static __le32 getcrc32(u8 *buf, int len) Need to consider the fragment situation */ void rtw_wep_encrypt(struct adapter *padapter, u8 *pxmitframe) -{ /* exclude ICV */ - - unsigned char crc[4]; - struct arc4context mycontext; - +{ int curfragnum, length; - u32 keylength; - u8 *pframe, *payload, *iv; /* wepkey */ - u8 wepkey[16]; - u8 hw_hdr_offset = 0; + u8 *pframe; + u8 hw_hdr_offset = 0; struct pkt_attrib *pattrib = &((struct xmit_frame *)pxmitframe)->attrib; struct security_priv *psecuritypriv = &padapter->securitypriv; struct xmit_priv *pxmitpriv = &padapter->xmitpriv; @@ -165,33 +159,53 @@ void rtw_wep_encrypt(struct adapter *padapter, u8 *pxmitframe) /* start to encrypt each fragment */ if ((pattrib->encrypt == _WEP40_) || (pattrib->encrypt == _WEP104_)) { - keylength = psecuritypriv->dot11DefKeylen[psecuritypriv->dot11PrivacyKeyIndex]; + const int keyindex = psecuritypriv->dot11PrivacyKeyIndex; + void *crypto_private; + struct sk_buff *skb; + struct lib80211_crypto_ops *crypto_ops = try_then_request_module(lib80211_get_crypto_ops("WEP"), "lib80211_crypt_wep"); + + if (!crypto_ops) + goto exit; + + crypto_private = crypto_ops->init(keyindex); + if (!crypto_private) + goto exit; + + if (crypto_ops->set_key(psecuritypriv->dot11DefKey[keyindex].skey, + psecuritypriv->dot11DefKeylen[keyindex], NULL, crypto_private) < 0) + goto exit; for (curfragnum = 0; curfragnum < pattrib->nr_frags; curfragnum++) { - iv = pframe+pattrib->hdrlen; - memcpy(&wepkey[0], iv, 3); - memcpy(&wepkey[3], &psecuritypriv->dot11DefKey[psecuritypriv->dot11PrivacyKeyIndex].skey[0], keylength); - payload = pframe+pattrib->iv_len+pattrib->hdrlen; + if (curfragnum + 1 == pattrib->nr_frags) + length = pattrib->last_txcmdsz; + else + length = pxmitpriv->frag_len; + skb = dev_alloc_skb(length); + if (!skb) + goto exit; - if ((curfragnum+1) == pattrib->nr_frags) { /* the last fragment */ - length = pattrib->last_txcmdsz-pattrib->hdrlen-pattrib->iv_len-pattrib->icv_len; + skb_put_data(skb, pframe, length); - *((__le32 *)crc) = getcrc32(payload, length); + memmove(skb->data + 4, skb->data, pattrib->hdrlen); + skb_pull(skb, 4); + skb_trim(skb, skb->len - 4); - arcfour_init(&mycontext, wepkey, 3+keylength); - arcfour_encrypt(&mycontext, payload, payload, length); - arcfour_encrypt(&mycontext, payload+length, crc, 4); - } else { - length = pxmitpriv->frag_len-pattrib->hdrlen-pattrib->iv_len-pattrib->icv_len; - *((__le32 *)crc) = getcrc32(payload, length); - arcfour_init(&mycontext, wepkey, 3+keylength); - arcfour_encrypt(&mycontext, payload, payload, length); - arcfour_encrypt(&mycontext, payload+length, crc, 4); - - pframe += pxmitpriv->frag_len; - pframe = (u8 *)round_up((size_t)(pframe), 4); + if (crypto_ops->encrypt_mpdu(skb, pattrib->hdrlen, crypto_private)) { + kfree_skb(skb); + goto exit; } + + memcpy(pframe, skb->data, skb->len); + + pframe += skb->len; + pframe = (u8 *)round_up((size_t)(pframe), 4); + + kfree_skb(skb); } + +exit: + if (crypto_ops && crypto_private) + crypto_ops->deinit(crypto_private); } } -- 2.16.1