Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp2080886imm; Sat, 30 Jun 2018 10:26:08 -0700 (PDT) X-Google-Smtp-Source: ADUXVKI6yuOESGJcxbnePEBAZv9nH10C/eUJ/A6Rzk+L0BdTMLSkhC3aEipA+/sYpsfOOL+giIy2 X-Received: by 2002:a65:4dc3:: with SMTP id q3-v6mr16277227pgt.331.1530379568190; Sat, 30 Jun 2018 10:26:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530379568; cv=none; d=google.com; s=arc-20160816; b=Acq4SiEQE0/1BdqFeD4gRfGuytIU1DUU0SoLKN3bdJSIprHP16WPHHWVO3ci+3MSXq 46K6aExmnyyqGSwoWPGRE2Z6FOdCA88N+Qn9xcBdR0G4SeWmIlTMRBw5vC1FKRgU0Ui1 qA3zz2zu2IX67giRsZcbC8y93/l995F3X3q0C+dApq0WC6I/LQJVBD6GPBOw/b16RZRo ypbJQL9n5aaZCN6P5mmcA9MwE8t/r10DIWI241g0+Tx/kkjy9lLIx7zX3a3bE4p3zGMT gZLLhi7YtqJ1sHq6iIDrDmJOd0syq49TW+FXjC3Pnb2FtuXMz+pxspfDun8JeMKrLTsk AkkA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:content-disposition :mime-version:message-id:subject:cc:to:from:date:dkim-signature :arc-authentication-results; bh=Dgxudz0a1pzLwUtbKyQJYZ0oHiDFzvD9573v6zEkwEw=; b=f5yglrqFRD29d8rLzaN5Dzv14VVfFV8vNiE+rStSRgdGz4GRjA+YzBNl9Q1dIypHPp 7lijZRN3zZM/5vPKvM7GosDkCG4cK8SlIvXWXf7uT2eVrhyZSqGd/fLeWQBUL94kKKgq h1BknTYnlEvkm8coAprDdESXInxN4HqCu90AgNenVmsP6/w9jjIjQk/XOo1C332LOmzP NzCavsURn3bzFlhKcqNHhPm7Me2JovRRNvqL7bn+nYvoGUS1kLfpE0kVWlFs8JGbsAoZ 2Otng+CtXKcUkCHQDXr14dxCYLyqbjqBFgkNP0ecv2FerQAEEPIGznEyQEmi4kccFovt BUyQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=ApSHYUuG; 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 d41-v6si11534068pla.162.2018.06.30.10.25.53; Sat, 30 Jun 2018 10:26:08 -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=ApSHYUuG; 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 S1751700AbeF3RY0 (ORCPT + 99 others); Sat, 30 Jun 2018 13:24:26 -0400 Received: from mail-lj1-f196.google.com ([209.85.208.196]:40120 "EHLO mail-lj1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751304AbeF3RYX (ORCPT ); Sat, 30 Jun 2018 13:24:23 -0400 Received: by mail-lj1-f196.google.com with SMTP id a6-v6so9626899ljj.7 for ; Sat, 30 Jun 2018 10:24:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:mime-version:content-disposition :user-agent; bh=Dgxudz0a1pzLwUtbKyQJYZ0oHiDFzvD9573v6zEkwEw=; b=ApSHYUuGM3YJnFoNj6N6l3XrsNRwbLXQ0bcXHy8EanCOIp4VvkZ2ihyvuBzM8wWnUa uIazQ5o/0LpaiLrIMNhmDbgTvUkhZ1jRXg2W2ayyCAStp/QO+07IFDFGNWFjS/XnuEfL hKSCmQwrHdhJt98uZ0X6JtnIJVb4/whRJY7wV/zBYtf5Kpy1pyzQuRjL/A9kRlyKck4e IwgrTCOrnpe0DVOJ3h6ywEjqDpBvolZaEmQguNGlFc1r2IpRdFQJcRKfPUXiiDvhv+F8 StXnW+kB2WRFOyxBkT45q4hEg7U1jcJ5xzC6dlOKin0J+y4u0+M/1WTNUS9HiGOs3A71 uJmw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition:user-agent; bh=Dgxudz0a1pzLwUtbKyQJYZ0oHiDFzvD9573v6zEkwEw=; b=Np1RLRwM5z9XcsABTGHzCk22Kd5uC2mPwzMoYCm3+O+m//oR2KOtY1ztDvO74qVhVm YnGJmCF6nOa0t0BDxo95iwDnQ/6ny1YKMc9nEL2cg2wgYtchotu7aLnPz3OkiUXnkjaK xTLhWy4qtL8abObO0plJCNS0VEHGetkx+bmYVzvQCzNeuRMBOU4gl5+tV03W1D8Sexzx C34qayyIAXwc4C56iWu+h+YHnKiYbqqkGBdw6GwCVg0n0GxR3cioN+3+p65CDFG4PCX6 KwpXuvIuGSe+pbNEDVRr/kZ4t8RfpH9hkhnNSol+0khTsEdoERFoX8f6PsQYhezj9ag4 evCg== X-Gm-Message-State: APt69E0DB7GEt/GAJTpVwi9Rgl93VisOLN4WSPSx81oz1y6kZkJFeK78 /HI5benP7oSoDO0rLjL+Rjc= X-Received: by 2002:a2e:5f89:: with SMTP id x9-v6mr5696447lje.16.1530379461480; Sat, 30 Jun 2018 10:24:21 -0700 (PDT) Received: from alpha (92-100-183-173.dynamic.avangarddsl.ru. [92.100.183.173]) by smtp.gmail.com with ESMTPSA id k202-v6sm2208130lfg.15.2018.06.30.10.24.20 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sat, 30 Jun 2018 10:24:20 -0700 (PDT) Received: (nullmailer pid 1236 invoked by uid 1000); Sat, 30 Jun 2018 17:25:29 -0000 Date: Sat, 30 Jun 2018 20:25:29 +0300 From: Ivan Safonov To: Greg Kroah-Hartman Cc: Dan Carpenter , devel@driverdev.osuosl.org, Santha Meena Ramamoorthy , Janani Sankara Babu , linux-kernel@vger.kernel.org Subject: [PATCH v3] staging:r8188eu: Use lib80211 to encrypt (WEP) tx frames Message-ID: <20180630172529.GA1232@alpha> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.9.4 (2018-02-28) 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 --- v2: - refactor error handling, v3: - fix commit message. drivers/staging/rtl8188eu/core/rtw_security.c | 82 +++++++++++++++------------ 1 file changed, 47 insertions(+), 35 deletions(-) diff --git a/drivers/staging/rtl8188eu/core/rtw_security.c b/drivers/staging/rtl8188eu/core/rtw_security.c index 5b8d7288a4e7..a01290467c64 100644 --- a/drivers/staging/rtl8188eu/core/rtw_security.c +++ b/drivers/staging/rtl8188eu/core/rtw_security.c @@ -131,60 +131,72 @@ 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; - + const int keyindex = psecuritypriv->dot11PrivacyKeyIndex; + void *crypto_private; + struct sk_buff *skb; + struct lib80211_crypto_ops *crypto_ops; if (((struct xmit_frame *)pxmitframe)->buf_addr == NULL) return; + if ((pattrib->encrypt != _WEP40_) && (pattrib->encrypt != _WEP104_)) + return; + hw_hdr_offset = TXDESC_SIZE + (((struct xmit_frame *)pxmitframe)->pkt_offset * PACKET_OFFSET_SZ); pframe = ((struct xmit_frame *)pxmitframe)->buf_addr + hw_hdr_offset; - /* start to encrypt each fragment */ - if ((pattrib->encrypt == _WEP40_) || (pattrib->encrypt == _WEP104_)) { - keylength = psecuritypriv->dot11DefKeylen[psecuritypriv->dot11PrivacyKeyIndex]; + crypto_ops = try_then_request_module(lib80211_get_crypto_ops("WEP"), "lib80211_crypt_wep"); - 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 (!crypto_ops) + return; - if ((curfragnum+1) == pattrib->nr_frags) { /* the last fragment */ - length = pattrib->last_txcmdsz-pattrib->hdrlen-pattrib->iv_len-pattrib->icv_len; + crypto_private = crypto_ops->init(keyindex); + if (!crypto_private) + return; - *((__le32 *)crc) = getcrc32(payload, length); + if (crypto_ops->set_key(psecuritypriv->dot11DefKey[keyindex].skey, + psecuritypriv->dot11DefKeylen[keyindex], NULL, crypto_private) < 0) + goto free_crypto_private; - 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); - } + for (curfragnum = 0; curfragnum < pattrib->nr_frags; curfragnum++) { + if (curfragnum + 1 == pattrib->nr_frags) + length = pattrib->last_txcmdsz; + else + length = pxmitpriv->frag_len; + skb = dev_alloc_skb(length); + if (!skb) + goto free_crypto_private; + + skb_put_data(skb, pframe, length); + + memmove(skb->data + 4, skb->data, pattrib->hdrlen); + skb_pull(skb, 4); + skb_trim(skb, skb->len - 4); + + if (crypto_ops->encrypt_mpdu(skb, pattrib->hdrlen, crypto_private)) { + kfree_skb(skb); + goto free_crypto_private; } + + memcpy(pframe, skb->data, skb->len); + + pframe += skb->len; + pframe = (u8 *)round_up((size_t)(pframe), 4); + + kfree_skb(skb); } + +free_crypto_private: + crypto_ops->deinit(crypto_private); } int rtw_wep_decrypt(struct adapter *padapter, u8 *precvframe) -- 2.16.4