From: Fabio Aiuto <fabioaiuto83@gmail.com>
To: David Laight <David.Laight@ACULAB.COM>
Cc: "gregkh@linuxfoundation.org" <gregkh@linuxfoundation.org>,
"linux-staging@lists.linux.dev" <linux-staging@lists.linux.dev>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v2 1/2] staging: rtl8723bs: replace private CRC-32 routines with in-kernel ones
Date: Tue, 11 May 2021 11:49:27 +0200 [thread overview]
Message-ID: <20210511094927.GA1410@agape.jhs> (raw)
In-Reply-To: <29938747c82e4cf1837be5f1cdb803b7@AcuMS.aculab.com>
Hello David,
On Mon, May 10, 2021 at 01:38:49PM +0000, David Laight wrote:
> > replace private CRC-32 routines with in-kernel ones.
>
> Have you verified that they compute the same CRC?
>
> There are all sorts of subtle reasons why the outputs can differ.
>
> David
>
> -
> Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
> Registration No: 1397386 (Wales)
>
I tried this:
#include <linux/module.h>
#include <linux/crc32poly.h>
#include <linux/crc32.h>
/* Copy pasted from rtl8723bs/core/rtw_security.c */
static signed int bcrc32initialized;
static u32 crc32_table[256];
MODULE_LICENSE("GPL");
MODULE_DESCRIPTION("CRC-32 verifier");
MODULE_AUTHOR("Fabio Aiuto");
/* Copy pasted from rtl8723bs/core/rtw_security.c */
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));
}
/* Copy pasted from rtl8723bs/core/rtw_security.c */
static void crc32_init(void)
{
if (bcrc32initialized == 1)
return;
else {
signed 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_BE : (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;
}
}
/* Copy pasted from rtl8723bs/core/rtw_security.c */
static __le32 getcrc32(u8 *buf, signed 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 */
}
static int __init crc32_entry(void)
{
u8 payload;
unsigned char crc_priv[4], crc_pub[4];
payload = (u8)1234;
/* private crc calculation used in rtl8723bs */
*((__le32 *)crc_priv) = getcrc32(&payload, 2);
pr_info("private rtl8723bs crc: %x", *crc_priv);
/* in-kernel public crc calculation */
*((__le32 *)crc_pub) = ~crc32_le(~0, &payload, 2);
pr_info("generic crc: %x", *crc_pub);
return 0;
}
static void __exit crc32_exit(void)
{
}
module_init(crc32_entry);
module_exit(crc32_exit);
And run it on qemu. Don't know why to display the second pr_info()
I have to rmmod it, but both methods give the same result (62)
[ 38.149979] crc32m: module is from the staging directory, the quality is unknown, you have been warned.
[ 38.169208] private rtl8723bs crc: 62
[ 38.169400] generic crc: 62
thank you,
fabio
next prev parent reply other threads:[~2021-05-11 9:49 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-05-10 13:19 [PATCH v2 0/2] staging: rtl8723bs: use of generic CRC-32 Fabio Aiuto
2021-05-10 13:19 ` [PATCH v2 1/2] staging: rtl8723bs: replace private CRC-32 routines with in-kernel ones Fabio Aiuto
2021-05-10 13:38 ` David Laight
2021-05-10 13:53 ` Fabio Aiuto
2021-05-11 9:49 ` Fabio Aiuto [this message]
2021-05-10 13:19 ` [PATCH v2 2/2] staging: rtl8723bs: remove unneeded comments to silence 'line too long' warning Fabio Aiuto
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210511094927.GA1410@agape.jhs \
--to=fabioaiuto83@gmail.com \
--cc=David.Laight@ACULAB.COM \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-staging@lists.linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).