#include "lib_crc.h" #define P_32 0xEDB88320L static int crc_tab32_init = FALSE; static unsigned long crc_tab32[256]; static void init_crc32_tab( void ); /*******************************************************************\ * * * unsigned long update_crc_32( unsigned long crc, char c ); * * * * The function update_crc_32 calculates a new CRC-32 value * * based on the previous value of the CRC and the next byte * * of the data to be checked. * * * \*******************************************************************/ unsigned long update_crc_32( unsigned long crc, char c ) { unsigned long tmp, long_c; long_c = 0x000000ffL & (unsigned long) c; if ( ! crc_tab32_init ) init_crc32_tab(); tmp = crc ^ long_c; crc = (crc >> 8) ^ crc_tab32[ tmp & 0xff ]; return crc; } /* update_crc_32 */ /*******************************************************************\ * * * static void init_crc32_tab( void ); * * * * The function init_crc32_tab() is used to fill the array * * for calculation of the CRC-32 with values. * * * \*******************************************************************/ static void init_crc32_tab( void ) { int i, j; unsigned long crc; for (i=0; i<256; i++) { crc = (unsigned long) i; for (j=0; j<8; j++) { if ( crc & 0x00000001L ) crc = ( crc >> 1 ) ^ P_32; else crc = crc >> 1; } crc_tab32[i] = crc; } crc_tab32_init = TRUE; } /* init_crc32_tab */