xref: /spdk/include/spdk/crc16.h (revision a6dbe3721eb3b5990707fc3e378c95e505dd8ab5)
1 /*   SPDX-License-Identifier: BSD-3-Clause
2  *   Copyright (C) 2017 Intel Corporation.
3  *   All rights reserved.
4  */
5 
6 /**
7  * \file
8  * CRC-16 utility functions
9  */
10 
11 #ifndef SPDK_CRC16_H
12 #define SPDK_CRC16_H
13 
14 #include "spdk/stdinc.h"
15 
16 #ifdef __cplusplus
17 extern "C" {
18 #endif
19 
20 /**
21  * T10-DIF CRC-16 polynomial
22  */
23 #define SPDK_T10DIF_CRC16_POLYNOMIAL 0x8bb7u
24 
25 /**
26  * Calculate T10-DIF CRC-16 checksum.
27  *
28  * \param init_crc Initial CRC-16 value.
29  * \param buf Data buffer to checksum.
30  * \param len Length of buf in bytes.
31  * \return CRC-16 value.
32  */
33 uint16_t spdk_crc16_t10dif(uint16_t init_crc, const void *buf, size_t len);
34 
35 /**
36  * Calculate T10-DIF CRC-16 checksum and copy data.
37  *
38  * \param init_crc Initial CRC-16 value.
39  * \param dst Destination data buffer for copy.
40  * \param src Source data buffer for CRC calculation and copy.
41  * \param len Length of buffer in bytes.
42  * \return CRC-16 value.
43  */
44 uint16_t spdk_crc16_t10dif_copy(uint16_t init_crc, uint8_t *dst, uint8_t *src,
45 				size_t len);
46 #ifdef __cplusplus
47 }
48 #endif
49 
50 #endif /* SPDK_CRC16_H */
51