Subversion Repositories freemyipod

Rev

Rev 693 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
693 user890104 1
/*
2
 * CRC32 functions
3
 * Based on public domain implementation by Finn Yannick Jacobs.
4
 */
5
 
6
/* Written and copyright 1999 by Finn Yannick Jacobs
7
 * No rights were reserved to this, so feel free to
8
 * manipulate or do with it, what you want or desire :)
9
 */
10
 
11
#include "crc32.h"
12
 
13
/* crc32table[] built by crc32_init() */
14
static unsigned long crc32table[256];
15
 
16
/* Calculate crc32. Little endian.
17
 * Standard seed is 0xffffffff or 0.
18
 * Some implementations xor result with 0xffffffff after calculation.
19
 */
694 user890104 20
uint32_t crc32(void *data, unsigned int len, uint32_t seed)
21
{
22
    uint8_t *d = data;
23
 
24
    while (len--)
25
    {
26
        seed = ((seed >> 8) & 0x00FFFFFF) ^ crc32table [(seed ^ *d++) & 0xFF];
27
    }
28
 
29
    return seed;
693 user890104 30
}
31
 
32
/* Calculate crc32table */
694 user890104 33
void crc32_init()
34
{
35
    uint32_t poly = 0xEDB88320L;
36
    uint32_t crc;
37
    int i, j;
693 user890104 38
 
694 user890104 39
    for (i = 0; i < 256; ++i)
40
    {
41
        crc = i;
42
 
43
        for (j = 8; j > 0; --j)
44
        {
45
            crc = (crc >> 1) ^ ((crc & 1) ? poly : 0);
46
        }
47
 
48
        crc32table[i] = crc;
49
    }
693 user890104 50
}