Commit 1b11e893 authored by Fabio Aiuto's avatar Fabio Aiuto Committed by Greg Kroah-Hartman

staging: rtl8723bs: replace private arc4 encryption with in-kernel one

replace private arc4 encryption with in-kernel one.
Signed-off-by: default avatarFabio Aiuto <fabioaiuto83@gmail.com>
Link: https://lore.kernel.org/r/af960dc728f039d64f4fb28fcece3ca92d24fbe4.1620372584.git.fabioaiuto83@gmail.comSigned-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 8adffa4b
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include <drv_types.h> #include <drv_types.h>
#include <rtw_debug.h> #include <rtw_debug.h>
#include <crypto/aes.h> #include <crypto/aes.h>
#include <crypto/arc4.h>
static const char * const _security_type_str[] = { static const char * const _security_type_str[] = {
"N/A", "N/A",
...@@ -30,66 +31,6 @@ const char *security_type_str(u8 value) ...@@ -30,66 +31,6 @@ const char *security_type_str(u8 value)
/* WEP related ===== */ /* 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 signed int bcrc32initialized;
static u32 crc32_table[256]; static u32 crc32_table[256];
...@@ -149,7 +90,7 @@ void rtw_wep_encrypt(struct adapter *padapter, u8 *pxmitframe) ...@@ -149,7 +90,7 @@ void rtw_wep_encrypt(struct adapter *padapter, u8 *pxmitframe)
{ /* exclude ICV */ { /* exclude ICV */
unsigned char crc[4]; unsigned char crc[4];
struct arc4context mycontext; struct arc4_ctx mycontext;
signed int curfragnum, length; signed int curfragnum, length;
u32 keylength; u32 keylength;
...@@ -183,16 +124,16 @@ void rtw_wep_encrypt(struct adapter *padapter, u8 *pxmitframe) ...@@ -183,16 +124,16 @@ void rtw_wep_encrypt(struct adapter *padapter, u8 *pxmitframe)
*((__le32 *)crc) = getcrc32(payload, length); *((__le32 *)crc) = getcrc32(payload, length);
arcfour_init(&mycontext, wepkey, 3+keylength); arc4_setkey(&mycontext, wepkey, 3 + keylength);
arcfour_encrypt(&mycontext, payload, payload, length); arc4_crypt(&mycontext, payload, payload, length);
arcfour_encrypt(&mycontext, payload+length, crc, 4); arc4_crypt(&mycontext, payload + length, crc, 4);
} else { } else {
length = pxmitpriv->frag_len-pattrib->hdrlen-pattrib->iv_len-pattrib->icv_len; length = pxmitpriv->frag_len-pattrib->hdrlen-pattrib->iv_len-pattrib->icv_len;
*((__le32 *)crc) = getcrc32(payload, length); *((__le32 *)crc) = getcrc32(payload, length);
arcfour_init(&mycontext, wepkey, 3+keylength); arc4_setkey(&mycontext, wepkey, 3 + keylength);
arcfour_encrypt(&mycontext, payload, payload, length); arc4_crypt(&mycontext, payload, payload, length);
arcfour_encrypt(&mycontext, payload+length, crc, 4); arc4_crypt(&mycontext, payload + length, crc, 4);
pframe += pxmitpriv->frag_len; pframe += pxmitpriv->frag_len;
pframe = (u8 *)round_up((SIZE_PTR)(pframe), 4); pframe = (u8 *)round_up((SIZE_PTR)(pframe), 4);
...@@ -205,7 +146,7 @@ void rtw_wep_decrypt(struct adapter *padapter, u8 *precvframe) ...@@ -205,7 +146,7 @@ void rtw_wep_decrypt(struct adapter *padapter, u8 *precvframe)
{ {
/* exclude ICV */ /* exclude ICV */
u8 crc[4]; u8 crc[4];
struct arc4context mycontext; struct arc4_ctx mycontext;
signed int length; signed int length;
u32 keylength; u32 keylength;
u8 *pframe, *payload, *iv, wepkey[16]; u8 *pframe, *payload, *iv, wepkey[16];
...@@ -229,8 +170,8 @@ void rtw_wep_decrypt(struct adapter *padapter, u8 *precvframe) ...@@ -229,8 +170,8 @@ void rtw_wep_decrypt(struct adapter *padapter, u8 *precvframe)
payload = pframe+prxattrib->iv_len+prxattrib->hdrlen; payload = pframe+prxattrib->iv_len+prxattrib->hdrlen;
/* decrypt payload include icv */ /* decrypt payload include icv */
arcfour_init(&mycontext, wepkey, 3+keylength); arc4_setkey(&mycontext, wepkey, 3 + keylength);
arcfour_encrypt(&mycontext, payload, payload, length); arc4_crypt(&mycontext, payload, payload, length);
/* calculate icv and compare the icv */ /* calculate icv and compare the icv */
*((u32 *)crc) = le32_to_cpu(getcrc32(payload, length-4)); *((u32 *)crc) = le32_to_cpu(getcrc32(payload, length-4));
...@@ -578,7 +519,7 @@ u32 rtw_tkip_encrypt(struct adapter *padapter, u8 *pxmitframe) ...@@ -578,7 +519,7 @@ u32 rtw_tkip_encrypt(struct adapter *padapter, u8 *pxmitframe)
u8 ttkey[16]; u8 ttkey[16];
u8 crc[4]; u8 crc[4];
u8 hw_hdr_offset = 0; u8 hw_hdr_offset = 0;
struct arc4context mycontext; struct arc4_ctx mycontext;
signed int curfragnum, length; signed int curfragnum, length;
u8 *pframe, *payload, *iv, *prwskey; u8 *pframe, *payload, *iv, *prwskey;
...@@ -620,16 +561,16 @@ u32 rtw_tkip_encrypt(struct adapter *padapter, u8 *pxmitframe) ...@@ -620,16 +561,16 @@ u32 rtw_tkip_encrypt(struct adapter *padapter, u8 *pxmitframe)
length = pattrib->last_txcmdsz-pattrib->hdrlen-pattrib->iv_len-pattrib->icv_len; length = pattrib->last_txcmdsz-pattrib->hdrlen-pattrib->iv_len-pattrib->icv_len;
*((__le32 *)crc) = getcrc32(payload, length);/* modified by Amy*/ *((__le32 *)crc) = getcrc32(payload, length);/* modified by Amy*/
arcfour_init(&mycontext, rc4key, 16); arc4_setkey(&mycontext, rc4key, 16);
arcfour_encrypt(&mycontext, payload, payload, length); arc4_crypt(&mycontext, payload, payload, length);
arcfour_encrypt(&mycontext, payload+length, crc, 4); arc4_crypt(&mycontext, payload + length, crc, 4);
} else { } else {
length = pxmitpriv->frag_len-pattrib->hdrlen-pattrib->iv_len-pattrib->icv_len; length = pxmitpriv->frag_len-pattrib->hdrlen-pattrib->iv_len-pattrib->icv_len;
*((__le32 *)crc) = getcrc32(payload, length);/* modified by Amy*/ *((__le32 *)crc) = getcrc32(payload, length);/* modified by Amy*/
arcfour_init(&mycontext, rc4key, 16); arc4_setkey(&mycontext, rc4key, 16);
arcfour_encrypt(&mycontext, payload, payload, length); arc4_crypt(&mycontext, payload, payload, length);
arcfour_encrypt(&mycontext, payload+length, crc, 4); arc4_crypt(&mycontext, payload + length, crc, 4);
pframe += pxmitpriv->frag_len; pframe += pxmitpriv->frag_len;
pframe = (u8 *)round_up((SIZE_PTR)(pframe), 4); pframe = (u8 *)round_up((SIZE_PTR)(pframe), 4);
...@@ -649,7 +590,7 @@ u32 rtw_tkip_decrypt(struct adapter *padapter, u8 *precvframe) ...@@ -649,7 +590,7 @@ u32 rtw_tkip_decrypt(struct adapter *padapter, u8 *precvframe)
u8 rc4key[16]; u8 rc4key[16];
u8 ttkey[16]; u8 ttkey[16];
u8 crc[4]; u8 crc[4];
struct arc4context mycontext; struct arc4_ctx mycontext;
signed int length; signed int length;
u8 *pframe, *payload, *iv, *prwskey; u8 *pframe, *payload, *iv, *prwskey;
...@@ -726,8 +667,8 @@ u32 rtw_tkip_decrypt(struct adapter *padapter, u8 *precvframe) ...@@ -726,8 +667,8 @@ u32 rtw_tkip_decrypt(struct adapter *padapter, u8 *precvframe)
/* 4 decrypt payload include icv */ /* 4 decrypt payload include icv */
arcfour_init(&mycontext, rc4key, 16); arc4_setkey(&mycontext, rc4key, 16);
arcfour_encrypt(&mycontext, payload, payload, length); arc4_crypt(&mycontext, payload, payload, length);
*((u32 *)crc) = le32_to_cpu(getcrc32(payload, length-4)); *((u32 *)crc) = le32_to_cpu(getcrc32(payload, length-4));
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment