Blog
Community
Development
Documentation
CNDP
22.08.0
Toggle main menu visibility
Loading...
Searching...
No Matches
crc32.h
1
/*-
2
* SPDX-License-Identifier: BSD-3-Clause
3
*
4
* Copyright (c) 1992, 1993
5
* The Regents of the University of California. All rights reserved.
6
*
7
* Redistribution and use in source and binary forms, with or without
8
* modification, are permitted provided that the following conditions
9
* are met:
10
* 1. Redistributions of source code must retain the above copyright
11
* notice, this list of conditions and the following disclaimer.
12
* 2. Redistributions in binary form must reproduce the above copyright
13
* notice, this list of conditions and the following disclaimer in the
14
* documentation and/or other materials provided with the distribution.
15
* 3. Neither the name of the University nor the names of its contributors
16
* may be used to endorse or promote products derived from this software
17
* without specific prior written permission.
18
*
19
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29
* SUCH DAMAGE.
30
*
31
* @(#)libkern.h 8.1 (Berkeley) 6/10/93
32
* $FreeBSD$
33
*/
34
35
#ifndef _CRC32_H_
36
#define _CRC32_H_
37
38
#include <stdint.h>
// for uint32_t, uint8_t
39
#include <sys/cdefs.h>
40
#include <sys/types.h>
41
#include <stddef.h>
// for size_t
42
43
extern
const
uint32_t crc32_tab[];
44
45
#define rounddown(x, y) (((x) / (y)) * (y))
46
#define rounddown2(x, y) ((x) & (~((y)-1)))
/* if y is power of two */
47
#define roundup2(x, y) (((x) + ((y)-1)) & (~((y)-1)))
/* if y is power of two */
48
49
static
__inline uint32_t
50
crc32_raw(
const
void
*buf,
size_t
size, uint32_t crc)
51
{
52
const
uint8_t *p = (
const
uint8_t *)buf;
53
54
while
(size--)
55
crc = crc32_tab[(crc ^ *p++) & 0xFF] ^ (crc >> 8);
56
return
(crc);
57
}
58
59
static
__inline uint32_t
60
crc32(
const
void
*buf,
size_t
size)
61
{
62
uint32_t crc;
63
64
crc = crc32_raw(buf, size, ~0U);
65
return
(crc ^ ~0U);
66
}
67
68
uint32_t calculate_crc32c(uint32_t crc32c,
const
unsigned
char
*buffer,
unsigned
int
length);
69
70
uint32_t sse42_crc32c(uint32_t,
const
unsigned
char
*,
unsigned
);
71
72
#endif
/* _CRC32_H_ */
lib
usr
clib
utils
crc32.h
Generated by
1.18.0