configure.ac: fix typo
[rofl0r-gnuboy.git] / xz / xz_crc64.c
blobca1caee899ae2834b88d60d60312718166326bdf
1 /*
2 * CRC64 using the polynomial from ECMA-182
4 * This file is similar to xz_crc32.c. See the comments there.
6 * Authors: Lasse Collin <lasse.collin@tukaani.org>
7 * Igor Pavlov <http://7-zip.org/>
9 * This file has been put into the public domain.
10 * You can do whatever you want with this file.
13 #include "xz_private.h"
15 #ifndef STATIC_RW_DATA
16 # define STATIC_RW_DATA static
17 #endif
19 STATIC_RW_DATA uint64_t xz_crc64_table[256];
21 XZ_EXTERN void xz_crc64_init(void)
23 const uint64_t poly = 0xC96C5795D7870F42;
25 uint32_t i;
26 uint32_t j;
27 uint64_t r;
29 for (i = 0; i < 256; ++i) {
30 r = i;
31 for (j = 0; j < 8; ++j)
32 r = (r >> 1) ^ (poly & ~((r & 1) - 1));
34 xz_crc64_table[i] = r;
37 return;
40 XZ_EXTERN uint64_t xz_crc64(const uint8_t *buf, size_t size, uint64_t crc)
42 crc = ~crc;
44 while (size != 0) {
45 crc = xz_crc64_table[*buf++ ^ (crc & 0xFF)] ^ (crc >> 8);
46 --size;
49 return ~crc;