Debian Codegraph @

Source/crc32.c

raw
1 /*
2 * crc32.c
3 *
4 * This file is a part of NSIS.
5 *
6 * Copyright (C) 1999-2026 Nullsoft and Contributors
7 *
8 * Licensed under the zlib/libpng license (the "License");
9 * you may not use this file except in compliance with the License.
10 *
11 * Licence details can be found in the file COPYING.
12 *
13 * This software is provided 'as-is', without any express or implied
14 * warranty.
15 *
16 * Unicode support by Jim Park -- 08/24/2007
17 */
18
19 #include "Platform.h"
20 #include "crc32.h"
21 #include "exehead/config.h"
22
23 #ifdef NSIS_CONFIG_CRC_SUPPORT
24
25 // this is based on the (slow,small) CRC32 implementation from zlib.
26 crc32_t NSISCALL CRC32(crc32_t crc, const unsigned char *buf, size_t len)
27 {
28 static crc32_t crc_table[256];
29
30 if (!crc_table[1])
31 {
32 crc32_t c;
33 int n, k;
34
35 for (n = 0; n < 256; n++)
36 {
37 c = (crc32_t)n;
38 for (k = 0; k < 8; k++) c = (c >> 1) ^ (c & 1 ? 0xedb88320L : 0);
39 crc_table[n] = c;
40 }
41 }
42
43 crc = crc ^ 0xffffffffL;
44 while (len-- > 0) {
45 crc = crc_table[(crc ^ (*buf++)) & 0xff] ^ (crc >> 8);
46 }
47 return crc ^ 0xffffffffL;
48 }
49
50 #endif