linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/2] staging: r8188eu: Use in-kernel API and remove no more needed symbols
@ 2021-07-30 10:37 Fabio M. De Francesco
  2021-07-30 10:37 ` [PATCH 1/2] staging: r8188eu: Replace a custom function with crc32_le() Fabio M. De Francesco
  2021-07-30 10:37 ` [PATCH 2/2] staging: r8188eu: Remove no more used functions and variables Fabio M. De Francesco
  0 siblings, 2 replies; 4+ messages in thread
From: Fabio M. De Francesco @ 2021-07-30 10:37 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Larry Finger, linux-staging, linux-kernel
  Cc: Fabio M. De Francesco

Use crc32_le() in-kernel API in place of the custom getcrc32(). Then
remove no more necessary functions and variables that were needed by
getcrc32().

Fabio M. De Francesco (2):
  staging: r8188eu: Replace a custom function with crc32_le()
  staging: r8188eu: Remove no more used functions and variables

 drivers/staging/r8188eu/core/rtw_security.c | 111 ++++++--------------
 1 file changed, 35 insertions(+), 76 deletions(-)

-- 
2.32.0


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 1/2] staging: r8188eu: Replace a custom function with crc32_le()
  2021-07-30 10:37 [PATCH 0/2] staging: r8188eu: Use in-kernel API and remove no more needed symbols Fabio M. De Francesco
@ 2021-07-30 10:37 ` Fabio M. De Francesco
  2021-07-30 10:37 ` [PATCH 2/2] staging: r8188eu: Remove no more used functions and variables Fabio M. De Francesco
  1 sibling, 0 replies; 4+ messages in thread
From: Fabio M. De Francesco @ 2021-07-30 10:37 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Larry Finger, linux-staging, linux-kernel
  Cc: Fabio M. De Francesco

Use crc32_le() in place of the custom getcrc32().

Signed-off-by: Fabio M. De Francesco <fmdefrancesco@gmail.com>
---
 drivers/staging/r8188eu/core/rtw_security.c | 74 ++++++++++-----------
 1 file changed, 35 insertions(+), 39 deletions(-)

diff --git a/drivers/staging/r8188eu/core/rtw_security.c b/drivers/staging/r8188eu/core/rtw_security.c
index 5df970994e23..9625beea4b3c 100644
--- a/drivers/staging/r8188eu/core/rtw_security.c
+++ b/drivers/staging/r8188eu/core/rtw_security.c
@@ -111,29 +111,15 @@ static void crc32_init(void)
 	}
 }
 
-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, u8 *pxmitframe)
 {	/*  exclude ICV */
-
-	unsigned char	crc[4];
+	union {
+		__le32 f0;
+		u8 f1[4];
+	} crc;
 	struct arc4context	 mycontext;
 
 	int	curfragnum, length;
@@ -167,17 +153,17 @@ void rtw_wep_encrypt(struct adapter *padapter, u8 *pxmitframe)
 			if ((curfragnum+1) == pattrib->nr_frags) {	/* the last fragment */
 				length = pattrib->last_txcmdsz-pattrib->hdrlen-pattrib->iv_len-pattrib->icv_len;
 
-				*((__le32 *)crc) = getcrc32(payload, length);
+				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, 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);
+				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, 4);
+				arcfour_encrypt(&mycontext, payload+length, crc.f1, 4);
 
 				pframe += pxmitpriv->frag_len;
 				pframe = (u8 *)RND4((size_t)(pframe));
@@ -190,7 +176,10 @@ void rtw_wep_encrypt(struct adapter *padapter, u8 *pxmitframe)
 void rtw_wep_decrypt(struct adapter  *padapter, u8 *precvframe)
 {
 	/*  exclude ICV */
-	u8	crc[4];
+	union {
+		__le32 f0;
+		u8 f1[4];
+	} crc;
 	struct arc4context	 mycontext;
 	int	length;
 	u32	keylength;
@@ -217,12 +206,12 @@ void rtw_wep_decrypt(struct adapter  *padapter, u8 *precvframe)
 		arcfour_encrypt(&mycontext, payload, payload,  length);
 
 		/* calculate icv and compare the icv */
-		*((__le32 *)crc) = getcrc32(payload, length - 4);
+		crc.f0 = cpu_to_le32(~crc32_le(~0, payload, length));
 
-		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]) {
 			RT_TRACE(_module_rtl871x_security_c_, _drv_err_,
 				 ("rtw_wep_decrypt:icv error crc (%4ph)!=payload (%4ph)\n",
 				 &crc, &payload[length-4]));
@@ -574,7 +563,10 @@ u32	rtw_tkip_encrypt(struct adapter *padapter, u8 *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;
@@ -624,17 +616,18 @@ u32	rtw_tkip_encrypt(struct adapter *padapter, u8 *pxmitframe)
 					RT_TRACE(_module_rtl871x_security_c_, _drv_info_,
 						 ("pattrib->iv_len=%x, pattrib->icv_len=%x\n",
 						 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 *)RND4((size_t)(pframe));
@@ -656,7 +649,10 @@ u32 rtw_tkip_decrypt(struct adapter *padapter, u8 *precvframe)
 	u32 pnh;
 	u8   rc4key[16];
 	u8   ttkey[16];
-	u8	crc[4];
+	union {
+		__le32 f0;
+		u8 f1[4];
+	} crc;
 	struct arc4context mycontext;
 	int			length;
 
@@ -702,12 +698,12 @@ u32 rtw_tkip_decrypt(struct adapter *padapter, u8 *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));
 
-			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]) {
 				RT_TRACE(_module_rtl871x_security_c_, _drv_err_,
 					 ("rtw_wep_decrypt:icv error crc (%4ph)!=payload (%4ph)\n",
 					 &crc, &payload[length-4]));
-- 
2.32.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 2/2] staging: r8188eu: Remove no more used functions and variables
  2021-07-30 10:37 [PATCH 0/2] staging: r8188eu: Use in-kernel API and remove no more needed symbols Fabio M. De Francesco
  2021-07-30 10:37 ` [PATCH 1/2] staging: r8188eu: Replace a custom function with crc32_le() Fabio M. De Francesco
@ 2021-07-30 10:37 ` Fabio M. De Francesco
  2021-07-30 18:51   ` Larry Finger
  1 sibling, 1 reply; 4+ messages in thread
From: Fabio M. De Francesco @ 2021-07-30 10:37 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Larry Finger, linux-staging, linux-kernel
  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>
---
 drivers/staging/r8188eu/core/rtw_security.c | 37 ---------------------
 1 file changed, 37 deletions(-)

diff --git a/drivers/staging/r8188eu/core/rtw_security.c b/drivers/staging/r8188eu/core/rtw_security.c
index 9625beea4b3c..136ba1e61dca 100644
--- a/drivers/staging/r8188eu/core/rtw_security.c
+++ b/drivers/staging/r8188eu/core/rtw_security.c
@@ -74,43 +74,6 @@ static void arcfour_encrypt(struct arc4context *parc4ctx, u8 *dest, u8 *src, u32
 
 }
 
-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)
-{
-	if (bcrc32initialized == 1) {
-		return;
-	} else {
-		int i, j;
-		u32 c;
-		u8 *p = (u8 *)&c, *p1;
-		u8 k;
-
-		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
 */
-- 
2.32.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH 2/2] staging: r8188eu: Remove no more used functions and variables
  2021-07-30 10:37 ` [PATCH 2/2] staging: r8188eu: Remove no more used functions and variables Fabio M. De Francesco
@ 2021-07-30 18:51   ` Larry Finger
  0 siblings, 0 replies; 4+ messages in thread
From: Larry Finger @ 2021-07-30 18:51 UTC (permalink / raw)
  To: Fabio M. De Francesco, Greg Kroah-Hartman, linux-staging, linux-kernel

On 7/30/21 5:37 AM, Fabio M. De Francesco wrote:
> 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>
> ---
>   drivers/staging/r8188eu/core/rtw_security.c | 37 ---------------------
>   1 file changed, 37 deletions(-)
> 
> diff --git a/drivers/staging/r8188eu/core/rtw_security.c b/drivers/staging/r8188eu/core/rtw_security.c
> index 9625beea4b3c..136ba1e61dca 100644
> --- a/drivers/staging/r8188eu/core/rtw_security.c
> +++ b/drivers/staging/r8188eu/core/rtw_security.c
> @@ -74,43 +74,6 @@ static void arcfour_encrypt(struct arc4context *parc4ctx, u8 *dest, u8 *src, u32
>   
>   }
>   
> -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)
> -{
> -	if (bcrc32initialized == 1) {
> -		return;
> -	} else {
> -		int i, j;
> -		u32 c;
> -		u8 *p = (u8 *)&c, *p1;
> -		u8 k;
> -
> -		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
>   */
> 

These two patches are

Tested-by: Larry Finger <Larry.Finger@lwfinger.net>

Thanks for your contribution.

Larry


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-07-30 18:51 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-30 10:37 [PATCH 0/2] staging: r8188eu: Use in-kernel API and remove no more needed symbols Fabio M. De Francesco
2021-07-30 10:37 ` [PATCH 1/2] staging: r8188eu: Replace a custom function with crc32_le() Fabio M. De Francesco
2021-07-30 10:37 ` [PATCH 2/2] staging: r8188eu: Remove no more used functions and variables Fabio M. De Francesco
2021-07-30 18:51   ` Larry Finger

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).