liblzma: Fix a typo in a comment
[xz/debian.git] / src / liblzma / check / crc32_small.c
blob6a1bd66185ead891159aa32211600e810a91e5cc
1 // SPDX-License-Identifier: 0BSD
3 ///////////////////////////////////////////////////////////////////////////////
4 //
5 /// \file crc32_small.c
6 /// \brief CRC32 calculation (size-optimized)
7 //
8 // Author: Lasse Collin
9 //
10 ///////////////////////////////////////////////////////////////////////////////
12 #include "check.h"
15 uint32_t lzma_crc32_table[1][256];
18 #ifdef HAVE_FUNC_ATTRIBUTE_CONSTRUCTOR
19 __attribute__((__constructor__))
20 #endif
21 static void
22 crc32_init(void)
24 static const uint32_t poly32 = UINT32_C(0xEDB88320);
26 for (size_t b = 0; b < 256; ++b) {
27 uint32_t r = b;
28 for (size_t i = 0; i < 8; ++i) {
29 if (r & 1)
30 r = (r >> 1) ^ poly32;
31 else
32 r >>= 1;
35 lzma_crc32_table[0][b] = r;
38 return;
42 #ifndef HAVE_FUNC_ATTRIBUTE_CONSTRUCTOR
43 extern void
44 lzma_crc32_init(void)
46 mythread_once(crc32_init);
47 return;
49 #endif
52 extern LZMA_API(uint32_t)
53 lzma_crc32(const uint8_t *buf, size_t size, uint32_t crc)
55 #ifndef HAVE_FUNC_ATTRIBUTE_CONSTRUCTOR
56 lzma_crc32_init();
57 #endif
59 crc = ~crc;
61 while (size != 0) {
62 crc = lzma_crc32_table[0][*buf++ ^ (crc & 0xFF)] ^ (crc >> 8);
63 --size;
66 return ~crc;