mirror of
https://github.com/hardkernel/linux.git
synced 2026-06-08 03:40:35 +09:00
staging: r8188eu: use in-kernel arc4 encryption
Replace custom arc4 implementation with in-kernel one. Signed-off-by: Michael Straube <straube.linux@gmail.com> Link: https://lore.kernel.org/r/20210903190444.15585-3-straube.linux@gmail.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
committed by
Greg Kroah-Hartman
parent
c96bb23d71
commit
24e11a227d
@@ -10,68 +10,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);
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
Need to consider the fragment situation
|
||||
*/
|
||||
@@ -81,7 +19,6 @@ void rtw_wep_encrypt(struct adapter *padapter, struct xmit_frame *pxmitframe)
|
||||
__le32 f0;
|
||||
u8 f1[4];
|
||||
} crc;
|
||||
struct arc4context mycontext;
|
||||
|
||||
int curfragnum, length;
|
||||
u32 keylength;
|
||||
@@ -92,6 +29,7 @@ void rtw_wep_encrypt(struct adapter *padapter, struct xmit_frame *pxmitframe)
|
||||
struct pkt_attrib *pattrib = &pxmitframe->attrib;
|
||||
struct security_priv *psecuritypriv = &padapter->securitypriv;
|
||||
struct xmit_priv *pxmitpriv = &padapter->xmitpriv;
|
||||
struct arc4_ctx *ctx = &psecuritypriv->xmit_arc4_ctx;
|
||||
|
||||
if (!pxmitframe->buf_addr)
|
||||
return;
|
||||
@@ -114,15 +52,15 @@ void rtw_wep_encrypt(struct adapter *padapter, struct xmit_frame *pxmitframe)
|
||||
|
||||
crc.f0 = cpu_to_le32(~crc32_le(~0, payload, length));
|
||||
|
||||
arcfour_init(&mycontext, wepkey, 3 + keylength);
|
||||
arcfour_encrypt(&mycontext, payload, payload, length);
|
||||
arcfour_encrypt(&mycontext, payload + length, crc.f1, 4);
|
||||
arc4_setkey(ctx, wepkey, 3 + keylength);
|
||||
arc4_crypt(ctx, payload, payload, length);
|
||||
arc4_crypt(ctx, payload + length, crc.f1, 4);
|
||||
} else {
|
||||
length = pxmitpriv->frag_len - pattrib->hdrlen - pattrib->iv_len - pattrib->icv_len;
|
||||
crc.f0 = cpu_to_le32(~crc32_le(~0, payload, length));
|
||||
arcfour_init(&mycontext, wepkey, 3 + keylength);
|
||||
arcfour_encrypt(&mycontext, payload, payload, length);
|
||||
arcfour_encrypt(&mycontext, payload + length, crc.f1, 4);
|
||||
arc4_setkey(ctx, wepkey, 3 + keylength);
|
||||
arc4_crypt(ctx, payload, payload, length);
|
||||
arc4_crypt(ctx, payload + length, crc.f1, 4);
|
||||
|
||||
pframe += pxmitpriv->frag_len;
|
||||
pframe = (u8 *)RND4((size_t)(pframe));
|
||||
@@ -135,13 +73,13 @@ void rtw_wep_encrypt(struct adapter *padapter, struct xmit_frame *pxmitframe)
|
||||
void rtw_wep_decrypt(struct adapter *padapter, struct recv_frame *precvframe)
|
||||
{
|
||||
/* exclude ICV */
|
||||
struct arc4context mycontext;
|
||||
int length;
|
||||
u32 keylength;
|
||||
u8 *pframe, *payload, *iv, wepkey[16];
|
||||
u8 keyindex;
|
||||
struct rx_pkt_attrib *prxattrib = &precvframe->attrib;
|
||||
struct security_priv *psecuritypriv = &padapter->securitypriv;
|
||||
struct arc4_ctx *ctx = &psecuritypriv->recv_arc4_ctx;
|
||||
|
||||
pframe = precvframe->rx_data;
|
||||
|
||||
@@ -157,8 +95,8 @@ void rtw_wep_decrypt(struct adapter *padapter, struct recv_frame *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(ctx, wepkey, 3 + keylength);
|
||||
arc4_crypt(ctx, payload, payload, length);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -509,7 +447,6 @@ u32 rtw_tkip_encrypt(struct adapter *padapter, struct xmit_frame *pxmitframe)
|
||||
u8 f1[4];
|
||||
} crc;
|
||||
u8 hw_hdr_offset = 0;
|
||||
struct arc4context mycontext;
|
||||
int curfragnum, length;
|
||||
|
||||
u8 *pframe, *payload, *iv, *prwskey;
|
||||
@@ -518,6 +455,7 @@ u32 rtw_tkip_encrypt(struct adapter *padapter, struct xmit_frame *pxmitframe)
|
||||
struct pkt_attrib *pattrib = &pxmitframe->attrib;
|
||||
struct security_priv *psecuritypriv = &padapter->securitypriv;
|
||||
struct xmit_priv *pxmitpriv = &padapter->xmitpriv;
|
||||
struct arc4_ctx *ctx = &psecuritypriv->xmit_arc4_ctx;
|
||||
u32 res = _SUCCESS;
|
||||
|
||||
if (!pxmitframe->buf_addr)
|
||||
@@ -554,16 +492,16 @@ u32 rtw_tkip_encrypt(struct adapter *padapter, struct xmit_frame *pxmitframe)
|
||||
length = pattrib->last_txcmdsz - pattrib->hdrlen - pattrib->iv_len - pattrib->icv_len;
|
||||
crc.f0 = cpu_to_le32(~crc32_le(~0, payload, length));
|
||||
|
||||
arcfour_init(&mycontext, rc4key, 16);
|
||||
arcfour_encrypt(&mycontext, payload, payload, length);
|
||||
arcfour_encrypt(&mycontext, payload + length, crc.f1, 4);
|
||||
arc4_setkey(ctx, rc4key, 16);
|
||||
arc4_crypt(ctx, payload, payload, length);
|
||||
arc4_crypt(ctx, payload + length, crc.f1, 4);
|
||||
} else {
|
||||
length = pxmitpriv->frag_len - pattrib->hdrlen - pattrib->iv_len - pattrib->icv_len;
|
||||
crc.f0 = cpu_to_le32(~crc32_le(~0, payload, length));
|
||||
|
||||
arcfour_init(&mycontext, rc4key, 16);
|
||||
arcfour_encrypt(&mycontext, payload, payload, length);
|
||||
arcfour_encrypt(&mycontext, payload + length, crc.f1, 4);
|
||||
arc4_setkey(ctx, rc4key, 16);
|
||||
arc4_crypt(ctx, payload, payload, length);
|
||||
arc4_crypt(ctx, payload + length, crc.f1, 4);
|
||||
|
||||
pframe += pxmitpriv->frag_len;
|
||||
pframe = (u8 *)RND4((size_t)(pframe));
|
||||
@@ -588,7 +526,6 @@ u32 rtw_tkip_decrypt(struct adapter *padapter, struct recv_frame *precvframe)
|
||||
__le32 f0;
|
||||
u8 f1[4];
|
||||
} crc;
|
||||
struct arc4context mycontext;
|
||||
int length;
|
||||
|
||||
u8 *pframe, *payload, *iv, *prwskey;
|
||||
@@ -596,6 +533,7 @@ u32 rtw_tkip_decrypt(struct adapter *padapter, struct recv_frame *precvframe)
|
||||
struct sta_info *stainfo;
|
||||
struct rx_pkt_attrib *prxattrib = &precvframe->attrib;
|
||||
struct security_priv *psecuritypriv = &padapter->securitypriv;
|
||||
struct arc4_ctx *ctx = &psecuritypriv->recv_arc4_ctx;
|
||||
u32 res = _SUCCESS;
|
||||
|
||||
pframe = precvframe->rx_data;
|
||||
@@ -629,8 +567,8 @@ u32 rtw_tkip_decrypt(struct adapter *padapter, struct recv_frame *precvframe)
|
||||
|
||||
/* 4 decrypt payload include icv */
|
||||
|
||||
arcfour_init(&mycontext, rc4key, 16);
|
||||
arcfour_encrypt(&mycontext, payload, payload, length);
|
||||
arc4_setkey(ctx, rc4key, 16);
|
||||
arc4_crypt(ctx, payload, payload, length);
|
||||
|
||||
crc.f0 = cpu_to_le32(~crc32_le(~0, payload, length));
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
|
||||
#include "osdep_service.h"
|
||||
#include "drv_types.h"
|
||||
#include <crypto/arc4.h>
|
||||
|
||||
#define _NO_PRIVACY_ 0x0
|
||||
#define _WEP40_ 0x1
|
||||
@@ -106,6 +107,10 @@ struct security_priv {
|
||||
union Keytype dot118021XGrprxmickey[4];
|
||||
union pn48 dot11Grptxpn; /* PN48 used for Grp Key xmit.*/
|
||||
union pn48 dot11Grprxpn; /* PN48 used for Grp Key recv.*/
|
||||
|
||||
struct arc4_ctx xmit_arc4_ctx;
|
||||
struct arc4_ctx recv_arc4_ctx;
|
||||
|
||||
#ifdef CONFIG_88EU_AP_MODE
|
||||
/* extend security capabilities for AP_MODE */
|
||||
unsigned int dot8021xalg;/* 0:disable, 1:psk, 2:802.1x */
|
||||
|
||||
Reference in New Issue
Block a user