Subversion Repositories freemyipod

Rev

Go to most recent revision | Details | 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
 */
20
uint32_t crc32(void *data, unsigned int len, uint32_t seed) {
21
	uint8_t *d = data;
22
 
23
	while (len--) {
24
		seed = ((seed >> 8) & 0x00FFFFFF) ^ crc32table [(seed ^ *d++) & 0xFF];
25
	}
26
 
27
	return seed;
28
}
29
 
30
/* Calculate crc32table */
31
void crc32_init() {
32
	uint32_t poly = 0xEDB88320L;
33
	uint32_t crc;
34
	int i, j;
35
 
36
	for (i = 0; i < 256; ++i) {
37
		crc = i;
38
 
39
		for (j = 8; j > 0; --j) {
40
			crc = (crc >> 1) ^ ((crc & 1) ? poly : 0);
41
		}
42
 
43
		crc32table[i] = crc;
44
	}
45
}