debian/xz-utils: Remove old NEWS.Debian
[xz/debian.git] / src / liblzma / check / crc64_small.c
blob55d72316bce753973676a0538fb003d88bbcc9f9
1 ///////////////////////////////////////////////////////////////////////////////
2 //
3 /// \file crc64_small.c
4 /// \brief CRC64 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 static uint64_t crc64_table[256];
19 static void
20 crc64_init(void)
22 static const uint64_t poly64 = UINT64_C(0xC96C5795D7870F42);
24 for (size_t b = 0; b < 256; ++b) {
25 uint64_t r = b;
26 for (size_t i = 0; i < 8; ++i) {
27 if (r & 1)
28 r = (r >> 1) ^ poly64;
29 else
30 r >>= 1;
33 crc64_table[b] = r;
36 return;
40 extern LZMA_API(uint64_t)
41 lzma_crc64(const uint8_t *buf, size_t size, uint64_t crc)
43 mythread_once(crc64_init);
45 crc = ~crc;
47 while (size != 0) {
48 crc = crc64_table[*buf++ ^ (crc & 0xFF)] ^ (crc >> 8);
49 --size;
52 return ~crc;