[3/3] staging: rtl8712: Use existing arc4 implementation
diff mbox series

Message ID a793f56d34e53397607df54c683943d2c48b84f7.1618055514.git.christophe.jaillet@wanadoo.fr
State New
Headers show
Series
  • [1/3] staging: rtl8188eu: Use existing arc4 implementation
Related show

Commit Message

Christophe JAILLET April 10, 2021, 11:56 a.m. UTC
Use functions provided by <crypto/arc4.h> instead of hand writing them.

The implementations are slightly different, but are equivalent. It has
been checked with a test program which compares the output of the 2 sets of
functions.

Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
 drivers/staging/rtl8712/rtl871x_security.c | 118 +++++----------------
 1 file changed, 29 insertions(+), 89 deletions(-)

Comments

Greg KH April 10, 2021, 12:09 p.m. UTC | #1
On Sat, Apr 10, 2021 at 01:56:57PM +0200, Christophe JAILLET wrote:
> Use functions provided by <crypto/arc4.h> instead of hand writing them.
> 
> The implementations are slightly different, but are equivalent. It has
> been checked with a test program which compares the output of the 2 sets of
> functions.
> 
> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>

I can not see patch 2/3 of this series, what happened to it?

thanks,

greg k-h
kernel test robot April 10, 2021, 3:39 p.m. UTC | #2
Hi Christophe,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on staging/staging-testing]

url:    https://github.com/0day-ci/linux/commits/Christophe-JAILLET/staging-rtl8188eu-Use-existing-arc4-implementation/20210410-213656
base:   https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/staging.git 32abcac8037da5dc570c22abf266cbb92eee9fc9
config: arm-randconfig-s032-20210410 (attached as .config)
compiler: arm-linux-gnueabi-gcc (GCC) 9.3.0
reproduce:
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # apt-get install sparse
        # sparse version: v0.6.3-279-g6d5d9b42-dirty
        # https://github.com/0day-ci/linux/commit/ea2709e5f53370e588967f79d2eb847555ea9d3b
        git remote add linux-review https://github.com/0day-ci/linux
        git fetch --no-tags linux-review Christophe-JAILLET/staging-rtl8188eu-Use-existing-arc4-implementation/20210410-213656
        git checkout ea2709e5f53370e588967f79d2eb847555ea9d3b
        # save the attached .config to linux build tree
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__' ARCH=arm 

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>

All warnings (new ones prefixed by >>):

   drivers/staging/rtl8712/rtl871x_security.c: In function 'r8712_wep_encrypt':
>> drivers/staging/rtl8712/rtl871x_security.c:147:1: warning: the frame size of 1072 bytes is larger than 1024 bytes [-Wframe-larger-than=]
     147 | }
         | ^
   drivers/staging/rtl8712/rtl871x_security.c: In function 'r8712_wep_decrypt':
   drivers/staging/rtl8712/rtl871x_security.c:182:1: warning: the frame size of 1056 bytes is larger than 1024 bytes [-Wframe-larger-than=]
     182 | }
         | ^
   drivers/staging/rtl8712/rtl871x_security.c: In function 'r8712_tkip_encrypt':
   drivers/staging/rtl8712/rtl871x_security.c:576:1: warning: the frame size of 1088 bytes is larger than 1024 bytes [-Wframe-larger-than=]
     576 | }
         | ^
   drivers/staging/rtl8712/rtl871x_security.c: In function 'r8712_tkip_decrypt':
   drivers/staging/rtl8712/rtl871x_security.c:631:1: warning: the frame size of 1072 bytes is larger than 1024 bytes [-Wframe-larger-than=]
     631 | }
         | ^


vim +147 drivers/staging/rtl8712/rtl871x_security.c

2865d42c78a912 Larry Finger        2010-08-20   88  
2865d42c78a912 Larry Finger        2010-08-20   89  /*
09b080f73a4191 Vijai Kumar K       2016-11-20   90   * Need to consider the fragment situation
2865d42c78a912 Larry Finger        2010-08-20   91   */
2865d42c78a912 Larry Finger        2010-08-20   92  void r8712_wep_encrypt(struct _adapter *padapter, u8 *pxmitframe)
2865d42c78a912 Larry Finger        2010-08-20   93  {	/* exclude ICV */
2865d42c78a912 Larry Finger        2010-08-20   94  	unsigned char	crc[4];
ea2709e5f53370 Christophe JAILLET  2021-04-10   95  	struct arc4_ctx  mycontext;
b78559b60518eb Martin Homuth       2017-12-19   96  	u32 curfragnum, length, keylength, pki;
2865d42c78a912 Larry Finger        2010-08-20   97  	u8 *pframe, *payload, *iv;    /*,*wepkey*/
2865d42c78a912 Larry Finger        2010-08-20   98  	u8 wepkey[16];
2865d42c78a912 Larry Finger        2010-08-20   99  	struct	pkt_attrib  *pattrib = &((struct xmit_frame *)
2865d42c78a912 Larry Finger        2010-08-20  100  				       pxmitframe)->attrib;
2865d42c78a912 Larry Finger        2010-08-20  101  	struct	security_priv *psecuritypriv = &padapter->securitypriv;
2865d42c78a912 Larry Finger        2010-08-20  102  	struct	xmit_priv *pxmitpriv = &padapter->xmitpriv;
2865d42c78a912 Larry Finger        2010-08-20  103  
2865d42c78a912 Larry Finger        2010-08-20  104  	if (((struct xmit_frame *)pxmitframe)->buf_addr == NULL)
2865d42c78a912 Larry Finger        2010-08-20  105  		return;
2865d42c78a912 Larry Finger        2010-08-20  106  	pframe = ((struct xmit_frame *)pxmitframe)->buf_addr + TXDESC_OFFSET;
2865d42c78a912 Larry Finger        2010-08-20  107  	/*start to encrypt each fragment*/
2865d42c78a912 Larry Finger        2010-08-20  108  	if ((pattrib->encrypt == _WEP40_) || (pattrib->encrypt == _WEP104_)) {
b78559b60518eb Martin Homuth       2017-12-19  109  		pki = psecuritypriv->PrivacyKeyIndex;
b78559b60518eb Martin Homuth       2017-12-19  110  		keylength = psecuritypriv->DefKeylen[pki];
2865d42c78a912 Larry Finger        2010-08-20  111  		for (curfragnum = 0; curfragnum < pattrib->nr_frags;
2865d42c78a912 Larry Finger        2010-08-20  112  		     curfragnum++) {
2865d42c78a912 Larry Finger        2010-08-20  113  			iv = pframe + pattrib->hdrlen;
2865d42c78a912 Larry Finger        2010-08-20  114  			memcpy(&wepkey[0], iv, 3);
2865d42c78a912 Larry Finger        2010-08-20  115  			memcpy(&wepkey[3], &psecuritypriv->DefKey[
2865d42c78a912 Larry Finger        2010-08-20  116  				psecuritypriv->PrivacyKeyIndex].skey[0],
2865d42c78a912 Larry Finger        2010-08-20  117  				keylength);
2865d42c78a912 Larry Finger        2010-08-20  118  			payload = pframe + pattrib->iv_len + pattrib->hdrlen;
2865d42c78a912 Larry Finger        2010-08-20  119  			if ((curfragnum + 1) == pattrib->nr_frags) {
b78559b60518eb Martin Homuth       2017-12-19  120  				length = pattrib->last_txcmdsz -
b78559b60518eb Martin Homuth       2017-12-19  121  					pattrib->hdrlen -
b78559b60518eb Martin Homuth       2017-12-19  122  					pattrib->iv_len -
2865d42c78a912 Larry Finger        2010-08-20  123  					pattrib->icv_len;
dd9161483f420c Jannik Becher       2016-12-20  124  				*((__le32 *)crc) = cpu_to_le32(getcrc32(
2865d42c78a912 Larry Finger        2010-08-20  125  						payload, length));
ea2709e5f53370 Christophe JAILLET  2021-04-10  126  				arc4_setkey(&mycontext, wepkey, 3 + keylength);
ea2709e5f53370 Christophe JAILLET  2021-04-10  127  				arc4_crypt(&mycontext, payload, payload,
2865d42c78a912 Larry Finger        2010-08-20  128  					   length);
ea2709e5f53370 Christophe JAILLET  2021-04-10  129  				arc4_crypt(&mycontext, payload + length,
2865d42c78a912 Larry Finger        2010-08-20  130  					   crc, 4);
2865d42c78a912 Larry Finger        2010-08-20  131  			} else {
4ef2de5ae0377b Luis de Bethencourt 2015-10-19  132  				length = pxmitpriv->frag_len -
4ef2de5ae0377b Luis de Bethencourt 2015-10-19  133  					 pattrib->hdrlen - pattrib->iv_len -
4ef2de5ae0377b Luis de Bethencourt 2015-10-19  134  					 pattrib->icv_len;
dd9161483f420c Jannik Becher       2016-12-20  135  				*((__le32 *)crc) = cpu_to_le32(getcrc32(
2865d42c78a912 Larry Finger        2010-08-20  136  						payload, length));
ea2709e5f53370 Christophe JAILLET  2021-04-10  137  				arc4_setkey(&mycontext, wepkey, 3 + keylength);
ea2709e5f53370 Christophe JAILLET  2021-04-10  138  				arc4_crypt(&mycontext, payload, payload,
2865d42c78a912 Larry Finger        2010-08-20  139  					   length);
ea2709e5f53370 Christophe JAILLET  2021-04-10  140  				arc4_crypt(&mycontext, payload + length,
2865d42c78a912 Larry Finger        2010-08-20  141  					   crc, 4);
2865d42c78a912 Larry Finger        2010-08-20  142  				pframe += pxmitpriv->frag_len;
2865d42c78a912 Larry Finger        2010-08-20  143  				pframe = (u8 *)RND4((addr_t)(pframe));
2865d42c78a912 Larry Finger        2010-08-20  144  			}
2865d42c78a912 Larry Finger        2010-08-20  145  		}
2865d42c78a912 Larry Finger        2010-08-20  146  	}
2865d42c78a912 Larry Finger        2010-08-20 @147  }
2865d42c78a912 Larry Finger        2010-08-20  148  

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org
kernel test robot April 17, 2021, 12:57 p.m. UTC | #3
Hi Christophe,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on staging/staging-testing]

url:    https://github.com/0day-ci/linux/commits/Christophe-JAILLET/staging-rtl8188eu-Use-existing-arc4-implementation/20210410-213656
base:   https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/staging.git 32abcac8037da5dc570c22abf266cbb92eee9fc9
config: x86_64-randconfig-s021-20210416 (attached as .config)
compiler: gcc-9 (Debian 9.3.0-22) 9.3.0
reproduce:
        # apt-get install sparse
        # sparse version: v0.6.3-280-g2cd6d34e-dirty
        # https://github.com/0day-ci/linux/commit/ea2709e5f53370e588967f79d2eb847555ea9d3b
        git remote add linux-review https://github.com/0day-ci/linux
        git fetch --no-tags linux-review Christophe-JAILLET/staging-rtl8188eu-Use-existing-arc4-implementation/20210410-213656
        git checkout ea2709e5f53370e588967f79d2eb847555ea9d3b
        # save the attached .config to linux build tree
        make W=1 C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__' W=1 ARCH=x86_64 

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>

All errors (new ones prefixed by >>):

   ld: drivers/staging/rtl8712/rtl871x_security.o: in function `r8712_wep_encrypt':
>> drivers/staging/rtl8712/rtl871x_security.c:126: undefined reference to `arc4_setkey'
>> ld: drivers/staging/rtl8712/rtl871x_security.c:127: undefined reference to `arc4_crypt'
   ld: drivers/staging/rtl8712/rtl871x_security.c:129: undefined reference to `arc4_crypt'
>> ld: drivers/staging/rtl8712/rtl871x_security.c:137: undefined reference to `arc4_setkey'
   ld: drivers/staging/rtl8712/rtl871x_security.c:138: undefined reference to `arc4_crypt'
   ld: drivers/staging/rtl8712/rtl871x_security.c:140: undefined reference to `arc4_crypt'
   ld: drivers/staging/rtl8712/rtl871x_security.o: in function `r8712_wep_decrypt':
   drivers/staging/rtl8712/rtl871x_security.c:177: undefined reference to `arc4_setkey'
   ld: drivers/staging/rtl8712/rtl871x_security.c:178: undefined reference to `arc4_crypt'
   ld: drivers/staging/rtl8712/rtl871x_security.o: in function `r8712_tkip_encrypt':
   drivers/staging/rtl8712/rtl871x_security.c:550: undefined reference to `arc4_setkey'
   ld: drivers/staging/rtl8712/rtl871x_security.c:551: undefined reference to `arc4_crypt'
   ld: drivers/staging/rtl8712/rtl871x_security.c:553: undefined reference to `arc4_crypt'
   ld: drivers/staging/rtl8712/rtl871x_security.c:562: undefined reference to `arc4_setkey'
   ld: drivers/staging/rtl8712/rtl871x_security.c:563: undefined reference to `arc4_crypt'
   ld: drivers/staging/rtl8712/rtl871x_security.c:565: undefined reference to `arc4_crypt'
   ld: drivers/staging/rtl8712/rtl871x_security.o: in function `r8712_tkip_decrypt':
   drivers/staging/rtl8712/rtl871x_security.c:625: undefined reference to `arc4_setkey'
   ld: drivers/staging/rtl8712/rtl871x_security.c:626: undefined reference to `arc4_crypt'


vim +126 drivers/staging/rtl8712/rtl871x_security.c

    88	
    89	/*
    90	 * Need to consider the fragment situation
    91	 */
    92	void r8712_wep_encrypt(struct _adapter *padapter, u8 *pxmitframe)
    93	{	/* exclude ICV */
    94		unsigned char	crc[4];
    95		struct arc4_ctx  mycontext;
    96		u32 curfragnum, length, keylength, pki;
    97		u8 *pframe, *payload, *iv;    /*,*wepkey*/
    98		u8 wepkey[16];
    99		struct	pkt_attrib  *pattrib = &((struct xmit_frame *)
   100					       pxmitframe)->attrib;
   101		struct	security_priv *psecuritypriv = &padapter->securitypriv;
   102		struct	xmit_priv *pxmitpriv = &padapter->xmitpriv;
   103	
   104		if (((struct xmit_frame *)pxmitframe)->buf_addr == NULL)
   105			return;
   106		pframe = ((struct xmit_frame *)pxmitframe)->buf_addr + TXDESC_OFFSET;
   107		/*start to encrypt each fragment*/
   108		if ((pattrib->encrypt == _WEP40_) || (pattrib->encrypt == _WEP104_)) {
   109			pki = psecuritypriv->PrivacyKeyIndex;
   110			keylength = psecuritypriv->DefKeylen[pki];
   111			for (curfragnum = 0; curfragnum < pattrib->nr_frags;
   112			     curfragnum++) {
   113				iv = pframe + pattrib->hdrlen;
   114				memcpy(&wepkey[0], iv, 3);
   115				memcpy(&wepkey[3], &psecuritypriv->DefKey[
   116					psecuritypriv->PrivacyKeyIndex].skey[0],
   117					keylength);
   118				payload = pframe + pattrib->iv_len + pattrib->hdrlen;
   119				if ((curfragnum + 1) == pattrib->nr_frags) {
   120					length = pattrib->last_txcmdsz -
   121						pattrib->hdrlen -
   122						pattrib->iv_len -
   123						pattrib->icv_len;
   124					*((__le32 *)crc) = cpu_to_le32(getcrc32(
   125							payload, length));
 > 126					arc4_setkey(&mycontext, wepkey, 3 + keylength);
 > 127					arc4_crypt(&mycontext, payload, payload,
   128						   length);
   129					arc4_crypt(&mycontext, payload + length,
   130						   crc, 4);
   131				} else {
   132					length = pxmitpriv->frag_len -
   133						 pattrib->hdrlen - pattrib->iv_len -
   134						 pattrib->icv_len;
   135					*((__le32 *)crc) = cpu_to_le32(getcrc32(
   136							payload, length));
 > 137					arc4_setkey(&mycontext, wepkey, 3 + keylength);
   138					arc4_crypt(&mycontext, payload, payload,
   139						   length);
   140					arc4_crypt(&mycontext, payload + length,
   141						   crc, 4);
   142					pframe += pxmitpriv->frag_len;
   143					pframe = (u8 *)RND4((addr_t)(pframe));
   144				}
   145			}
   146		}
   147	}
   148	

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org

Patch
diff mbox series

diff --git a/drivers/staging/rtl8712/rtl871x_security.c b/drivers/staging/rtl8712/rtl871x_security.c
index 1c7df65db3c9..b546e2f19620 100644
--- a/drivers/staging/rtl8712/rtl871x_security.c
+++ b/drivers/staging/rtl8712/rtl871x_security.c
@@ -16,6 +16,7 @@ 
 
 #define  _RTL871X_SECURITY_C_
 
+#include <crypto/arc4.h>
 #include <linux/compiler.h>
 #include <linux/kernel.h>
 #include <linux/errno.h>
@@ -38,66 +39,6 @@ 
 
 /* =====WEP related===== */
 
-struct arc4context {
-	u32 x;
-	u32 y;
-	u8 state[256];
-};
-
-static void arcfour_init(struct arc4context *parc4ctx, u8 *key, u32 key_len)
-{
-	u32	t, u;
-	u32	keyindex;
-	u32	stateindex;
-	u8 *state;
-	u32	counter;
-
-	state = parc4ctx->state;
-	parc4ctx->x = 0;
-	parc4ctx->y = 0;
-	for (counter = 0; counter < 256; counter++)
-		state[counter] = (u8)counter;
-	keyindex = 0;
-	stateindex = 0;
-	for (counter = 0; counter < 256; counter++) {
-		t = state[counter];
-		stateindex = (stateindex + key[keyindex] + t) & 0xff;
-		u = state[stateindex];
-		state[stateindex] = (u8)t;
-		state[counter] = (u8)u;
-		if (++keyindex >= key_len)
-			keyindex = 0;
-	}
-}
-
-static u32 arcfour_byte(struct arc4context *parc4ctx)
-{
-	u32 x;
-	u32 y;
-	u32 sx, sy;
-	u8 *state;
-
-	state = parc4ctx->state;
-	x = (parc4ctx->x + 1) & 0xff;
-	sx = state[x];
-	y = (sx + parc4ctx->y) & 0xff;
-	sy = state[y];
-	parc4ctx->x = x;
-	parc4ctx->y = y;
-	state[y] = (u8)sx;
-	state[x] = (u8)sy;
-	return state[(sx + sy) & 0xff];
-}
-
-static void arcfour_encrypt(struct arc4context	*parc4ctx,
-		     u8 *dest, u8 *src, u32 len)
-{
-	u32 i;
-
-	for (i = 0; i < len; i++)
-		dest[i] = src[i] ^ (unsigned char)arcfour_byte(parc4ctx);
-}
-
 static sint bcrc32initialized;
 static u32 crc32_table[256];
 
@@ -151,7 +92,7 @@  static u32 getcrc32(u8 *buf, u32 len)
 void r8712_wep_encrypt(struct _adapter *padapter, u8 *pxmitframe)
 {	/* exclude ICV */
 	unsigned char	crc[4];
-	struct arc4context  mycontext;
+	struct arc4_ctx  mycontext;
 	u32 curfragnum, length, keylength, pki;
 	u8 *pframe, *payload, *iv;    /*,*wepkey*/
 	u8 wepkey[16];
@@ -182,22 +123,22 @@  void r8712_wep_encrypt(struct _adapter *padapter, u8 *pxmitframe)
 					pattrib->icv_len;
 				*((__le32 *)crc) = cpu_to_le32(getcrc32(
 						payload, length));
-				arcfour_init(&mycontext, wepkey, 3 + keylength);
-				arcfour_encrypt(&mycontext, payload, payload,
-						length);
-				arcfour_encrypt(&mycontext, payload + length,
-						crc, 4);
+				arc4_setkey(&mycontext, wepkey, 3 + keylength);
+				arc4_crypt(&mycontext, payload, payload,
+					   length);
+				arc4_crypt(&mycontext, payload + length,
+					   crc, 4);
 			} else {
 				length = pxmitpriv->frag_len -
 					 pattrib->hdrlen - pattrib->iv_len -
 					 pattrib->icv_len;
 				*((__le32 *)crc) = cpu_to_le32(getcrc32(
 						payload, length));
-				arcfour_init(&mycontext, wepkey, 3 + keylength);
-				arcfour_encrypt(&mycontext, payload, payload,
-						length);
-				arcfour_encrypt(&mycontext, payload + length,
-						crc, 4);
+				arc4_setkey(&mycontext, wepkey, 3 + keylength);
+				arc4_crypt(&mycontext, payload, payload,
+					   length);
+				arc4_crypt(&mycontext, payload + length,
+					   crc, 4);
 				pframe += pxmitpriv->frag_len;
 				pframe = (u8 *)RND4((addr_t)(pframe));
 			}
@@ -209,7 +150,7 @@  void r8712_wep_decrypt(struct _adapter  *padapter, u8 *precvframe)
 {
 	/* exclude ICV */
 	u8 crc[4];
-	struct arc4context  mycontext;
+	struct arc4_ctx mycontext;
 	u32 length, keylength;
 	u8 *pframe, *payload, *iv, wepkey[16];
 	u8  keyindex;
@@ -233,8 +174,8 @@  void r8712_wep_decrypt(struct _adapter  *padapter, u8 *precvframe)
 			   u.hdr.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);
+		arc4_setkey(&mycontext, wepkey, 3 + keylength);
+		arc4_crypt(&mycontext, payload, payload, length);
 		/* calculate icv and compare the icv */
 		*((__le32 *)crc) = cpu_to_le32(getcrc32(payload, length - 4));
 	}
@@ -563,7 +504,7 @@  u32 r8712_tkip_encrypt(struct _adapter *padapter, u8 *pxmitframe)
 	u8 rc4key[16];
 	u8 ttkey[16];
 	u8 crc[4];
-	struct arc4context mycontext;
+	struct arc4_ctx mycontext;
 	u32 curfragnum, length;
 
 	u8 *pframe, *payload, *iv, *prwskey;
@@ -606,11 +547,11 @@  u32 r8712_tkip_encrypt(struct _adapter *padapter, u8 *pxmitframe)
 					     pattrib->icv_len;
 					*((__le32 *)crc) = cpu_to_le32(
 						getcrc32(payload, length));
-					arcfour_init(&mycontext, rc4key, 16);
-					arcfour_encrypt(&mycontext, payload,
-							payload, length);
-					arcfour_encrypt(&mycontext, payload +
-							length, crc, 4);
+					arc4_setkey(&mycontext, rc4key, 16);
+					arc4_crypt(&mycontext, payload,
+						   payload, length);
+					arc4_crypt(&mycontext, payload +
+						   length, crc, 4);
 				} else {
 					length = pxmitpriv->frag_len -
 						 pattrib->hdrlen -
@@ -618,12 +559,11 @@  u32 r8712_tkip_encrypt(struct _adapter *padapter, u8 *pxmitframe)
 						 pattrib->icv_len;
 					*((__le32 *)crc) = cpu_to_le32(getcrc32(
 							payload, length));
-					arcfour_init(&mycontext, rc4key, 16);
-					arcfour_encrypt(&mycontext, payload,
-							 payload, length);
-					arcfour_encrypt(&mycontext,
-							payload + length, crc,
-							4);
+					arc4_setkey(&mycontext, rc4key, 16);
+					arc4_crypt(&mycontext, payload,
+						   payload, length);
+					arc4_crypt(&mycontext,
+						   payload + length, crc, 4);
 					pframe += pxmitpriv->frag_len;
 					pframe = (u8 *)RND4((addr_t)(pframe));
 				}
@@ -643,7 +583,7 @@  void r8712_tkip_decrypt(struct _adapter *padapter, u8 *precvframe)
 	u8 rc4key[16];
 	u8 ttkey[16];
 	u8 crc[4];
-	struct arc4context mycontext;
+	struct arc4_ctx mycontext;
 	u32 length;
 	u8 *pframe, *payload, *iv, *prwskey, idx = 0;
 	union pn48 txpn;
@@ -682,8 +622,8 @@  void r8712_tkip_decrypt(struct _adapter *padapter, u8 *precvframe)
 			phase2(&rc4key[0], prwskey, (unsigned short *)
 			       &ttkey[0], pnl);
 			/* 4 decrypt payload include icv */
-			arcfour_init(&mycontext, rc4key, 16);
-			arcfour_encrypt(&mycontext, payload, payload, length);
+			arc4_setkey(&mycontext, rc4key, 16);
+			arc4_crypt(&mycontext, payload, payload, length);
 			*((__le32 *)crc) = cpu_to_le32(getcrc32(payload,
 					length - 4));
 		}