]> icculus.org git repositories - icculus/xz.git/blob - src/liblzma/check/crc32_init.c
Fix a comment API header.
[icculus/xz.git] / src / liblzma / check / crc32_init.c
1 ///////////////////////////////////////////////////////////////////////////////
2 //
3 /// \file       crc32_init.c
4 /// \brief      CRC32 table initialization
5 //
6 //  This code is based on various public domain sources.
7 //  This code has been put into the public domain.
8 //
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.
12 //
13 ///////////////////////////////////////////////////////////////////////////////
14
15 #ifdef HAVE_CONFIG_H
16 #       include "check.h"
17 #endif
18
19 #ifdef WORDS_BIGENDIAN
20 #       include "check_byteswap.h"
21 #endif
22
23
24 uint32_t lzma_crc32_table[8][256];
25
26
27 extern void
28 lzma_crc32_init(void)
29 {
30         static const uint32_t poly32 = UINT32_C(0xEDB88320);
31
32         for (size_t s = 0; s < 8; ++s) {
33                 for (size_t b = 0; b < 256; ++b) {
34                         uint32_t r = s == 0 ? b : lzma_crc32_table[s - 1][b];
35
36                         for (size_t i = 0; i < 8; ++i) {
37                                 if (r & 1)
38                                         r = (r >> 1) ^ poly32;
39                                 else
40                                         r >>= 1;
41                         }
42
43                         lzma_crc32_table[s][b] = r;
44                 }
45         }
46
47 #ifdef WORDS_BIGENDIAN
48         for (size_t s = 0; s < 8; ++s)
49                 for (size_t b = 0; b < 256; ++b)
50                         lzma_crc32_table[s][b]
51                                         = bswap_32(lzma_crc32_table[s][b]);
52 #endif
53
54         return;
55 }