1 ///////////////////////////////////////////////////////////////////////////////
4 /// \brief CRC32 table initialization
6 // This code is based on various public domain sources.
7 // This code has been put into the public domain.
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 ///////////////////////////////////////////////////////////////////////////////
19 #include <sys/types.h>
22 #ifdef WORDS_BIGENDIAN
23 # include "check_byteswap.h"
27 uint32_t lzma_crc32_table[8][256];
33 static const uint32_t poly32 = UINT32_C(0xEDB88320);
35 for (size_t s = 0; s < 8; ++s) {
36 for (size_t b = 0; b < 256; ++b) {
37 uint32_t r = s == 0 ? b : lzma_crc32_table[s - 1][b];
39 for (size_t i = 0; i < 8; ++i) {
41 r = (r >> 1) ^ poly32;
46 lzma_crc32_table[s][b] = r;
50 #ifdef WORDS_BIGENDIAN
51 for (size_t s = 0; s < 8; ++s)
52 for (size_t b = 0; b < 256; ++b)
53 lzma_crc32_table[s][b]
54 = bswap_32(lzma_crc32_table[s][b]);