Different zlib CRC Algorithms

Phil Thompson phil at river-bank.demon.co.uk
Tue Feb 4 10:01:02 EST 2003

On Tuesday 04 February 2003 1:35 pm, David Woodhouse wrote:
> On Tue, 2003-02-04 at 12:12, Phil Thompson wrote:
> > I'm curious to know why the zlib implementation in the kernel uses a
> > slightly different algorithm for computing CRCs than the standard zlib
> > userland library?
> >
> > The difference is that the zlib library flips all the bits of the CRC on
> > entry to crc32() and flips them again on exit. The result being a
> > different CRC than would be generated by the kernel.
> Er, are you sure? We generate JFFS2 images using the userspace zlib
> library from mkfs.jffs2, and those images work fine with both the old
> and new kernel zlib.

mkfs.jffs2 is linked against -lz but first links in crc32.o from the mtd tree, 
ie. it seems to be using the kernel zlib not the userspace zlib (at least for 

I found this putting together my bootloader JFFS2 reader which I'm doing first 
as a Linux application - and so using userspace zlib. I have to calculate the 
CRC as follows...

	crc = (crc32(crc ^ 0xffffffff),buf,len) ^ 0xffffffff);

...otherwise all the CRC checks fail.


More information about the linux-mtd mailing list