LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
* [PATCH 0/3] staging: r8188eu: clean up dead code and use in-kernel arc4
@ 2021-09-03 19:04 Michael Straube
2021-09-03 19:04 ` [PATCH 1/3] staging: r8188eu: remove unused constant CRC32_POLY Michael Straube
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Michael Straube @ 2021-09-03 19:04 UTC (permalink / raw)
To: gregkh
Cc: Larry.Finger, phil, martin, fmdefrancesco, linux-staging,
linux-kernel, Michael Straube
This series removes the unused function rtw_use_tkipkey_handler()
and constant CRC32_POLY.
And it converts the driver to use in-kernel arc4 encryption instead
of a custom implementation for WEP and TKIP.
Tested with Inter-Tech DMG-02 and TP-Link TL-WA901N access point in
WEP and TKIP mode.
Michael Straube (3):
staging: r8188eu: remove unused constant CRC32_POLY
staging: r8188eu: use in-kernel arc4 encryption
staging: r8188eu: remove rtw_use_tkipkey_handler()
drivers/staging/r8188eu/core/rtw_security.c | 123 +++---------------
.../staging/r8188eu/include/rtw_security.h | 6 +-
2 files changed, 25 insertions(+), 104 deletions(-)
--
2.33.0
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH 1/3] staging: r8188eu: remove unused constant CRC32_POLY
2021-09-03 19:04 [PATCH 0/3] staging: r8188eu: clean up dead code and use in-kernel arc4 Michael Straube
@ 2021-09-03 19:04 ` Michael Straube
2021-09-03 19:04 ` [PATCH 2/3] staging: r8188eu: use in-kernel arc4 encryption Michael Straube
2021-09-03 19:04 ` [PATCH 3/3] staging: r8188eu: remove rtw_use_tkipkey_handler() Michael Straube
2 siblings, 0 replies; 4+ messages in thread
From: Michael Straube @ 2021-09-03 19:04 UTC (permalink / raw)
To: gregkh
Cc: Larry.Finger, phil, martin, fmdefrancesco, linux-staging,
linux-kernel, Michael Straube
Remove unused constant CRC32_POLY.
Signed-off-by: Michael Straube <straube.linux@gmail.com>
---
drivers/staging/r8188eu/core/rtw_security.c | 2 --
1 file changed, 2 deletions(-)
diff --git a/drivers/staging/r8188eu/core/rtw_security.c b/drivers/staging/r8188eu/core/rtw_security.c
index 48f77c6cf43c..d0586af1abad 100644
--- a/drivers/staging/r8188eu/core/rtw_security.c
+++ b/drivers/staging/r8188eu/core/rtw_security.c
@@ -10,8 +10,6 @@
/* WEP related ===== */
-#define CRC32_POLY 0x04c11db7
-
struct arc4context {
u32 x;
u32 y;
--
2.33.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 2/3] staging: r8188eu: use in-kernel arc4 encryption
2021-09-03 19:04 [PATCH 0/3] staging: r8188eu: clean up dead code and use in-kernel arc4 Michael Straube
2021-09-03 19:04 ` [PATCH 1/3] staging: r8188eu: remove unused constant CRC32_POLY Michael Straube
@ 2021-09-03 19:04 ` Michael Straube
2021-09-03 19:04 ` [PATCH 3/3] staging: r8188eu: remove rtw_use_tkipkey_handler() Michael Straube
2 siblings, 0 replies; 4+ messages in thread
From: Michael Straube @ 2021-09-03 19:04 UTC (permalink / raw)
To: gregkh
Cc: Larry.Finger, phil, martin, fmdefrancesco, linux-staging,
linux-kernel, Michael Straube
Replace custom arc4 implementation with in-kernel one.
Signed-off-by: Michael Straube <straube.linux@gmail.com>
---
drivers/staging/r8188eu/core/rtw_security.c | 102 ++++--------------
.../staging/r8188eu/include/rtw_security.h | 5 +
2 files changed, 25 insertions(+), 82 deletions(-)
diff --git a/drivers/staging/r8188eu/core/rtw_security.c b/drivers/staging/r8188eu/core/rtw_security.c
index d0586af1abad..a7f769048a44 100644
--- a/drivers/staging/r8188eu/core/rtw_security.c
+++ b/drivers/staging/r8188eu/core/rtw_security.c
@@ -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));
diff --git a/drivers/staging/r8188eu/include/rtw_security.h b/drivers/staging/r8188eu/include/rtw_security.h
index 1fc1a4f30eec..8ff583cdc0a6 100644
--- a/drivers/staging/r8188eu/include/rtw_security.h
+++ b/drivers/staging/r8188eu/include/rtw_security.h
@@ -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 */
--
2.33.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 3/3] staging: r8188eu: remove rtw_use_tkipkey_handler()
2021-09-03 19:04 [PATCH 0/3] staging: r8188eu: clean up dead code and use in-kernel arc4 Michael Straube
2021-09-03 19:04 ` [PATCH 1/3] staging: r8188eu: remove unused constant CRC32_POLY Michael Straube
2021-09-03 19:04 ` [PATCH 2/3] staging: r8188eu: use in-kernel arc4 encryption Michael Straube
@ 2021-09-03 19:04 ` Michael Straube
2 siblings, 0 replies; 4+ messages in thread
From: Michael Straube @ 2021-09-03 19:04 UTC (permalink / raw)
To: gregkh
Cc: Larry.Finger, phil, martin, fmdefrancesco, linux-staging,
linux-kernel, Michael Straube
Function rtw_use_tkipkey_handler() is unused, remove it.
Signed-off-by: Michael Straube <straube.linux@gmail.com>
---
drivers/staging/r8188eu/core/rtw_security.c | 19 -------------------
.../staging/r8188eu/include/rtw_security.h | 1 -
2 files changed, 20 deletions(-)
diff --git a/drivers/staging/r8188eu/core/rtw_security.c b/drivers/staging/r8188eu/core/rtw_security.c
index a7f769048a44..82987255400a 100644
--- a/drivers/staging/r8188eu/core/rtw_security.c
+++ b/drivers/staging/r8188eu/core/rtw_security.c
@@ -1568,22 +1568,3 @@ do { \
d##2 = TE0(s##2) ^ TE1(s##3) ^ TE2(s##0) ^ TE3(s##1) ^ rk[4 * i + 2]; \
d##3 = TE0(s##3) ^ TE1(s##0) ^ TE2(s##1) ^ TE3(s##2) ^ rk[4 * i + 3]; \
} while (0);
-
-/**
- * omac1_aes_128 - One-Key CBC MAC (OMAC1) hash with AES-128 (aka AES-CMAC)
- * @key: 128-bit key for the hash operation
- * @data: Data buffer for which a MAC is determined
- * @data_len: Length of data buffer in bytes
- * @mac: Buffer for MAC (128 bits, i.e., 16 bytes)
- * Returns: 0 on success, -1 on failure
- *
- * This is a mode for using block cipher (AES in this case) for authentication.
- * OMAC1 was standardized with the name CMAC by NIST in a Special Publication
- * (SP) 800-38B.
- */
-void rtw_use_tkipkey_handler(void *FunctionContext)
-{
- struct adapter *padapter = (struct adapter *)FunctionContext;
-
- padapter->securitypriv.busetkipkey = true;
-}
diff --git a/drivers/staging/r8188eu/include/rtw_security.h b/drivers/staging/r8188eu/include/rtw_security.h
index 8ff583cdc0a6..9bbda86a6641 100644
--- a/drivers/staging/r8188eu/include/rtw_security.h
+++ b/drivers/staging/r8188eu/include/rtw_security.h
@@ -341,6 +341,5 @@ void rtw_wep_encrypt(struct adapter *padapter, struct xmit_frame *pxmitframe);
u32 rtw_aes_decrypt(struct adapter *padapter, struct recv_frame *precvframe);
u32 rtw_tkip_decrypt(struct adapter *padapter, struct recv_frame *precvframe);
void rtw_wep_decrypt(struct adapter *padapter, struct recv_frame *precvframe);
-void rtw_use_tkipkey_handler(void *FunctionContext);
#endif /* __RTL871X_SECURITY_H_ */
--
2.33.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
end of thread, other threads:[~2021-09-03 19:05 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-03 19:04 [PATCH 0/3] staging: r8188eu: clean up dead code and use in-kernel arc4 Michael Straube
2021-09-03 19:04 ` [PATCH 1/3] staging: r8188eu: remove unused constant CRC32_POLY Michael Straube
2021-09-03 19:04 ` [PATCH 2/3] staging: r8188eu: use in-kernel arc4 encryption Michael Straube
2021-09-03 19:04 ` [PATCH 3/3] staging: r8188eu: remove rtw_use_tkipkey_handler() Michael Straube
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).