LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
* [PATCH v4 0/2] staging: rtl8188eu: Replace a custom function with crc32_le()
@ 2021-07-23 19:26 Fabio M. De Francesco
2021-07-23 19:26 ` [PATCH v4 1/2] " Fabio M. De Francesco
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Fabio M. De Francesco @ 2021-07-23 19:26 UTC (permalink / raw)
To: Larry Finger, Greg Kroah-Hartman, linux-staging, linux-kernel,
David Laight
Cc: Fabio M. De Francesco
Use kernel API crc32_le() in place of the custom getcrc32(). Remove no
more used functions and variables after the changes made by patch 1/2.
Fabio M. De Francesco (2):
staging: rtl8188eu: Replace a custom function with crc32_le()
staging: rtl8188eu: Remove no more used functions and variables
drivers/staging/rtl8188eu/core/rtw_security.c | 81 +++++--------------
1 file changed, 19 insertions(+), 62 deletions(-)
--
2.32.0
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH v4 1/2] staging: rtl8188eu: Replace a custom function with crc32_le()
2021-07-23 19:26 [PATCH v4 0/2] staging: rtl8188eu: Replace a custom function with crc32_le() Fabio M. De Francesco
@ 2021-07-23 19:26 ` Fabio M. De Francesco
2021-07-23 19:26 ` [PATCH v4 2/2] staging: rtl8188eu: Remove no more used functions and variables Fabio M. De Francesco
2021-07-27 13:17 ` [PATCH v4 0/2] staging: rtl8188eu: Replace a custom function with crc32_le() Greg Kroah-Hartman
2 siblings, 0 replies; 5+ messages in thread
From: Fabio M. De Francesco @ 2021-07-23 19:26 UTC (permalink / raw)
To: Larry Finger, Greg Kroah-Hartman, linux-staging, linux-kernel,
David Laight
Cc: Fabio M. De Francesco
Use crc32_le() in place of the custom getcrc32().
Signed-off-by: Fabio M. De Francesco <fmdefrancesco@gmail.com>
---
v3 --> v4:
According to a suggestion of David Laight, kill the casts of crc to __le32.
v2 --> v3:
Join two related patches in a series because they must be applied in
order (first 1/2, then 2/2). Rebase to the current Greg K-H's tree and resend.
v1 --> v2:
Use cpu_to_le32() to assign native endian return value of crc32_le to
crc in little endian byte order.
drivers/staging/rtl8188eu/core/rtw_security.c | 45 ++++++++-----------
1 file changed, 19 insertions(+), 26 deletions(-)
diff --git a/drivers/staging/rtl8188eu/core/rtw_security.c b/drivers/staging/rtl8188eu/core/rtw_security.c
index 1b2cb6196463..7001f24f118d 100644
--- a/drivers/staging/rtl8188eu/core/rtw_security.c
+++ b/drivers/staging/rtl8188eu/core/rtw_security.c
@@ -11,6 +11,7 @@
#include <wifi.h>
#include <osdep_intf.h>
#include <net/lib80211.h>
+#include <linux/types.h>
/* WEP related ===== */
@@ -111,21 +112,6 @@ static void crc32_init(void)
bcrc32initialized = 1;
}
-static __le32 getcrc32(u8 *buf, int len)
-{
- u8 *p;
- u32 crc;
-
- if (bcrc32initialized == 0)
- crc32_init();
-
- crc = 0xffffffff; /* preload shift register, per CRC-32 spec */
-
- for (p = buf; len > 0; ++p, --len)
- crc = crc32_table[(crc ^ *p) & 0xff] ^ (crc >> 8);
- return cpu_to_le32(~crc); /* transmit complement, per CRC-32 spec */
-}
-
/* Need to consider the fragment situation */
void rtw_wep_encrypt(struct adapter *padapter, struct xmit_frame *pxmitframe)
{
@@ -564,7 +550,10 @@ u32 rtw_tkip_encrypt(struct adapter *padapter, struct xmit_frame *pxmitframe)
u32 pnh;
u8 rc4key[16];
u8 ttkey[16];
- u8 crc[4];
+ union {
+ __le32 f0;
+ u8 f1[4];
+ } crc;
u8 hw_hdr_offset = 0;
struct arc4context mycontext;
int curfragnum, length;
@@ -609,17 +598,18 @@ u32 rtw_tkip_encrypt(struct adapter *padapter, struct xmit_frame *pxmitframe)
if ((curfragnum + 1) == pattrib->nr_frags) { /* 4 the last fragment */
length = pattrib->last_txcmdsz - pattrib->hdrlen - pattrib->iv_len - pattrib->icv_len;
- *((__le32 *)crc) = getcrc32(payload, length);/* modified by Amy*/
+ 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, 4);
+ arcfour_encrypt(&mycontext, payload + length, crc.f1, 4);
} else {
length = pxmitpriv->frag_len - pattrib->hdrlen - pattrib->iv_len - pattrib->icv_len;
- *((__le32 *)crc) = getcrc32(payload, length);/* modified by Amy*/
+ 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, 4);
+ arcfour_encrypt(&mycontext, payload + length, crc.f1, 4);
pframe += pxmitpriv->frag_len;
pframe = (u8 *)round_up((size_t)(pframe), 4);
@@ -639,7 +629,10 @@ u32 rtw_tkip_decrypt(struct adapter *padapter, struct recv_frame *precvframe)
u32 pnh;
u8 rc4key[16];
u8 ttkey[16];
- u8 crc[4];
+ union {
+ __le32 f0;
+ u8 f1[4];
+ } crc;
struct arc4context mycontext;
int length;
u8 *pframe, *payload, *iv, *prwskey;
@@ -682,12 +675,12 @@ u32 rtw_tkip_decrypt(struct adapter *padapter, struct recv_frame *precvframe)
arcfour_init(&mycontext, rc4key, 16);
arcfour_encrypt(&mycontext, payload, payload, length);
- *((__le32 *)crc) = getcrc32(payload, length - 4);
+ crc.f0 = cpu_to_le32(~crc32_le(~0, payload, length - 4));
- if (crc[3] != payload[length - 1] ||
- crc[2] != payload[length - 2] ||
- crc[1] != payload[length - 3] ||
- crc[0] != payload[length - 4])
+ if (crc.f1[3] != payload[length - 1] ||
+ crc.f1[2] != payload[length - 2] ||
+ crc.f1[1] != payload[length - 3] ||
+ crc.f1[0] != payload[length - 4])
res = _FAIL;
} else {
res = _FAIL;
--
2.32.0
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH v4 2/2] staging: rtl8188eu: Remove no more used functions and variables
2021-07-23 19:26 [PATCH v4 0/2] staging: rtl8188eu: Replace a custom function with crc32_le() Fabio M. De Francesco
2021-07-23 19:26 ` [PATCH v4 1/2] " Fabio M. De Francesco
@ 2021-07-23 19:26 ` Fabio M. De Francesco
2021-07-27 13:17 ` [PATCH v4 0/2] staging: rtl8188eu: Replace a custom function with crc32_le() Greg Kroah-Hartman
2 siblings, 0 replies; 5+ messages in thread
From: Fabio M. De Francesco @ 2021-07-23 19:26 UTC (permalink / raw)
To: Larry Finger, Greg Kroah-Hartman, linux-staging, linux-kernel,
David Laight
Cc: Fabio M. De Francesco
Remove the functions and variables from rtw_security.c that are no more
necessary since the patch that replaces getcrc32() with crc32_le().
Signed-off-by: Fabio M. De Francesco <fmdefrancesco@gmail.com>
---
v3 --> v4:
No changes.
v2 --> v3:
Join two related patches in a series because they must be applied in
order (first 1/2, then 2/2). Rebase to the current Greg K-H's tree and resend.
v1 -> v2:
Update the commit message with the URL of v2 of the above-mentioned
patch.
drivers/staging/rtl8188eu/core/rtw_security.c | 36 -------------------
1 file changed, 36 deletions(-)
diff --git a/drivers/staging/rtl8188eu/core/rtw_security.c b/drivers/staging/rtl8188eu/core/rtw_security.c
index 7001f24f118d..7185c1ae2ab8 100644
--- a/drivers/staging/rtl8188eu/core/rtw_security.c
+++ b/drivers/staging/rtl8188eu/core/rtw_security.c
@@ -76,42 +76,6 @@ static void arcfour_encrypt(struct arc4context *parc4ctx, u8 *dest, u8 *src, u32
dest[i] = src[i] ^ (unsigned char)arcfour_byte(parc4ctx);
}
-static int bcrc32initialized;
-static u32 crc32_table[256];
-
-static u8 crc32_reverseBit(u8 data)
-{
- return (u8)((data << 7) & 0x80) | ((data << 5) & 0x40) | ((data << 3) & 0x20) |
- ((data << 1) & 0x10) | ((data >> 1) & 0x08) | ((data >> 3) & 0x04) |
- ((data >> 5) & 0x02) | ((data >> 7) & 0x01);
-}
-
-static void crc32_init(void)
-{
- int i, j;
- u32 c;
- u8 *p = (u8 *)&c, *p1;
- u8 k;
-
- if (bcrc32initialized == 1)
- return;
-
- c = 0x12340000;
-
- for (i = 0; i < 256; ++i) {
- k = crc32_reverseBit((u8)i);
- for (c = ((u32)k) << 24, j = 8; j > 0; --j)
- c = c & 0x80000000 ? (c << 1) ^ CRC32_POLY : (c << 1);
- p1 = (u8 *)&crc32_table[i];
-
- p1[0] = crc32_reverseBit(p[3]);
- p1[1] = crc32_reverseBit(p[2]);
- p1[2] = crc32_reverseBit(p[1]);
- p1[3] = crc32_reverseBit(p[0]);
- }
- bcrc32initialized = 1;
-}
-
/* Need to consider the fragment situation */
void rtw_wep_encrypt(struct adapter *padapter, struct xmit_frame *pxmitframe)
{
--
2.32.0
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v4 0/2] staging: rtl8188eu: Replace a custom function with crc32_le()
2021-07-23 19:26 [PATCH v4 0/2] staging: rtl8188eu: Replace a custom function with crc32_le() Fabio M. De Francesco
2021-07-23 19:26 ` [PATCH v4 1/2] " Fabio M. De Francesco
2021-07-23 19:26 ` [PATCH v4 2/2] staging: rtl8188eu: Remove no more used functions and variables Fabio M. De Francesco
@ 2021-07-27 13:17 ` Greg Kroah-Hartman
2021-07-27 23:41 ` Fabio M. De Francesco
2 siblings, 1 reply; 5+ messages in thread
From: Greg Kroah-Hartman @ 2021-07-27 13:17 UTC (permalink / raw)
To: Fabio M. De Francesco
Cc: Larry Finger, linux-staging, linux-kernel, David Laight
On Fri, Jul 23, 2021 at 09:26:18PM +0200, Fabio M. De Francesco wrote:
> Use kernel API crc32_le() in place of the custom getcrc32(). Remove no
> more used functions and variables after the changes made by patch 1/2.
>
> Fabio M. De Francesco (2):
> staging: rtl8188eu: Replace a custom function with crc32_le()
> staging: rtl8188eu: Remove no more used functions and variables
>
> drivers/staging/rtl8188eu/core/rtw_security.c | 81 +++++--------------
> 1 file changed, 19 insertions(+), 62 deletions(-)
Much nicer, thanks!
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v4 0/2] staging: rtl8188eu: Replace a custom function with crc32_le()
2021-07-27 13:17 ` [PATCH v4 0/2] staging: rtl8188eu: Replace a custom function with crc32_le() Greg Kroah-Hartman
@ 2021-07-27 23:41 ` Fabio M. De Francesco
0 siblings, 0 replies; 5+ messages in thread
From: Fabio M. De Francesco @ 2021-07-27 23:41 UTC (permalink / raw)
To: Greg Kroah-Hartman
Cc: Larry Finger, linux-staging, linux-kernel, David Laight
On Tuesday, July 27, 2021 3:17:37 PM CEST Greg Kroah-Hartman wrote:
> On Fri, Jul 23, 2021 at 09:26:18PM +0200, Fabio M. De Francesco wrote:
> > Use kernel API crc32_le() in place of the custom getcrc32(). Remove no
> > more used functions and variables after the changes made by patch 1/2.
> >
> > Fabio M. De Francesco (2):
> > staging: rtl8188eu: Replace a custom function with crc32_le()
> > staging: rtl8188eu: Remove no more used functions and variables
> >
> > drivers/staging/rtl8188eu/core/rtw_security.c | 81 +++++--------------
> > 1 file changed, 19 insertions(+), 62 deletions(-)
>
> Much nicer, thanks!
Glad you appreciated my solution to this problem. There is another driver
(rtl8723bs) that needs a change like this. I will post a similar patch by
tomorrow.
Thanks very much,
Fabio
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2021-07-27 23:41 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-23 19:26 [PATCH v4 0/2] staging: rtl8188eu: Replace a custom function with crc32_le() Fabio M. De Francesco
2021-07-23 19:26 ` [PATCH v4 1/2] " Fabio M. De Francesco
2021-07-23 19:26 ` [PATCH v4 2/2] staging: rtl8188eu: Remove no more used functions and variables Fabio M. De Francesco
2021-07-27 13:17 ` [PATCH v4 0/2] staging: rtl8188eu: Replace a custom function with crc32_le() Greg Kroah-Hartman
2021-07-27 23:41 ` Fabio M. De Francesco
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).