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 _CRC32_H_ 9#define _CRC32_H_ 10 11#include <stdint.h> /* uint32_t */ 12#include <stdlib.h> /* size_t */ 13 14extern uint32_t crc32_tab[]; 15 16static __inline uint32_t 17crc32(const void *buf, size_t size) 18{ 19 const uint8_t *p = buf; 20 uint32_t crc; 21 22 crc = ~0U; 23 while (size--) 24 crc = crc32_tab[(crc ^ *p++) & 0xFF] ^ (crc >> 8); 25 return (crc ^ ~0U); 26} 27 28#endif /* !_CRC32_H_ */ 29