Make backup dialog modal.
[maemo-rb.git] / firmware / common / crc32-mi4.c
blob82c6f3e15be6392c4594fd40a3755d120be6718c
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
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
46 * functions!
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
53 * the result.
55 unsigned int chksum_crc32 (unsigned char *block, unsigned int length)
57 register unsigned long crc;
58 unsigned long i;
60 crc = 0;
61 for (i = 0; i < length; i++)
63 crc = ((crc >> 8) & 0x00FFFFFF) ^ crc_tab[(crc ^ *block++) & 0xFF];
65 return (crc);
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;
76 int i, j;
78 poly = 0xEDB88320L;
79 for (i = 0; i < 256; i++)
81 crc = i;
82 for (j = 8; j > 0; j--)
84 if (crc & 1)
86 crc = (crc >> 1) ^ poly;
88 else
90 crc >>= 1;
93 crc_tab[i] = crc;