2 * CRC32 (Castagnoli 1993)
4 * Based on Michael E. Kounavis and Frank L. Berry: A Systematic Approach
5 * to Building High Performance Software-based CRC Generators
6 * (Proceedings of the 10th IEEE Symposium on Computers and Communications 2005)
8 * Includes code from http://sourceforge.net/projects/slicing-by-8/,
9 * which carried the following copyright notice:
11 * Copyright (c) 2004-2006 Intel Corporation - All Rights Reserved
13 * This software program is licensed subject to the BSD License,
14 * available at http://www.opensource.org/licenses/bsd-license.html
16 * Adapted for LibUCW by Martin Mares <mj@ucw.cz> in 2012.
20 * Internal CRC calculator context.
21 * You should use it just as an opaque handle only.
23 typedef struct crc32_context {
25 void (*update_func)(struct crc32_context *ctx, const byte *buf, uns len);
29 * Initialize new calculation of CRC in a given context.
30 * @crc_mode selects which algorithm should be used.
32 void crc32_init(crc32_context *ctx, uns crc_mode);
35 * Algorithm used for CRC calculation. The algorithms differ by the amount
36 * of precomputed tables they use. Bigger tables imply faster calculation
37 * at the cost of an increased cache footprint.
40 CRC_MODE_DEFAULT, /* Default algorithm (4K table) */
41 CRC_MODE_SMALL, /* Optimize for small data (1K table) */
42 CRC_MODE_BIG, /* Optimize for large data (8K table) */
46 /** Feed @len bytes starting at @buf to the CRC calculator. **/
47 static inline void crc32_update(crc32_context *ctx, const byte *buf, uns len)
49 ctx->update_func(ctx, buf, len);
52 /** Finish calculation and return the CRC value. **/
53 static inline u32 crc32_final(crc32_context *ctx)
55 return ctx->state ^ 0xffffffff;