Skip to content

Commit 1b11e89

Browse files
fabioaiutogregkh
authored andcommitted
staging: rtl8723bs: replace private arc4 encryption with in-kernel one
replace private arc4 encryption with in-kernel one. Signed-off-by: Fabio Aiuto <[email protected]> Link: https://lore.kernel.org/r/af960dc728f039d64f4fb28fcece3ca92d24fbe4.1620372584.git.fabioaiuto83@gmail.com Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 8adffa4 commit 1b11e89

File tree

1 file changed

+21
-80
lines changed

1 file changed

+21
-80
lines changed

drivers/staging/rtl8723bs/core/rtw_security.c

Lines changed: 21 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <drv_types.h>
99
#include <rtw_debug.h>
1010
#include <crypto/aes.h>
11+
#include <crypto/arc4.h>
1112

1213
static const char * const _security_type_str[] = {
1314
"N/A",
@@ -30,66 +31,6 @@ const char *security_type_str(u8 value)
3031

3132
/* WEP related ===== */
3233

33-
struct arc4context {
34-
u32 x;
35-
u32 y;
36-
u8 state[256];
37-
};
38-
39-
40-
static void arcfour_init(struct arc4context *parc4ctx, u8 *key, u32 key_len)
41-
{
42-
u32 t, u;
43-
u32 keyindex;
44-
u32 stateindex;
45-
u8 *state;
46-
u32 counter;
47-
48-
state = parc4ctx->state;
49-
parc4ctx->x = 0;
50-
parc4ctx->y = 0;
51-
for (counter = 0; counter < 256; counter++)
52-
state[counter] = (u8)counter;
53-
keyindex = 0;
54-
stateindex = 0;
55-
for (counter = 0; counter < 256; counter++) {
56-
t = state[counter];
57-
stateindex = (stateindex + key[keyindex] + t) & 0xff;
58-
u = state[stateindex];
59-
state[stateindex] = (u8)t;
60-
state[counter] = (u8)u;
61-
if (++keyindex >= key_len)
62-
keyindex = 0;
63-
}
64-
}
65-
66-
static u32 arcfour_byte(struct arc4context *parc4ctx)
67-
{
68-
u32 x;
69-
u32 y;
70-
u32 sx, sy;
71-
u8 *state;
72-
73-
state = parc4ctx->state;
74-
x = (parc4ctx->x + 1) & 0xff;
75-
sx = state[x];
76-
y = (sx + parc4ctx->y) & 0xff;
77-
sy = state[y];
78-
parc4ctx->x = x;
79-
parc4ctx->y = y;
80-
state[y] = (u8)sx;
81-
state[x] = (u8)sy;
82-
return state[(sx + sy) & 0xff];
83-
}
84-
85-
static void arcfour_encrypt(struct arc4context *parc4ctx, u8 *dest, u8 *src, u32 len)
86-
{
87-
u32 i;
88-
89-
for (i = 0; i < len; i++)
90-
dest[i] = src[i] ^ (unsigned char)arcfour_byte(parc4ctx);
91-
}
92-
9334
static signed int bcrc32initialized;
9435
static u32 crc32_table[256];
9536

@@ -149,7 +90,7 @@ void rtw_wep_encrypt(struct adapter *padapter, u8 *pxmitframe)
14990
{ /* exclude ICV */
15091

15192
unsigned char crc[4];
152-
struct arc4context mycontext;
93+
struct arc4_ctx mycontext;
15394

15495
signed int curfragnum, length;
15596
u32 keylength;
@@ -183,16 +124,16 @@ void rtw_wep_encrypt(struct adapter *padapter, u8 *pxmitframe)
183124

184125
*((__le32 *)crc) = getcrc32(payload, length);
185126

186-
arcfour_init(&mycontext, wepkey, 3+keylength);
187-
arcfour_encrypt(&mycontext, payload, payload, length);
188-
arcfour_encrypt(&mycontext, payload+length, crc, 4);
127+
arc4_setkey(&mycontext, wepkey, 3 + keylength);
128+
arc4_crypt(&mycontext, payload, payload, length);
129+
arc4_crypt(&mycontext, payload + length, crc, 4);
189130

190131
} else {
191132
length = pxmitpriv->frag_len-pattrib->hdrlen-pattrib->iv_len-pattrib->icv_len;
192133
*((__le32 *)crc) = getcrc32(payload, length);
193-
arcfour_init(&mycontext, wepkey, 3+keylength);
194-
arcfour_encrypt(&mycontext, payload, payload, length);
195-
arcfour_encrypt(&mycontext, payload+length, crc, 4);
134+
arc4_setkey(&mycontext, wepkey, 3 + keylength);
135+
arc4_crypt(&mycontext, payload, payload, length);
136+
arc4_crypt(&mycontext, payload + length, crc, 4);
196137

197138
pframe += pxmitpriv->frag_len;
198139
pframe = (u8 *)round_up((SIZE_PTR)(pframe), 4);
@@ -205,7 +146,7 @@ void rtw_wep_decrypt(struct adapter *padapter, u8 *precvframe)
205146
{
206147
/* exclude ICV */
207148
u8 crc[4];
208-
struct arc4context mycontext;
149+
struct arc4_ctx mycontext;
209150
signed int length;
210151
u32 keylength;
211152
u8 *pframe, *payload, *iv, wepkey[16];
@@ -229,8 +170,8 @@ void rtw_wep_decrypt(struct adapter *padapter, u8 *precvframe)
229170
payload = pframe+prxattrib->iv_len+prxattrib->hdrlen;
230171

231172
/* decrypt payload include icv */
232-
arcfour_init(&mycontext, wepkey, 3+keylength);
233-
arcfour_encrypt(&mycontext, payload, payload, length);
173+
arc4_setkey(&mycontext, wepkey, 3 + keylength);
174+
arc4_crypt(&mycontext, payload, payload, length);
234175

235176
/* calculate icv and compare the icv */
236177
*((u32 *)crc) = le32_to_cpu(getcrc32(payload, length-4));
@@ -578,7 +519,7 @@ u32 rtw_tkip_encrypt(struct adapter *padapter, u8 *pxmitframe)
578519
u8 ttkey[16];
579520
u8 crc[4];
580521
u8 hw_hdr_offset = 0;
581-
struct arc4context mycontext;
522+
struct arc4_ctx mycontext;
582523
signed int curfragnum, length;
583524

584525
u8 *pframe, *payload, *iv, *prwskey;
@@ -620,16 +561,16 @@ u32 rtw_tkip_encrypt(struct adapter *padapter, u8 *pxmitframe)
620561
length = pattrib->last_txcmdsz-pattrib->hdrlen-pattrib->iv_len-pattrib->icv_len;
621562
*((__le32 *)crc) = getcrc32(payload, length);/* modified by Amy*/
622563

623-
arcfour_init(&mycontext, rc4key, 16);
624-
arcfour_encrypt(&mycontext, payload, payload, length);
625-
arcfour_encrypt(&mycontext, payload+length, crc, 4);
564+
arc4_setkey(&mycontext, rc4key, 16);
565+
arc4_crypt(&mycontext, payload, payload, length);
566+
arc4_crypt(&mycontext, payload + length, crc, 4);
626567

627568
} else {
628569
length = pxmitpriv->frag_len-pattrib->hdrlen-pattrib->iv_len-pattrib->icv_len;
629570
*((__le32 *)crc) = getcrc32(payload, length);/* modified by Amy*/
630-
arcfour_init(&mycontext, rc4key, 16);
631-
arcfour_encrypt(&mycontext, payload, payload, length);
632-
arcfour_encrypt(&mycontext, payload+length, crc, 4);
571+
arc4_setkey(&mycontext, rc4key, 16);
572+
arc4_crypt(&mycontext, payload, payload, length);
573+
arc4_crypt(&mycontext, payload + length, crc, 4);
633574

634575
pframe += pxmitpriv->frag_len;
635576
pframe = (u8 *)round_up((SIZE_PTR)(pframe), 4);
@@ -649,7 +590,7 @@ u32 rtw_tkip_decrypt(struct adapter *padapter, u8 *precvframe)
649590
u8 rc4key[16];
650591
u8 ttkey[16];
651592
u8 crc[4];
652-
struct arc4context mycontext;
593+
struct arc4_ctx mycontext;
653594
signed int length;
654595

655596
u8 *pframe, *payload, *iv, *prwskey;
@@ -726,8 +667,8 @@ u32 rtw_tkip_decrypt(struct adapter *padapter, u8 *precvframe)
726667

727668
/* 4 decrypt payload include icv */
728669

729-
arcfour_init(&mycontext, rc4key, 16);
730-
arcfour_encrypt(&mycontext, payload, payload, length);
670+
arc4_setkey(&mycontext, rc4key, 16);
671+
arc4_crypt(&mycontext, payload, payload, length);
731672

732673
*((u32 *)crc) = le32_to_cpu(getcrc32(payload, length-4));
733674

0 commit comments

Comments
 (0)