2006-10-28 19:45:02 +00:00
|
|
|
/*
|
|
|
|
* crc32.c
|
|
|
|
*
|
|
|
|
* This file is a part of NSIS.
|
|
|
|
*
|
2009-02-01 14:44:30 +00:00
|
|
|
* Copyright (C) 1999-2009 Nullsoft and Contributors
|
2006-10-28 19:45:02 +00:00
|
|
|
*
|
|
|
|
* Licensed under the zlib/libpng license (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
*
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
*
|
|
|
|
* This software is provided 'as-is', without any express or implied
|
|
|
|
* warranty.
|
2010-03-24 17:22:56 +00:00
|
|
|
*
|
|
|
|
* Unicode support by Jim Park -- 08/24/2007
|
2006-10-28 19:45:02 +00:00
|
|
|
*/
|
|
|
|
|
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
|