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 * $FreeBSD$ 6 */ 7 8#ifndef _SYS_GSB_CRC32_H_ 9#define _SYS_GSB_CRC32_H_ 10 11#include <sys/types.h> 12 13#ifdef _KERNEL 14 15extern const uint32_t crc32_tab[]; 16 17static __inline uint32_t 18crc32_raw(const void *buf, size_t size, uint32_t crc) 19{ 20 const uint8_t *p = (const uint8_t *)buf; 21 22 while (size--) 23 crc = crc32_tab[(crc ^ *p++) & 0xFF] ^ (crc >> 8); 24 return (crc); 25} 26 27static __inline uint32_t 28crc32(const void *buf, size_t size) 29{ 30 uint32_t crc; 31 32 crc = crc32_raw(buf, size, ~0U); 33 return (crc ^ ~0U); 34} 35#endif 36 37uint32_t calculate_crc32c(uint32_t crc32c, const unsigned char *buffer, 38 unsigned int length); 39 40#if defined(__amd64__) || defined(__i386__) 41uint32_t sse42_crc32c(uint32_t, const unsigned char *, unsigned); 42#endif 43#if defined(__aarch64__) 44uint32_t armv8_crc32c(uint32_t, const unsigned char *, unsigned int); 45#endif 46 47#ifdef TESTING 48uint32_t singletable_crc32c(uint32_t, const void *, size_t); 49uint32_t multitable_crc32c(uint32_t, const void *, size_t); 50#endif 51 52#endif /* !_SYS_GSB_CRC32_H_ */ 53