]> Joshua Wise's Git repositories - netwatch.git/blame - lib/crc32.c
More ICH2-specific code diked out.
[netwatch.git] / lib / crc32.c
CommitLineData
74032dae
JW
1#include <stdint.h>
2
3/* code from http://www.faqs.org/faqs/compression-faq/part1/section-26.html,
4 * presumed public domain */
5
db9fad13 6static uint32_t crc32_table[256];
74032dae 7
f2da68c5 8uint32_t crc32(uint8_t *buf, int len, uint32_t crc0)
74032dae
JW
9{
10 uint8_t *p;
11 uint32_t crc;
12
f2da68c5 13 crc = crc0;
74032dae
JW
14 for (p = buf; len > 0; ++p, --len)
15 crc = (crc << 8) ^ crc32_table[(crc >> 24) ^ *p];
f2da68c5 16 return crc;
74032dae
JW
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
24void 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.025765 seconds and 4 git commands to generate.