1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/// The polynomial used for the crc32 lookup table.
///
/// See also https://en.wikipedia.org/wiki/Cyclic_redundancy_check#Polynomial_representations
const POLYNOMIAL: u32 = 0x04C11DB7;
/// Most implementations (ethernet, zlib) use the reflected version of this polynomial.
const _: = assert!;
/// Lookup table to speed up crc32 checksum calculation.
///
/// The original C implementation notes:
///
/// > I think this is an implementation of the AUTODIN-II,
/// > Ethernet & FDDI 32-bit CRC standard. Vaguely derived
/// > from code by Rob Warnock, in Section 51 of the
/// > comp.compression FAQ.
pub static BZ2_CRC32TABLE: = generate_crc32_table;
/// Generate the crc32 lookup table.
///
/// Note that contrary to most material you'll find on the internet, we're using the non-reflected
/// polynomial, which impacts some of the logic (e.g. we bitwise and with 0x80000000 instead of 0x1).
///
/// This [article] has some excellent additional detail on how crc works, and how to make it fast.
///
/// [article]: https://create.stephan-brumme.com/crc32/
const