xref: /spdk/lib/util/util_internal.h (revision 588dfe314bb83d86effdf67ec42837b11c2620bf)
1 /*   SPDX-License-Identifier: BSD-3-Clause
2  *   Copyright (C) 2008-2012 Daisuke Aoyama <aoyama@peach.ne.jp>.
3  *   Copyright (C) 2020 Intel Corporation.
4  *   All rights reserved.
5  */
6 
7 #ifndef SPDK_UTIL_INTERNAL_H
8 #define SPDK_UTIL_INTERNAL_H
9 
10 #include "spdk/stdinc.h"
11 
12 /**
13  * IEEE CRC-32 polynomial (bit reflected)
14  */
15 #define SPDK_CRC32_POLYNOMIAL_REFLECT 0xedb88320UL
16 
17 /**
18  * CRC-32C (Castagnoli) polynomial (bit reflected)
19  */
20 #define SPDK_CRC32C_POLYNOMIAL_REFLECT 0x82f63b78UL
21 
22 struct spdk_crc32_table {
23 	uint32_t table[256];
24 };
25 
26 /**
27  * Initialize a CRC32 lookup table for a given polynomial.
28  *
29  * \param table Table to fill with precalculated CRC-32 data.
30  * \param polynomial_reflect Bit-reflected CRC-32 polynomial.
31  */
32 void crc32_table_init(struct spdk_crc32_table *table,
33 		      uint32_t polynomial_reflect);
34 
35 
36 /**
37  * Calculate a partial CRC-32 checksum.
38  *
39  * \param table CRC-32 table initialized with crc32_table_init().
40  * \param buf Data buffer to checksum.
41  * \param len Length of buf in bytes.
42  * \param crc Previous CRC-32 value.
43  * \return Updated CRC-32 value.
44  */
45 uint32_t crc32_update(const struct spdk_crc32_table *table,
46 		      const void *buf, size_t len,
47 		      uint32_t crc);
48 
49 #endif /* SPDK_UTIL_INTERNAL_H */
50