Path: blob/main/sys/contrib/xz-embedded/linux/lib/xz/xz_crc32.c
48521 views
/*1* CRC32 using the polynomial from IEEE-802.32*3* Authors: Lasse Collin <[email protected]>4* Igor Pavlov <https://7-zip.org/>5*6* This file has been put into the public domain.7* You can do whatever you want with this file.8*/910/*11* This is not the fastest implementation, but it is pretty compact.12* The fastest versions of xz_crc32() on modern CPUs without hardware13* accelerated CRC instruction are 3-5 times as fast as this version,14* but they are bigger and use more memory for the lookup table.15*/1617#include "xz_private.h"1819/*20* STATIC_RW_DATA is used in the pre-boot environment on some architectures.21* See <linux/decompress/mm.h> for details.22*/23#ifndef STATIC_RW_DATA24# define STATIC_RW_DATA static25#endif2627STATIC_RW_DATA uint32_t xz_crc32_table[256];2829XZ_EXTERN void xz_crc32_init(void)30{31const uint32_t poly = 0xEDB88320;3233uint32_t i;34uint32_t j;35uint32_t r;3637for (i = 0; i < 256; ++i) {38r = i;39for (j = 0; j < 8; ++j)40r = (r >> 1) ^ (poly & ~((r & 1) - 1));4142xz_crc32_table[i] = r;43}4445return;46}4748XZ_EXTERN uint32_t xz_crc32(const uint8_t *buf, size_t size, uint32_t crc)49{50crc = ~crc;5152while (size != 0) {53crc = xz_crc32_table[*buf++ ^ (crc & 0xFF)] ^ (crc >> 8);54--size;55}5657return ~crc;58}596061