|
1 /*********************************** CRC32 ***********************************/ |
|
2 |
|
3 /* Use a type crc32_t variable to store the crc value. |
|
4 * Initialise the variable to CRC32INIT before running the crc routine. |
|
5 * for more details see the CRC32.C file */ |
|
6 |
|
7 #ifndef CRC32INIT |
|
8 #define CRC32INIT 0xFFFFFFFFL /* the initializer for the 32-bit CRC */ |
|
9 |
|
10 typedef unsigned long crc32_t; /* the type of the 32-bit CRC */ |
|
11 |
|
12 extern const crc32_t crc32tab[]; /* a table of 32-bit CRC feedback terms */ |
|
13 |
|
14 #ifdef __cplusplus |
|
15 |
|
16 inline crc32_t crc32_update (const crc32_t crc, const unsigned char octet) |
|
17 { |
|
18 return crc32tab [(unsigned char) crc ^ octet] ^ ((crc >> 8) & 0x00FFFFFFL); |
|
19 } |
|
20 |
|
21 class crc32_c |
|
22 { |
|
23 private: |
|
24 crc32_t val; |
|
25 public: |
|
26 inline crc32_c (const crc32_t v = 0L) : val (v ^ CRC32INIT) {} |
|
27 inline void init () { val = CRC32INIT; } |
|
28 inline operator crc32_t () const { return val ^ CRC32INIT; } |
|
29 inline crc32_t operator = (const crc32_c &n) { |
|
30 return (val = n.val) ^ CRC32INIT; |
|
31 } |
|
32 inline crc32_t operator = (const crc32_t &n) { |
|
33 return val = n ^ CRC32INIT, n; |
|
34 } |
|
35 inline void update (const unsigned char octet) { |
|
36 val = crc32_update (val, octet); |
|
37 } |
|
38 crc32_t update (const unsigned char *block, int len); |
|
39 inline crc32_t update (const char* block, int len) { |
|
40 return update((const unsigned char*)block, len); |
|
41 } |
|
42 }; |
|
43 #else |
|
44 #define crc32_update(crc32,octet) ( crc32 = crc32tab[(unsigned char)(crc32) ^ \ |
|
45 (unsigned char)(octet) ] ^ ( ((crc32)>>8) & 0x00FFFFFFL ) ) |
|
46 #endif |
|
47 |
|
48 #endif CRC32INIT |