Skip to content

Commit

Permalink
staging: rtl8188eu: Replace a custom function with crc32_le()
Browse files Browse the repository at this point in the history
Use crc32_le in place of the custom getcrc32. This change makes GCC
to warn about incorrect castings to the restricted type __le32, but
they can be safely ignored because crc32_le calculates bitwise
little-endian Ethernet AUTODIN II CRC32.

Signed-off-by: Fabio M. De Francesco <fmdefrancesco@gmail.com>
  • Loading branch information
xp4ns3 authored and intel-lab-lkp committed Jul 1, 2021
1 parent 77ad1f0 commit c296b1e
Showing 1 changed file with 4 additions and 18 deletions.
22 changes: 4 additions & 18 deletions drivers/staging/rtl8188eu/core/rtw_security.c
Expand Up @@ -111,21 +111,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)
{
Expand Down Expand Up @@ -609,14 +594,15 @@ 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*/
*((__le32 *)crc) = ~crc32_le(~0, payload, length);

arcfour_init(&mycontext, rc4key, 16);
arcfour_encrypt(&mycontext, payload, payload, length);
arcfour_encrypt(&mycontext, payload + length, crc, 4);
} else {
length = pxmitpriv->frag_len - pattrib->hdrlen - pattrib->iv_len - pattrib->icv_len;
*((__le32 *)crc) = getcrc32(payload, length);/* modified by Amy*/
*((__le32 *)crc) = ~crc32_le(~0, payload, length);

arcfour_init(&mycontext, rc4key, 16);
arcfour_encrypt(&mycontext, payload, payload, length);
arcfour_encrypt(&mycontext, payload + length, crc, 4);
Expand Down Expand Up @@ -682,7 +668,7 @@ 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);
*((__le32 *)crc) = ~crc32_le(~0, payload, length - 4);

if (crc[3] != payload[length - 1] ||
crc[2] != payload[length - 2] ||
Expand Down

0 comments on commit c296b1e

Please sign in to comment.