2 * Distributed under the terms of the GNU GPL version 2.
3 * Copyright (c) 2007, 2008 The Board of Trustees of The Leland
4 * Stanford Junior University
9 void crc32_init(struct crc32 *crc, unsigned int polynomial)
13 for (i = 0; i < CRC32_TABLE_SIZE; ++i) {
14 unsigned int reg = i << 24;
16 for (j = 0; j < CRC32_TABLE_BITS; j++) {
17 int topBit = (reg & 0x80000000) != 0;
26 unsigned int crc32_calculate(const struct crc32 *crc,
27 const void *data_, size_t n_bytes)
29 // FIXME: this can be optimized by unrolling, see linux-2.6/lib/crc32.c.
30 const uint8_t *data = data_;
31 unsigned int result = 0;
34 for (i = 0; i < n_bytes; i++) {
35 unsigned int top = result >> 24;
37 result = (result << 8) ^ crc->table[top];