1 /*
2 * Copied from Linux kernel crypto/crc32c.c
3 * Copyright (c) 2004 Cisco Systems, Inc.
4 * Copyright (c) 2008 Herbert Xu <herbert@gondor.apana.org.au>
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the Free
8 * Software Foundation; either version 2 of the License, or (at your option)
9 * any later version.
10 *
11 */
12
13 /*
14 * This is the CRC-32C table
15 * Generated with:
16 * width = 32 bits
17 * poly = 0x1EDC6F41
18 * reflect input bytes = true
19 * reflect output bytes = true
20 */
21
22 static u32 crc32c_table[256];
23
24 /*
25 * Steps through buffer one byte at at time, calculates reflected
26 * crc using table.
27 */
28
crc32c_le(u32 crc,const char * data,size_t length)29 static inline u32 crc32c_le(u32 crc, const char *data, size_t length)
30 {
31 while (length--)
32 crc = crc32c_table[(u8)(crc ^ *data++)] ^ (crc >> 8);
33
34 return crc;
35 }
36
btrfs_init_crc32c(void)37 static inline void btrfs_init_crc32c(void)
38 {
39 int i, j;
40 u32 v;
41 const u32 poly = 0x82F63B78; /* Bit-reflected CRC32C polynomial */
42
43 for (i = 0; i < 256; i++) {
44 v = i;
45 for (j = 0; j < 8; j++) {
46 v = (v >> 1) ^ ((v & 1) ? poly : 0);
47 }
48 crc32c_table[i] = v;
49 }
50 }
51