summaryrefslogtreecommitdiffstats
path: root/sbin/hastd/crc32.h
blob: 3812a83f971fd8a43f8fc4b8e335479ce54888e2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
/*-
 *  COPYRIGHT (C) 1986 Gary S. Brown.  You may use this program, or
 *  code or tables extracted from it, as desired without restriction.
 *
 * $FreeBSD$
 */

#ifndef _CRC32_H_
#define	_CRC32_H_

#include <stdint.h>	/* uint32_t */
#include <stdlib.h>	/* size_t */

extern uint32_t crc32_tab[];

static __inline uint32_t
crc32(const void *buf, size_t size)
{
	const uint8_t *p = buf;
	uint32_t crc;

	crc = ~0U;
	while (size--)
		crc = crc32_tab[(crc ^ *p++) & 0xFF] ^ (crc >> 8);
	return (crc ^ ~0U);
}

#endif	/* !_CRC32_H_ */
OpenPOWER on IntegriCloud