2 * efone - Distributed internet phone system.
4 * (c) 1999,2000 Krzysztof Dabrowski
5 * (c) 1999,2000 ElysiuM deeZine
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version
10 * 2 of the License, or (at your option) any later version.
12 * Hacked by CyberLeo to make it capable of digesting long streams
13 * one buffer at a time. - 20090105
16 /* based on implementation by Finn Yannick Jacobs */
22 /* crc_tab[] -- this crcTable is being build by chksum_crc32GenTab().
23 * so make sure, you call it before using the other
26 uint32_t chksum_crc_tab[256];
28 /* chksum_crc() -- to a given block, this one calculates the
29 * crc32-checksum until the length is
30 * reached. the crc32-checksum will be
33 uint32_t chksum_crc32 (unsigned char *block, unsigned int length, uint32_t *chksum_crc)
35 register unsigned long crc;
38 crc = *chksum_crc ^ 0xFFFFFFFF;
39 for (i = 0; i < length; i++)
41 crc = ((crc >> 8) & 0x00FFFFFF) ^ chksum_crc_tab[(crc ^ *block++) & 0xFF];
43 *chksum_crc = crc ^ 0xFFFFFFFF;
47 /* chksum_crc32_gentab() -- to a global crc_tab[256], this one will
48 * calculate the crcTable for crc32-checksums.
49 * it is generated to the polynom [..]
52 void chksum_crc32_gentab ()
54 unsigned long crc, poly;
58 for (i = 0; i < 256; i++)
61 for (j = 8; j > 0; j--)
65 crc = (crc >> 1) ^ poly;
72 chksum_crc_tab[i] = crc;