#define CRC32_POLY 0x82F63B78 // CRC-32C (Castagnoli) #define CRC32_POLY 0xEDB88320 // CRC-32-IEEE 802.3 class CrcCalculate { public: unsigned int crc32table[256]; void make_crc_table(); CrcCalculate() { make_crc_table(); } friend unsigned int crc32base (void *ch, unsigned int byte, unsigned int cal); } CrcCalculate_;
void CrcCalculate::make_crc_table() { unsigned int i, j, x; for (i = 0; i < 256; i++){ x = i; for (j = 0; j < 8; j++) if(x&1) x=(x>>1)^CRC32_POLY; else x>>= 1; crc32table[i]=x; }}
unsigned int crc32base (void *ch, unsigned int byte, unsigned int cal) { unsigned int i; unsigned char *p = (unsigned char *)ch; for (i = 0; i < byte; i++) cal = (cal >> 8) ^ CrcCalculate_.crc32table[(cal ^ p[i]) & 0xFF]; return cal; }