1219351Spjd/*-
2219351Spjd *  COPYRIGHT (C) 1986 Gary S. Brown.  You may use this program, or
3219351Spjd *  code or tables extracted from it, as desired without restriction.
4219351Spjd *
5219351Spjd * $FreeBSD$
6219351Spjd */
7219351Spjd
8219351Spjd#ifndef _CRC32_H_
9219351Spjd#define	_CRC32_H_
10219351Spjd
11219351Spjd#include <stdint.h>	/* uint32_t */
12219351Spjd#include <stdlib.h>	/* size_t */
13219351Spjd
14219351Spjdextern uint32_t crc32_tab[];
15219351Spjd
16219351Spjdstatic __inline uint32_t
17219351Spjdcrc32(const void *buf, size_t size)
18219351Spjd{
19219351Spjd	const uint8_t *p = buf;
20219351Spjd	uint32_t crc;
21219351Spjd
22219351Spjd	crc = ~0U;
23219351Spjd	while (size--)
24219351Spjd		crc = crc32_tab[(crc ^ *p++) & 0xFF] ^ (crc >> 8);
25219351Spjd	return (crc ^ ~0U);
26219351Spjd}
27219351Spjd
28219351Spjd#endif	/* !_CRC32_H_ */
29