Back to home page

LXR

 
 

    


File indexing completed on 2025-05-11 08:24:10

0001 /*
0002  * CRC64 using the polynomial from ECMA-182
0003  *
0004  * This file is similar to xz_crc32.c. See the comments there.
0005  *
0006  * Authors: Lasse Collin <lasse.collin@tukaani.org>
0007  *          Igor Pavlov <http://7-zip.org/>
0008  *
0009  * This file has been put into the public domain.
0010  * You can do whatever you want with this file.
0011  */
0012 
0013 #include "xz_private.h"
0014 
0015 #ifndef STATIC_RW_DATA
0016 #   define STATIC_RW_DATA static
0017 #endif
0018 
0019 STATIC_RW_DATA uint64_t xz_crc64_table[256];
0020 
0021 XZ_EXTERN void xz_crc64_init(void)
0022 {
0023     const uint64_t poly = 0xC96C5795D7870F42;
0024 
0025     uint32_t i;
0026     uint32_t j;
0027     uint64_t r;
0028 
0029     for (i = 0; i < 256; ++i) {
0030         r = i;
0031         for (j = 0; j < 8; ++j)
0032             r = (r >> 1) ^ (poly & ~((r & 1) - 1));
0033 
0034         xz_crc64_table[i] = r;
0035     }
0036 
0037     return;
0038 }
0039 
0040 XZ_EXTERN uint64_t xz_crc64(const uint8_t *buf, size_t size, uint64_t crc)
0041 {
0042     crc = ~crc;
0043 
0044     while (size != 0) {
0045         crc = xz_crc64_table[*buf++ ^ (crc & 0xFF)] ^ (crc >> 8);
0046         --size;
0047     }
0048 
0049     return ~crc;
0050 }