Path: blob/main/sys/contrib/xz-embedded/linux/lib/xz/xz_crc64.c
48521 views
/*1* CRC64 using the polynomial from ECMA-1822*3* This file is similar to xz_crc32.c. See the comments there.4*5* Authors: Lasse Collin <[email protected]>6* Igor Pavlov <https://7-zip.org/>7*8* This file has been put into the public domain.9* You can do whatever you want with this file.10*/1112#include "xz_private.h"1314#ifndef STATIC_RW_DATA15# define STATIC_RW_DATA static16#endif1718STATIC_RW_DATA uint64_t xz_crc64_table[256];1920XZ_EXTERN void xz_crc64_init(void)21{22/*23* The ULL suffix is needed for -std=gnu89 compatibility24* on 32-bit platforms.25*/26const uint64_t poly = 0xC96C5795D7870F42ULL;2728uint32_t i;29uint32_t j;30uint64_t r;3132for (i = 0; i < 256; ++i) {33r = i;34for (j = 0; j < 8; ++j)35r = (r >> 1) ^ (poly & ~((r & 1) - 1));3637xz_crc64_table[i] = r;38}3940return;41}4243XZ_EXTERN uint64_t xz_crc64(const uint8_t *buf, size_t size, uint64_t crc)44{45crc = ~crc;4647while (size != 0) {48crc = xz_crc64_table[*buf++ ^ (crc & 0xFF)] ^ (crc >> 8);49--size;50}5152return ~crc;53}545556