2004-03-12 20:43:54 +00:00
|
|
|
#include "Platform.h"
|
2006-06-16 14:12:04 +00:00
|
|
|
#include "crc32.h"
|
2002-08-02 10:01:35 +00:00
|
|
|
#include "exehead/config.h"
|
|
|
|
#ifdef NSIS_CONFIG_CRC_SUPPORT
|
|
|
|
|
|
|
|
// this is based on the (slow,small) CRC32 implementation from zlib.
|
2006-06-16 14:12:04 +00:00
|
|
|
crc32_t NSISCALL CRC32(crc32_t crc, const unsigned char *buf, unsigned int len)
|
2002-08-02 10:01:35 +00:00
|
|
|
{
|
2006-06-16 14:12:04 +00:00
|
|
|
static crc32_t crc_table[256];
|
2002-08-02 10:01:35 +00:00
|
|
|
|
2002-08-11 18:58:41 +00:00
|
|
|
if (!crc_table[1])
|
|
|
|
{
|
2006-06-16 14:12:04 +00:00
|
|
|
crc32_t c;
|
2002-08-11 18:58:41 +00:00
|
|
|
int n, k;
|
2002-08-02 10:01:35 +00:00
|
|
|
|
2002-08-11 18:58:41 +00:00
|
|
|
for (n = 0; n < 256; n++)
|
|
|
|
{
|
2006-06-16 14:12:04 +00:00
|
|
|
c = (crc32_t)n;
|
2002-08-11 18:58:41 +00:00
|
|
|
for (k = 0; k < 8; k++) c = (c >> 1) ^ (c & 1 ? 0xedb88320L : 0);
|
|
|
|
crc_table[n] = c;
|
|
|
|
}
|
|
|
|
}
|
2002-08-02 10:01:35 +00:00
|
|
|
|
|
|
|
crc = crc ^ 0xffffffffL;
|
|
|
|
while (len-- > 0) {
|
2002-08-11 18:58:41 +00:00
|
|
|
crc = crc_table[(crc ^ (*buf++)) & 0xff] ^ (crc >> 8);
|
2002-08-02 10:01:35 +00:00
|
|
|
}
|
|
|
|
return crc ^ 0xffffffffL;
|
|
|
|
}
|
|
|
|
|
2002-08-11 18:58:41 +00:00
|
|
|
#endif
|