2 * efone - Distributed internet phone system.
\r
4 * (c) 1999,2000 Krzysztof Dabrowski
\r
5 * (c) 1999,2000 ElysiuM deeZine
\r
7 * This program is free software; you can redistribute it and/or
\r
8 * modify it under the terms of the GNU General Public License
\r
9 * as published by the Free Software Foundation; either version
\r
10 * 2 of the License, or (at your option) any later version.
\r
14 /* based on implementation by Finn Yannick Jacobs */
\r
18 #include <sys/types.h>
\r
21 /* crc_tab[] -- this crcTable is being build by chksum_crc32GenTab().
\r
22 * so make sure, you call it before using the other
\r
25 uint32_t crc_tab[256];
\r
27 /* chksum_crc() -- to a given block, this one calculates the
\r
28 * crc32-checksum until the length is
\r
29 * reached. the crc32-checksum will be
\r
32 uint32_t chksum_crc32 (unsigned char *block, unsigned int length)
\r
34 register unsigned long crc;
\r
38 for (i = 0; i < length; i++)
\r
40 crc = ((crc >> 8) & 0x00FFFFFF) ^ crc_tab[(crc ^ *block++) & 0xFF];
\r
42 return (crc ^ 0xFFFFFFFF);
\r
45 /* chksum_crc32gentab() -- to a global crc_tab[256], this one will
\r
46 * calculate the crcTable for crc32-checksums.
\r
47 * it is generated to the polynom [..]
\r
50 void chksum_crc32gentab ()
\r
52 unsigned long crc, poly;
\r
56 for (i = 0; i < 256; i++)
\r
59 for (j = 8; j > 0; j--)
\r
63 crc = (crc >> 1) ^ poly;
\r