diff options
author | pjd <pjd@FreeBSD.org> | 2011-03-06 22:56:14 +0000 |
---|---|---|
committer | pjd <pjd@FreeBSD.org> | 2011-03-06 22:56:14 +0000 |
commit | f56b79fee1b3a270c7df9a507133ade99dc1ab2a (patch) | |
tree | 6b872900bed0ce399d58f54f1a16e39911c78e4b /sbin/hastd/crc32.h | |
parent | 75dda0ff36fbb94f84d2478dec2bbe1ce89b3c1b (diff) | |
download | FreeBSD-src-f56b79fee1b3a270c7df9a507133ade99dc1ab2a.zip FreeBSD-src-f56b79fee1b3a270c7df9a507133ade99dc1ab2a.tar.gz |
Allow to checksum on-the-wire data using either CRC32 or SHA256.
MFC after: 2 weeks
Diffstat (limited to 'sbin/hastd/crc32.h')
-rw-r--r-- | sbin/hastd/crc32.h | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/sbin/hastd/crc32.h b/sbin/hastd/crc32.h new file mode 100644 index 0000000..3812a83 --- /dev/null +++ b/sbin/hastd/crc32.h @@ -0,0 +1,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_ */ |