19 #if !defined(CRC_FALSE)
22 #if !defined(CRC_TRUE)
23 #define CRC_TRUE !CRC_FALSE
32 #if defined(CRC_CCITT)
34 typedef unsigned short crc;
36 #define CRC_NAME "CRC-CCITT"
37 #define POLYNOMIAL 0x1021
38 #define INITIAL_REMAINDER 0xFFFF
39 #define FINAL_XOR_VALUE 0x0000
40 #define REFLECT_DATA CRC_FALSE
41 #define REFLECT_REMAINDER CRC_FALSE
42 #define CHECK_VALUE 0x29B1
46 typedef unsigned short crc;
48 #define CRC_NAME "CRC-16"
49 #define POLYNOMIAL 0x8005
50 #define INITIAL_REMAINDER 0x0000
51 #define FINAL_XOR_VALUE 0x0000
52 #define REFLECT_DATA CRC_TRUE
53 #define REFLECT_REMAINDER CRC_TRUE
54 #define CHECK_VALUE 0xBB3D
60 typedef unsigned int crc;
62 #define CRC_NAME "CRC-32"
63 #define POLYNOMIAL 0x04C11DB7
64 #define INITIAL_REMAINDER 0xFFFFFFFF
65 #define FINAL_XOR_VALUE 0xFFFFFFFF
66 #define REFLECT_DATA CRC_TRUE
67 #define REFLECT_REMAINDER CRC_TRUE
68 #define CHECK_VALUE 0xCBF43926
72 #error "One of CRC_CCITT, CRC16, or CRC32 must be #define'd."
79 #define WIDTH (8 * sizeof(crc))
80 #define TOPBIT (1 << (WIDTH - 1))
82 #if (REFLECT_DATA == CRC_TRUE)
84 #define REFLECT_DATA(X) ((unsigned char) reflect((X), 8))
87 #define REFLECT_DATA(X) (X)
90 #if (REFLECT_REMAINDER == CRC_TRUE)
91 #undef REFLECT_REMAINDER
92 #define REFLECT_REMAINDER(X) ((crc) reflect((X), WIDTH))
94 #undef REFLECT_REMAINDER
95 #define REFLECT_REMAINDER(X) (X)
98 unsigned long reflect(
unsigned long data,
unsigned char nBits);
115 template <
typename CharIterator>
125 for (byte = 0; byte < nBytes; ++
byte)
128 remainder =
crcTable[data] ^ (remainder << 8);