SmartAudio/lichee/brandy/pack_tools/update_signature/crc.c

50 lines
1.3 KiB
C
Raw Normal View History

2018-07-13 01:31:50 +00:00
/*
*********************************************************************************************************
* ePDK
* the Easy Portable/Player Develop Kits
* Decompression For Boot
*
* (c) Copyright 2009-2010, Sunny China
* All Rights Reserved
*
* File : calc_crc32.c
* By : sunny
* Version : V2.0
* Date : 2009-11-4 10:34:26
*********************************************************************************************************
*/
#include "crc.h"
unsigned int calc_crc32(void * buffer, unsigned int length)
{
unsigned int i, j;
CRC32_DATA_t crc32; //
unsigned int CRC32 = 0xffffffff; //<2F><><EFBFBD>ó<EFBFBD>ʼֵ
crc32.CRC = 0;
for( i = 0; i < 256; ++i)//<2F><>++i<><69><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ч<EFBFBD><D0A7>
{
crc32.CRC = i;
for( j = 0; j < 8 ; ++j)
{
//<2F><><EFBFBD><EFBFBD>ѭ<EFBFBD><D1AD>ʵ<EFBFBD><CAB5><EFBFBD>Ͼ<EFBFBD><CFBE><EFBFBD><EFBFBD><EFBFBD>"<22><><EFBFBD>㷨"<22><><EFBFBD><EFBFBD>ȡCRC<52><43>У<EFBFBD><D0A3><EFBFBD><EFBFBD>
if(crc32.CRC & 1)
crc32.CRC = (crc32.CRC >> 1) ^ 0xEDB88320;
else //0xEDB88320<32><30><EFBFBD><EFBFBD>CRC-32<33><32><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʽ<EFBFBD><CABD>ֵ
crc32.CRC >>= 1;
}
crc32.CRC_32_Tbl[i] = crc32.CRC;
}
CRC32 = 0xffffffff; //<2F><><EFBFBD>ó<EFBFBD>ʼֵ
for( i = 0; i < length; ++i)
{
CRC32 = crc32.CRC_32_Tbl[(CRC32^((unsigned char*)buffer)[i]) & 0xff] ^ (CRC32>>8);
}
//return CRC32;
return CRC32^0xffffffff;
}