]> Joshua Wise's Git repositories - netwatch.git/blob - lib/crc32.c
More ICH2-specific code diked out.
[netwatch.git] / lib / crc32.c
1 #include <stdint.h>
2
3 /* code from http://www.faqs.org/faqs/compression-faq/part1/section-26.html,
4  * presumed public domain */
5
6 static uint32_t crc32_table[256];
7
8 uint32_t crc32(uint8_t *buf, int len, uint32_t crc0)
9 {
10         uint8_t *p;
11         uint32_t crc;
12
13         crc = crc0;
14         for (p = buf; len > 0; ++p, --len)
15                 crc = (crc << 8) ^ crc32_table[(crc >> 24) ^ *p];
16         return crc;
17 }
18
19 /*
20  * Build auxiliary table for parallel byte-at-a-time CRC-32.
21  */
22 #define CRC32_POLY 0x04c11db7     /* AUTODIN II, Ethernet, & FDDI */
23
24 void crc32_init()
25 {
26         int i, j;
27         uint32_t c;
28
29         for (i = 0; i < 256; ++i) {
30                 for (c = i << 24, j = 8; j > 0; --j)
31                         c = c & 0x80000000 ? (c << 1) ^ CRC32_POLY : (c << 1);
32                 crc32_table[i] = c;
33         }
34 }
This page took 0.024963 seconds and 4 git commands to generate.