2 * Dr Dobb's Journal: http://www.ddj.com/ftp/1992/1992.05/crcman.zip
4 * Copyright Mark R. Nelson 1992
6 * This code used by permission of J Erickson <jerickson@ddj.com>
7 * Tues 6th October 1998. Copyright acknowledged above, as agreed.
13 #define CRC32_POLYNOMIAL 0xEDB88320L
15 /*****************************************************************
16 Instead of performing a straightforward calculation of the 32 bit
17 CRC using a series of logical operations, this program uses the
18 faster table lookup method. This routine is called once when the
19 program starts up to build the table which will be used later
20 when calculating the CRC values.
21 *****************************************************************/
23 static uint32 CRCTable[256];
25 void crc32_build_table(void)
31 for ( i = 0; i <= 255 ; i++ )
34 for ( j = 8 ; j > 0; j-- )
38 crc = ( crc >> 1 ) ^ CRC32_POLYNOMIAL;
49 /*****************************************************************
50 This routine calculates the CRC for a block of data using the
52 *****************************************************************/
54 uint32 crc32_calc_buffer( uint32 count, uchar *buffer)
62 while ( count-- != 0 )
67 temp1 = ( crc >> 8 ) & 0x00FFFFFFL;
68 temp2 = CRCTable[ ( (int) crc ^ *p++ ) & 0xff ];