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

Message ID 6a4aebf9feb9ece975734f2e51da5ecae2996cee.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, 1:35 p.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/rtl8723bs/core/rtw_security.c | 101 ++++--------------
 1 file changed, 21 insertions(+), 80 deletions(-)

Comments

kernel test robot April 10, 2021, 3:25 p.m. UTC | #1
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/e0f0911d8f1c282314b6c6df1c03a0656f575f77
        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 e0f0911d8f1c282314b6c6df1c03a0656f575f77
        # 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/rtl8723bs/core/rtw_security.c: In function 'rtw_wep_encrypt':
>> drivers/staging/rtl8723bs/core/rtw_security.c:144:1: warning: the frame size of 1072 bytes is larger than 1024 bytes [-Wframe-larger-than=]
     144 | }
         | ^
   drivers/staging/rtl8723bs/core/rtw_security.c: In function 'rtw_wep_decrypt':
   drivers/staging/rtl8723bs/core/rtw_security.c:181:1: warning: the frame size of 1056 bytes is larger than 1024 bytes [-Wframe-larger-than=]
     181 | }
         | ^
   drivers/staging/rtl8723bs/core/rtw_security.c: In function 'rtw_tkip_encrypt':
   drivers/staging/rtl8723bs/core/rtw_security.c:583:1: warning: the frame size of 1088 bytes is larger than 1024 bytes [-Wframe-larger-than=]
     583 | }
         | ^
   drivers/staging/rtl8723bs/core/rtw_security.c: In function 'rtw_tkip_decrypt':
   drivers/staging/rtl8723bs/core/rtw_security.c:679:1: warning: the frame size of 1072 bytes is larger than 1024 bytes [-Wframe-larger-than=]
     679 | }
         | ^


vim +144 drivers/staging/rtl8723bs/core/rtw_security.c

554c0a3abf216c Hans de Goede      2017-03-29   92  
554c0a3abf216c Hans de Goede      2017-03-29   93  	unsigned char crc[4];
e0f0911d8f1c28 Christophe JAILLET 2021-04-10   94  	struct arc4_ctx mycontext;
554c0a3abf216c Hans de Goede      2017-03-29   95  
d495c5503d1339 Marco Cesati       2021-03-12   96  	signed int	curfragnum, length;
554c0a3abf216c Hans de Goede      2017-03-29   97  	u32 keylength;
554c0a3abf216c Hans de Goede      2017-03-29   98  
554c0a3abf216c Hans de Goede      2017-03-29   99  	u8 *pframe, *payload, *iv;    /* wepkey */
554c0a3abf216c Hans de Goede      2017-03-29  100  	u8 wepkey[16];
554c0a3abf216c Hans de Goede      2017-03-29  101  	u8 hw_hdr_offset = 0;
554c0a3abf216c Hans de Goede      2017-03-29  102  	struct pkt_attrib *pattrib = &((struct xmit_frame *)pxmitframe)->attrib;
554c0a3abf216c Hans de Goede      2017-03-29  103  	struct security_priv *psecuritypriv = &padapter->securitypriv;
554c0a3abf216c Hans de Goede      2017-03-29  104  	struct xmit_priv *pxmitpriv = &padapter->xmitpriv;
554c0a3abf216c Hans de Goede      2017-03-29  105  
554c0a3abf216c Hans de Goede      2017-03-29  106  	if (((struct xmit_frame *)pxmitframe)->buf_addr == NULL)
554c0a3abf216c Hans de Goede      2017-03-29  107  		return;
554c0a3abf216c Hans de Goede      2017-03-29  108  
554c0a3abf216c Hans de Goede      2017-03-29  109  	hw_hdr_offset = TXDESC_OFFSET;
554c0a3abf216c Hans de Goede      2017-03-29  110  	pframe = ((struct xmit_frame *)pxmitframe)->buf_addr + hw_hdr_offset;
554c0a3abf216c Hans de Goede      2017-03-29  111  
554c0a3abf216c Hans de Goede      2017-03-29  112  	/* start to encrypt each fragment */
554c0a3abf216c Hans de Goede      2017-03-29  113  	if ((pattrib->encrypt == _WEP40_) || (pattrib->encrypt == _WEP104_)) {
554c0a3abf216c Hans de Goede      2017-03-29  114  		keylength = psecuritypriv->dot11DefKeylen[psecuritypriv->dot11PrivacyKeyIndex];
554c0a3abf216c Hans de Goede      2017-03-29  115  
554c0a3abf216c Hans de Goede      2017-03-29  116  		for (curfragnum = 0; curfragnum < pattrib->nr_frags; curfragnum++) {
554c0a3abf216c Hans de Goede      2017-03-29  117  			iv = pframe+pattrib->hdrlen;
554c0a3abf216c Hans de Goede      2017-03-29  118  			memcpy(&wepkey[0], iv, 3);
554c0a3abf216c Hans de Goede      2017-03-29  119  			memcpy(&wepkey[3], &psecuritypriv->dot11DefKey[psecuritypriv->dot11PrivacyKeyIndex].skey[0], keylength);
554c0a3abf216c Hans de Goede      2017-03-29  120  			payload = pframe+pattrib->iv_len+pattrib->hdrlen;
554c0a3abf216c Hans de Goede      2017-03-29  121  
554c0a3abf216c Hans de Goede      2017-03-29  122  			if ((curfragnum+1) == pattrib->nr_frags) {	/* the last fragment */
554c0a3abf216c Hans de Goede      2017-03-29  123  
554c0a3abf216c Hans de Goede      2017-03-29  124  				length = pattrib->last_txcmdsz-pattrib->hdrlen-pattrib->iv_len-pattrib->icv_len;
554c0a3abf216c Hans de Goede      2017-03-29  125  
554c0a3abf216c Hans de Goede      2017-03-29  126  				*((__le32 *)crc) = getcrc32(payload, length);
554c0a3abf216c Hans de Goede      2017-03-29  127  
e0f0911d8f1c28 Christophe JAILLET 2021-04-10  128  				arc4_setkey(&mycontext, wepkey, 3 + keylength);
e0f0911d8f1c28 Christophe JAILLET 2021-04-10  129  				arc4_crypt(&mycontext, payload, payload, length);
e0f0911d8f1c28 Christophe JAILLET 2021-04-10  130  				arc4_crypt(&mycontext, payload + length, crc, 4);
554c0a3abf216c Hans de Goede      2017-03-29  131  
554c0a3abf216c Hans de Goede      2017-03-29  132  			} else {
554c0a3abf216c Hans de Goede      2017-03-29  133  				length = pxmitpriv->frag_len-pattrib->hdrlen-pattrib->iv_len-pattrib->icv_len;
554c0a3abf216c Hans de Goede      2017-03-29  134  				*((__le32 *)crc) = getcrc32(payload, length);
e0f0911d8f1c28 Christophe JAILLET 2021-04-10  135  				arc4_setkey(&mycontext, wepkey, 3 + keylength);
e0f0911d8f1c28 Christophe JAILLET 2021-04-10  136  				arc4_crypt(&mycontext, payload, payload, length);
e0f0911d8f1c28 Christophe JAILLET 2021-04-10  137  				arc4_crypt(&mycontext, payload + length, crc, 4);
554c0a3abf216c Hans de Goede      2017-03-29  138  
554c0a3abf216c Hans de Goede      2017-03-29  139  				pframe += pxmitpriv->frag_len;
87fe08d74ca66d Ross Schmidt       2020-10-03  140  				pframe = (u8 *)round_up((SIZE_PTR)(pframe), 4);
554c0a3abf216c Hans de Goede      2017-03-29  141  			}
554c0a3abf216c Hans de Goede      2017-03-29  142  		}
554c0a3abf216c Hans de Goede      2017-03-29  143  	}
554c0a3abf216c Hans de Goede      2017-03-29 @144  }
554c0a3abf216c Hans de Goede      2017-03-29  145  

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org
Greg KH April 12, 2021, 9:34 a.m. UTC | #2
On Sat, Apr 10, 2021 at 03:35:52PM +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>
> ---
>  drivers/staging/rtl8723bs/core/rtw_security.c | 101 ++++--------------
>  1 file changed, 21 insertions(+), 80 deletions(-)
> 
> diff --git a/drivers/staging/rtl8723bs/core/rtw_security.c b/drivers/staging/rtl8723bs/core/rtw_security.c
> index 9587d89a6b24..86949a65e96f 100644
> --- a/drivers/staging/rtl8723bs/core/rtw_security.c
> +++ b/drivers/staging/rtl8723bs/core/rtw_security.c
> @@ -6,6 +6,7 @@
>   ******************************************************************************/
>  #define  _RTW_SECURITY_C_
>  
> +#include <crypto/arc4.h>
>  #include <linux/crc32poly.h>
>  #include <drv_types.h>
>  #include <rtw_debug.h>
> @@ -31,66 +32,6 @@ const char *security_type_str(u8 value)
>  
>  /* 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 signed int bcrc32initialized;
>  static u32 crc32_table[256];
>  
> @@ -150,7 +91,7 @@ void rtw_wep_encrypt(struct adapter *padapter, u8 *pxmitframe)
>  {																	/*  exclude ICV */
>  
>  	unsigned char crc[4];
> -	struct arc4context	 mycontext;
> +	struct arc4_ctx mycontext;

Are you sure you can declare that much space on the stack?  Is that what
other users of this api do?  In looking at the in-kernel users, they do
not :(

Can you fix up this series to not take up so much stack memory?

thanks,

greg k-h
Christophe JAILLET April 12, 2021, 9:09 p.m. UTC | #3
Le 12/04/2021 à 11:34, Greg KH a écrit :
> On Sat, Apr 10, 2021 at 03:35:52PM +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>
>> ---
>>   drivers/staging/rtl8723bs/core/rtw_security.c | 101 ++++--------------
>>   1 file changed, 21 insertions(+), 80 deletions(-)
>>
>> diff --git a/drivers/staging/rtl8723bs/core/rtw_security.c b/drivers/staging/rtl8723bs/core/rtw_security.c
>> index 9587d89a6b24..86949a65e96f 100644
>> --- a/drivers/staging/rtl8723bs/core/rtw_security.c
>> +++ b/drivers/staging/rtl8723bs/core/rtw_security.c
>> @@ -6,6 +6,7 @@
>>    ******************************************************************************/
>>   #define  _RTW_SECURITY_C_
>>   
>> +#include <crypto/arc4.h>
>>   #include <linux/crc32poly.h>
>>   #include <drv_types.h>
>>   #include <rtw_debug.h>
>> @@ -31,66 +32,6 @@ const char *security_type_str(u8 value)
>>   
>>   /* 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 signed int bcrc32initialized;
>>   static u32 crc32_table[256];
>>   
>> @@ -150,7 +91,7 @@ void rtw_wep_encrypt(struct adapter *padapter, u8 *pxmitframe)
>>   {																	/*  exclude ICV */
>>   
>>   	unsigned char crc[4];
>> -	struct arc4context	 mycontext;
>> +	struct arc4_ctx mycontext;
> 
> Are you sure you can declare that much space on the stack?  Is that what
> other users of this api do?  In looking at the in-kernel users, they do
> not :(
> 

In fact arc4context was a u8[256] but arc4_ctx uses a u32[256].

Maybe arc4 function should be modified to use u8? Or at least when
CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS is defined?



Concerning the other uses of the arc4 API, in fact there is only few of 
them. Most uses are buried into lib80211_crypt_tkip.c and 
lib80211_crypt_wep.c which is the way to go, IMHO.
In fact, I think that most, if not all 'rtl871x_security.c' could be 
removed.

However, it looks like a big step to me. And without any hardware to 
test, I'm pretty sure to break something.


Any hints on the best way to axe some duplicated code without to much 
risks to break everything?

CJ

> Can you fix up this series to not take up so much stack memory?

I guess that _adapter could be used to store this arc4_ctx, but I'm not 
convinced that it is the way to go.

CJ

> 
> thanks,
> 
> greg k-h
>

Patch
diff mbox series

diff --git a/drivers/staging/rtl8723bs/core/rtw_security.c b/drivers/staging/rtl8723bs/core/rtw_security.c
index 9587d89a6b24..86949a65e96f 100644
--- a/drivers/staging/rtl8723bs/core/rtw_security.c
+++ b/drivers/staging/rtl8723bs/core/rtw_security.c
@@ -6,6 +6,7 @@ 
  ******************************************************************************/
 #define  _RTW_SECURITY_C_
 
+#include <crypto/arc4.h>
 #include <linux/crc32poly.h>
 #include <drv_types.h>
 #include <rtw_debug.h>
@@ -31,66 +32,6 @@  const char *security_type_str(u8 value)
 
 /* 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 signed int bcrc32initialized;
 static u32 crc32_table[256];
 
@@ -150,7 +91,7 @@  void rtw_wep_encrypt(struct adapter *padapter, u8 *pxmitframe)
 {																	/*  exclude ICV */
 
 	unsigned char crc[4];
-	struct arc4context	 mycontext;
+	struct arc4_ctx mycontext;
 
 	signed int	curfragnum, length;
 	u32 keylength;
@@ -184,16 +125,16 @@  void rtw_wep_encrypt(struct adapter *padapter, u8 *pxmitframe)
 
 				*((__le32 *)crc) = 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) = 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 *)round_up((SIZE_PTR)(pframe), 4);
@@ -206,7 +147,7 @@  void rtw_wep_decrypt(struct adapter  *padapter, u8 *precvframe)
 {
 	/*  exclude ICV */
 	u8 crc[4];
-	struct arc4context	 mycontext;
+	struct arc4_ctx mycontext;
 	signed int	length;
 	u32 keylength;
 	u8 *pframe, *payload, *iv, wepkey[16];
@@ -230,8 +171,8 @@  void rtw_wep_decrypt(struct adapter  *padapter, u8 *precvframe)
 		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 */
 		*((u32 *)crc) = le32_to_cpu(getcrc32(payload, length-4));
@@ -579,7 +520,7 @@  u32 rtw_tkip_encrypt(struct adapter *padapter, u8 *pxmitframe)
 	u8   ttkey[16];
 	u8 crc[4];
 	u8   hw_hdr_offset = 0;
-	struct arc4context mycontext;
+	struct arc4_ctx mycontext;
 	signed int			curfragnum, length;
 
 	u8 *pframe, *payload, *iv, *prwskey;
@@ -621,16 +562,16 @@  u32 rtw_tkip_encrypt(struct adapter *padapter, u8 *pxmitframe)
 					length = pattrib->last_txcmdsz-pattrib->hdrlen-pattrib->iv_len-pattrib->icv_len;
 					*((__le32 *)crc) = getcrc32(payload, length);/* modified by Amy*/
 
-					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-pattrib->iv_len-pattrib->icv_len;
 					*((__le32 *)crc) = getcrc32(payload, length);/* modified by Amy*/
-					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 *)round_up((SIZE_PTR)(pframe), 4);
@@ -650,7 +591,7 @@  u32 rtw_tkip_decrypt(struct adapter *padapter, u8 *precvframe)
 	u8   rc4key[16];
 	u8   ttkey[16];
 	u8 crc[4];
-	struct arc4context mycontext;
+	struct arc4_ctx mycontext;
 	signed int			length;
 
 	u8 *pframe, *payload, *iv, *prwskey;
@@ -721,8 +662,8 @@  u32 rtw_tkip_decrypt(struct adapter *padapter, u8 *precvframe)
 
 			/* 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);
 
 			*((u32 *)crc) = le32_to_cpu(getcrc32(payload, length-4));