Subversion Repositories freemyipod

Rev

Rev 693 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 693 Rev 694
Line 15... Line 15...
15
 
15
 
16
/* Calculate crc32. Little endian.
16
/* Calculate crc32. Little endian.
17
 * Standard seed is 0xffffffff or 0.
17
 * Standard seed is 0xffffffff or 0.
18
 * Some implementations xor result with 0xffffffff after calculation.
18
 * Some implementations xor result with 0xffffffff after calculation.
19
 */
19
 */
20
uint32_t crc32(void *data, unsigned int len, uint32_t seed) {
20
uint32_t crc32(void *data, unsigned int len, uint32_t seed)
-
 
21
{
21
	uint8_t *d = data;
22
    uint8_t *d = data;
22
	
23
    
23
	while (len--) {
24
    while (len--)
-
 
25
    {
24
		seed = ((seed >> 8) & 0x00FFFFFF) ^ crc32table [(seed ^ *d++) & 0xFF];
26
        seed = ((seed >> 8) & 0x00FFFFFF) ^ crc32table [(seed ^ *d++) & 0xFF];
25
	}
27
    }
26
	
28
    
27
	return seed;
29
    return seed;
28
}
30
}
29
 
31
 
30
/* Calculate crc32table */
32
/* Calculate crc32table */
31
void crc32_init() {
33
void crc32_init()
-
 
34
{
32
	uint32_t poly = 0xEDB88320L;
35
    uint32_t poly = 0xEDB88320L;
33
	uint32_t crc;
36
    uint32_t crc;
34
	int i, j;
37
    int i, j;
35
 
38
 
36
	for (i = 0; i < 256; ++i) {
39
    for (i = 0; i < 256; ++i)
-
 
40
    {
37
		crc = i;
41
        crc = i;
38
		
42
        
39
		for (j = 8; j > 0; --j) {
43
        for (j = 8; j > 0; --j)
-
 
44
        {
40
			crc = (crc >> 1) ^ ((crc & 1) ? poly : 0);
45
            crc = (crc >> 1) ^ ((crc & 1) ? poly : 0);
41
		}
46
        }
42
		
47
        
43
		crc32table[i] = crc;
48
        crc32table[i] = crc;
44
	}
49
    }
45
}
50
}