summaryrefslogtreecommitdiff
path: root/usr/src/lib/varpd/svp/common/libvarpd_svp_crc.c
blob: ade47ff998f811f5ed00031b339a16e20cb994b0 (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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/*
 * This file and its contents are supplied under the terms of the
 * Common Development and Distribution License ("CDDL"), version 1.0.
 * You may only use this file in accordance with the terms of version
 * 1.0 of the CDDL.
 *
 * A full copy of the text of the CDDL should have accompanied this
 * source.  A copy of the CDDL is also available via the Internet at
 * http://www.illumos.org/license/CDDL.
 */

/*
 * Copyright 2015, Joyent, Inc.
 */

/*
 * Perform standard crc32 functions.
 *
 * For more information, see the big theory statement in
 * lib/varpd/svp/common/libvarpd_svp.c.
 *
 * Really, this should just be a libcrc.
 */

#include <sys/crc32.h>
#include <stdint.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <inttypes.h>
#include <libvarpd_svp.h>

static uint32_t svp_crc32_tab[] = { CRC32_TABLE };

static uint32_t
svp_crc32(uint32_t old, const uint8_t *buf, size_t len)
{
	uint32_t out;

	CRC32(out, buf, len, old, svp_crc32_tab);
	return (out);
}

void
svp_query_crc32(svp_req_t *shp, void *buf, size_t data)
{
	uint32_t crc = -1U;

	shp->svp_crc32 = 0;
	crc = svp_crc32(crc, (uint8_t *)shp, sizeof (svp_req_t));
	crc = svp_crc32(crc, buf, data);
	crc = ~crc;
	shp->svp_crc32 = htonl(crc);
}