RE: [PATCH v3 1/2] staging: rtl8188eu: Replace a custom function with crc32_le()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Fabio M. De Francesco
> Sent: 21 July 2021 12:01
> 
> Use crc32_le() in place of the custom getcrc32().
> 
...
> @@ -609,14 +595,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) = 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);
>  				} else {
>  					length = pxmitpriv->frag_len - pattrib->hdrlen - pattrib->iv_len -
> pattrib->icv_len;
> -					*((__le32 *)crc) = getcrc32(payload, length);/* modified by Amy*/
> +					*((__le32 *)crc) = 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);

Change crc to be __le32, kill the casts and pass &crc in the last call.

> @@ -682,7 +669,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) = cpu_to_le32(~crc32_le(~0, payload, length - 4));
> 
>  			if (crc[3] != payload[length - 1] ||
>  			    crc[2] != payload[length - 2] ||

You could to the same here, or make crc u32, remove the cpu_to_le32()
and use get_unaligned_u32(payload + length - 4) (or whatever it is called).

But it is much better to do:
	crc = crc32_le(~0, payload, length);
	if (crc != VALID_CRC32)
		res = _FAIL;

You can lookup VALID_CRC32, but it is crc32_le(0, "\xff\xff\xff\xff", 4);

	David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)






[Index of Archives]     [Linux Driver Development]     [Linux Driver Backports]     [DMA Engine]     [Linux GPIO]     [Linux SPI]     [Video for Linux]     [Linux USB Devel]     [Linux Coverity]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Yosemite Backpacking]
  Powered by Linux