Problem with CRC32 (fast version)

Feb 10, 2009 5 Replies

Hi,



I seem to be to stupid to get valid results using the fast CRC32 algorithm by Richard Black (poly:0x04C11DB7). I have also a plain table driven version. The checksum of a given file of the fast version and the normal version differ, but I counter checked and the normal version's CRC is correct.



Anyone knows if there is a bug in the posted algorithm. And if so, where ?



formatting link



TIA


42Bastian Do not email to bastian42@yahoo.com, it's a spam-only account :-) Use @monlynx.de instead !

Some years ago I implemented that reading RFC1662; it worked and the description was really easy to understand and implement.

Not so long ago I posted (for the sake of some usenet thread) an excerpt of my source at

formatting link
, perhaps it will be also some help.

Dimiter

------------------------------------------------------ Dimiter Popoff Transgalactic Instruments

formatting link

------------------------------------------------------

formatting link

Original message:

formatting link

Thanks Dimiter,

but that's not the algo by R.Black.

These are the "normal" byte-wise CRCs but I wanted to use the 32bit at-once way, but the result differs from the expected value.

Also the byte-wise one. BTW: What kind of assembly language is this. Looks like a weird mixture of Power and 68k :-)

Here the algo by (c) Richard Black :

void crc32_init(void) { int i,j; unsigned int crc; for (i = 0; i < 256; i++) { crc = i 8; result = crctab[result & 0xff] ^ result >> 8; result = crctab[result & 0xff] ^ result >> 8; result ^= *p++; #else result = crctab[result >> 24] ^ result > 24] ^ result > 24] ^ result > 24] ^ result

I think I found it ...

I replace this by the reflected crctable.

and fixed CRC calculation:

unsigned int crc32(unsigned char *data, int len,int le) { unsigned int result; unsigned int *p = (unsigned int *)data; unsigned int *e = (unsigned int *)(data + len); if (len < 4) abort(); result = 0xffffffff;

while( p < e ) { result ^= *p++;

if ( le ){ result = crctab[result & 0xff] ^ result >> 8; result = crctab[result & 0xff] ^ result >> 8; result = crctab[result & 0xff] ^ result >> 8; result = crctab[result & 0xff] ^ result >> 8; }else{ result = crctab[result >> 24] ^ result > 24] ^ result > 24] ^ result > 24] ^ result

Oops, I missed that. I may have thought you meant Roy Black.... :-) :-)

Anyway, since you already posted both your problem and the solution people will know this is not about the normal CRC used in PPP and elsewhere (and hopefully do not start wondering too much who is Roy Black, I am not sure how well known he is outside Germany... :-) ).

I directed you to it also because I knew you would see that, we know each other from the time of the Motorola mailing lists. It is what I call VPA, it will take CPU32 sources (and optionally much more) and produce power object code (this is how I made the transition to power, I had many megabytes of cpu32 sources too good to be thrown away). You can locate the native assembly lists in the same directory (as .txt), I have left it open.

Dimiter

------------------------------------------------------ Dimiter Popoff Transgalactic Instruments

formatting link

------------------------------------------------------

formatting link

Original message:

formatting link

That would have been more a fuzzy algo :-)

And I doubt any of the younger Germans will ...

Sorry for my ignorance. I did not remember.

Yes found it :-)

Take care.

42Bastian Do not email to bastian42@yahoo.com, it's a spam-only account :-) Use @monlynx.de instead !

Join the Discussion

Have something to add? Share your thoughts — no account required.

Didn't find your answer?

Ask the community — no account required