1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
8 * $Id: crc32.c 10464 2006-08-05 20:19:10Z miipekk $
10 * Copyright (C) 2007 Barry Wardell
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
23 * We can't use the CRC32 implementation in the firmware library as it uses a
24 * different polynomial. The polynomial needed is 0xEDB88320L
26 * CRC32 implementation taken from:
28 * efone - Distributed internet phone system.
30 * (c) 1999,2000 Krzysztof Dabrowski
31 * (c) 1999,2000 ElysiuM deeZine
33 * This program is free software; you can redistribute it and/or
34 * modify it under the terms of the GNU General Public License
35 * as published by the Free Software Foundation; either version
36 * 2 of the License, or (at your option) any later version.
40 /* based on implementation by Finn Yannick Jacobs */
42 #include "crc32-mi4.h"
44 /* crc_tab[] -- this crcTable is being build by chksum_crc32GenTab().
45 * so make sure, you call it before using the other
48 static unsigned int crc_tab
[256];
50 /* chksum_crc() -- to a given block, this one calculates the
51 * crc32-checksum until the length is
52 * reached. the crc32-checksum will be
55 unsigned int chksum_crc32 (unsigned char *block
, unsigned int length
)
57 register unsigned long crc
;
61 for (i
= 0; i
< length
; i
++)
63 crc
= ((crc
>> 8) & 0x00FFFFFF) ^ crc_tab
[(crc
^ *block
++) & 0xFF];
68 /* chksum_crc32gentab() -- to a global crc_tab[256], this one will
69 * calculate the crcTable for crc32-checksums.
70 * it is generated to the polynom [..]
73 void chksum_crc32gentab (void)
75 unsigned long crc
, poly
;
79 for (i
= 0; i
< 256; i
++)
82 for (j
= 8; j
> 0; j
--)
86 crc
= (crc
>> 1) ^ poly
;