| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
#include "check.h" |
| 13 |
|
| 14 |
|
| 15 |
static uint64_t crc64_table[256]; |
| 16 |
|
| 17 |
|
| 18 |
#ifdef HAVE_FUNC_ATTRIBUTE_CONSTRUCTOR |
| 19 |
__attribute__((__constructor__)) |
| 20 |
#endif |
| 21 |
static void |
| 22 |
crc64_init(void) |
| 23 |
{ |
| 24 |
static const uint64_t poly64 = UINT64_C(0xC96C5795D7870F42); |
| 25 |
|
| 26 |
for (size_t b = 0; b < 256; ++b) { |
| 27 |
uint64_t r = b; |
| 28 |
for (size_t i = 0; i < 8; ++i) { |
| 29 |
if (r & 1) |
| 30 |
r = (r >> 1) ^ poly64; |
| 31 |
else |
| 32 |
r >>= 1; |
| 33 |
} |
| 34 |
|
| 35 |
crc64_table[b] = r; |
| 36 |
} |
| 37 |
|
| 38 |
return; |
| 39 |
} |
| 40 |
|
| 41 |
|
| 42 |
extern LZMA_API(uint64_t) |
| 43 |
lzma_crc64(const uint8_t *buf, size_t size, uint64_t crc) |
| 44 |
{ |
| 45 |
#ifndef HAVE_FUNC_ATTRIBUTE_CONSTRUCTOR |
| 46 |
mythread_once(crc64_init); |
| 47 |
#endif |
| 48 |
|
| 49 |
crc = ~crc; |
| 50 |
|
| 51 |
while (size != 0) { |
| 52 |
crc = crc64_table[*buf++ ^ (crc & 0xFF)] ^ (crc >> 8); |
| 53 |
--size; |
| 54 |
} |
| 55 |
|
| 56 |
return ~crc; |
| 57 |
} |