/* * efone - Distributed internet phone system. * * (c) 1999,2000 Krzysztof Dabrowski * (c) 1999,2000 ElysiuM deeZine * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version * 2 of the License, or (at your option) any later version. * * Hacked by CyberLeo to make it capable of digesting long streams * one buffer at a time. - 20090105 */ /* based on implementation by Finn Yannick Jacobs */ #include #include #include /* crc_tab[] -- this crcTable is being build by chksum_crc32GenTab(). * so make sure, you call it before using the other * functions! */ uint32_t chksum_crc_tab[256]; /* chksum_crc() -- to a given block, this one calculates the * crc32-checksum until the length is * reached. the crc32-checksum will be * the result. */ uint32_t chksum_crc32 (unsigned char *block, unsigned int length, uint32_t *chksum_crc) { register unsigned long crc; unsigned long i; crc = *chksum_crc ^ 0xFFFFFFFF; for (i = 0; i < length; i++) { crc = ((crc >> 8) & 0x00FFFFFF) ^ chksum_crc_tab[(crc ^ *block++) & 0xFF]; } *chksum_crc = crc ^ 0xFFFFFFFF; return *chksum_crc; } /* chksum_crc32_gentab() -- to a global crc_tab[256], this one will * calculate the crcTable for crc32-checksums. * it is generated to the polynom [..] */ void chksum_crc32_gentab () { unsigned long crc, poly; int i, j; poly = 0xEDB88320L; for (i = 0; i < 256; i++) { crc = i; for (j = 8; j > 0; j--) { if (crc & 1) { crc = (crc >> 1) ^ poly; } else { crc >>= 1; } } chksum_crc_tab[i] = crc; } }