FreeBSD/Linux Kernel Cross Reference
sys/lib/libz/crc32.c
1 /* $NetBSD: crc32.c,v 1.7 2005/02/26 22:58:57 perry Exp $ */
2
3 /* crc32.c -- compute the CRC-32 of a data stream
4 * Copyright (C) 1995-2002 Mark Adler
5 * For conditions of distribution and use, see copyright notice in zlib.h
6 */
7
8 /* @(#) $Id: crc32.c,v 1.7 2005/02/26 22:58:57 perry Exp $ */
9
10 #include "zlib.h"
11
12 #define local static
13
14 local const uLongf crc_table[16] = {
15 0x00000000L, 0x1db71064L, 0x3b6e20c8L, 0x26d930acL,
16 0x76dc4190L, 0x6b6b51f4L, 0x4db26158L, 0x5005713cL,
17 0xedb88320L, 0xf00f9344L, 0xd6d6a3e8L, 0xcb61b38cL,
18 0x9b64c2b0L, 0x86d3d2d4L, 0xa00ae278L, 0xbdbdf21cL
19 };
20
21 /* ========================================================================= */
22 #define DO1(buf) do { crc ^= *buf++; crc = (crc >> 4) ^ crc_table[crc & 0xf]; crc = (crc >> 4) ^ crc_table[crc & 0xf]; } while (0)
23 #define DO2(buf) DO1(buf); DO1(buf);
24 #define DO4(buf) DO2(buf); DO2(buf);
25 #define DO8(buf) DO4(buf); DO4(buf);
26
27 /* ========================================================================= */
28 uLong ZEXPORT crc32(crc, buf, len)
29 uLong crc;
30 const Bytef *buf;
31 uInt len;
32 {
33 if (buf == Z_NULL) return 0L;
34 crc = crc ^ 0xffffffffL;
35 while (len >= 8)
36 {
37 DO8(buf);
38 len -= 8;
39 }
40 if (len) do {
41 DO1(buf);
42 } while (--len);
43 return crc ^ 0xffffffffL;
44 }
Cache object: e313ee65ba2c0d951156daa0b3d28034
|