2006-04-23 06:44:19 +00:00
|
|
|
#include "crc32.h"
|
|
|
|
|
2009-12-14 05:23:29 +00:00
|
|
|
uint32_t crc32table[256];
|
2006-04-23 06:44:19 +00:00
|
|
|
|
|
|
|
void initcrc32table(void)
|
|
|
|
{
|
2009-01-09 09:29:17 +00:00
|
|
|
uint32_t i,j,k;
|
2006-04-24 19:04:22 +00:00
|
|
|
|
|
|
|
// algorithm and polynomial same as that used by infozip's zip
|
2007-12-12 17:42:14 +00:00
|
|
|
for (i=0; i<256; i++)
|
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
j = i;
|
|
|
|
for (k=8; k; k--)
|
2007-12-12 17:42:14 +00:00
|
|
|
j = (j&1) ? (0xedb88320L ^(j>>1)) : (j>>1);
|
2006-04-24 19:04:22 +00:00
|
|
|
crc32table[i] = j;
|
|
|
|
}
|
2006-04-23 06:44:19 +00:00
|
|
|
}
|
|
|
|
|
2009-01-09 09:29:17 +00:00
|
|
|
uint32_t crc32once(uint8_t *blk, uint32_t len)
|
2006-04-23 06:44:19 +00:00
|
|
|
{
|
2009-01-09 09:29:17 +00:00
|
|
|
uint32_t crc;
|
2006-04-24 19:04:22 +00:00
|
|
|
|
|
|
|
crc32init(&crc);
|
|
|
|
crc32block(&crc, blk, len);
|
|
|
|
return crc32finish(&crc);
|
2006-04-23 06:44:19 +00:00
|
|
|
}
|