📄 crc32.c
字号:
/* crc32.c -- compute the CRC-32 of a data stream
* Copyright (C) 1995-2002 Mark Adler
* For conditions of distribution and use, see copyright notice in zlib.h
*/
#include "project.h"
static int crc_table_empty = 1;
static ULONG crc_table[256];
static void make_crc_table(void);
static void make_crc_table()
{
ULONG c;
int n, k;
ULONG poly; /* polynomial exclusive-or pattern */
/* terms of polynomial defining this crc (except x^32): */
static const BYTE p[] = {0,1,2,4,5,7,8,10,11,12,16,22,23,26};
/* make exclusive-or pattern from polynomial (0xedb88320L) */
poly = 0L;
for (n = 0; n < sizeof(p)/sizeof(BYTE); n++)
poly |= 1L << (31 - p[n]);
for (n = 0; n < 256; n++)
{
c = (ULONG)n;
for (k = 0; k < 8; k++)
c = c & 1 ? poly ^ (c >> 1) : c >> 1;
crc_table[n] = c;
}
crc_table_empty = 0;
}
ULONG
crc32(
PVOID buf,
SIZE_T len
)
{
PUCHAR buffer = buf;
ULONG crc = 0;
if (crc_table_empty)
make_crc_table();
while( len-- ) {
crc = crc_table[((int)crc ^ (*buffer++)) & 0xff] ^ (crc >> 8);
}
return crc;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -