cksum missing

Rob Landley rob at landley.net
Tue Mar 21 16:04:43 PST 2006


On Tuesday 21 March 2006 1:15 pm, walter harms wrote:
> you may like to look at this:
> http://en.wikipedia.org/wiki/Cyclic_redundancy_check
> it says basicly there are 3 sorts of crc32.
> You can init with 0 or ~0 and xor the result with 0 or ~0
> more over there is a big and little endian version:
> (nice reading: linux kernel code
> http://os.inf.tu-dresden.de/l4env/doc/html/oshkosh/crc32_8c-source.html)

Yeah, I know.  And technically speaking, that's eight different kinds.

The crc code crushes down quite nicely with a little effort.  For example, 
here's the code I wound up with in bunzip2:

unsigned int crc32Table[256], writeCRC;

    /* Init the CRC32 table (big endian) */

    for(i=0;i<256;i++) {
        c=i<<24;
        for(j=8;j;j--)
            c=c&0x80000000 ? (c<<1)^0x04c11db7 : (c<<1);
        bd->crc32Table[i]=c;
    }

    bd->writeCRC=0xffffffffUL;


And then for each piece of data ("current"):

 bd->writeCRC=(((bd->writeCRC)<<8)
                          ^bd->crc32Table[((bd->writeCRC)>>24)^current]);

> the question is how to handle all this ? i will take a dive into the
> code and lets see what happens next.

Not brain surgery.  Just not easy to merge with the other endianness of CRC.  
(As I said, same basic algorithm, very different implementation.)

> re,
>   walter

Rob

> Rob Sullivan wrote:
> >> We already have two checksum calculation things.  One in bunzip and one
> >> in gunzip.  (They're two different kinds of CRC32.  The same basic
> >> algorithm but the endianness is different and one is initialized to 0
> >> the other to -1.)
> >
> > How about integrating a CRC32 function into libbb with both types of
> > endianness? This might save a fair bit of duplicated code.
> >
> > Rob

-- 
Never bet against the cheap plastic solution.


More information about the busybox mailing list