1/*- 2 * COPYRIGHT (C) 1986 Gary S. Brown. You may use this program, or 3 * code or tables extracted from it, as desired without restriction. 4 */ 5 6#ifndef _SYS_GSB_CRC32_H_ 7#define _SYS_GSB_CRC32_H_ 8 9#include <sys/types.h> 10 11#ifdef _KERNEL 12 13extern const uint32_t crc32_tab[]; 14 15static __inline uint32_t 16crc32_raw(const void *buf, size_t size, uint32_t crc) 17{ 18 const uint8_t *p = (const uint8_t *)buf; 19 20 while (size--) 21 crc = crc32_tab[(crc ^ *p++) & 0xFF] ^ (crc >> 8); 22 return (crc); 23} 24 25static __inline uint32_t 26crc32(const void *buf, size_t size) 27{ 28 uint32_t crc; 29 30 crc = crc32_raw(buf, size, ~0U); 31 return (crc ^ ~0U); 32} 33#endif 34 35uint32_t calculate_crc32c(uint32_t crc32c, const unsigned char *buffer, 36 unsigned int length); 37 38#if defined(__amd64__) || defined(__i386__) 39uint32_t sse42_crc32c(uint32_t, const unsigned char *, unsigned); 40#endif 41#if defined(__aarch64__) 42uint32_t armv8_crc32c(uint32_t, const unsigned char *, unsigned int); 43#endif 44 45#ifdef TESTING 46uint32_t singletable_crc32c(uint32_t, const void *, size_t); 47uint32_t multitable_crc32c(uint32_t, const void *, size_t); 48#endif 49 50#endif /* !_SYS_GSB_CRC32_H_ */ 51