debian/xz-utils: Remove old NEWS.Debian
[xz/debian.git] / src / liblzma / check / crc32_small.c
blob5f8a32868782dcc4bbac89019a032681ae3d56c8
1 ///////////////////////////////////////////////////////////////////////////////
2 //
3 /// \file crc32_small.c
4 /// \brief CRC32 calculation (size-optimized)
5 //
6 // Author: Lasse Collin
7 //
8 // This file has been put into the public domain.
9 // You can do whatever you want with this file.
11 ///////////////////////////////////////////////////////////////////////////////
13 #include "check.h"
16 uint32_t lzma_crc32_table[1][256];
19 static void
20 crc32_init(void)
22 static const uint32_t poly32 = UINT32_C(0xEDB88320);
24 for (size_t b = 0; b < 256; ++b) {
25 uint32_t r = b;
26 for (size_t i = 0; i < 8; ++i) {
27 if (r & 1)
28 r = (r >> 1) ^ poly32;
29 else
30 r >>= 1;
33 lzma_crc32_table[0][b] = r;
36 return;
40 extern void
41 lzma_crc32_init(void)
43 mythread_once(crc32_init);
44 return;
48 extern LZMA_API(uint32_t)
49 lzma_crc32(const uint8_t *buf, size_t size, uint32_t crc)
51 lzma_crc32_init();
53 crc = ~crc;
55 while (size != 0) {
56 crc = lzma_crc32_table[0][*buf++ ^ (crc & 0xFF)] ^ (crc >> 8);
57 --size;
60 return ~crc;