Revert "TODO epan/dissectors/asn1/kerberos/packet-kerberos-template.c new GSS flags"
[wireshark-sm.git] / wsutil / crc16.h
blob2c1be91d7168d80d47966a0d09b03b9a98a0ceb5
1 /** @file
2 * Declaration of CRC-16 routines and table
4 * 2004 Richard van der Hoff <richardv@mxtelecom.com>
6 * Wireshark - Network traffic analyzer
7 * By Gerald Combs <gerald@wireshark.org>
8 * Copyright 1998 Gerald Combs
10 * SPDX-License-Identifier: GPL-2.0-or-later
13 #ifndef __CRC16_H__
14 #define __CRC16_H__
16 #include <wireshark.h>
18 #ifdef __cplusplus
19 extern "C" {
20 #endif /* __cplusplus */
22 /* Calculate the CCITT/ITU/CRC-16 16-bit CRC
24 (parameters for this CRC are:
25 Polynomial: x^16 + x^12 + x^5 + 1 (0x1021);
26 Start value 0xFFFF;
27 XOR result with 0xFFFF;
28 First bit is LSB)
31 /** Compute CRC16 CCITT checksum of a buffer of data.
32 @param buf The buffer containing the data.
33 @param len The number of bytes to include in the computation.
34 @return The CRC16 CCITT checksum. */
35 WS_DLL_PUBLIC uint16_t crc16_ccitt(const uint8_t *buf, unsigned len);
37 /** Compute CRC16 X.25 CCITT checksum of a buffer of data.
38 @param buf The buffer containing the data.
39 @param len The number of bytes to include in the computation.
40 @return The CRC16 X.25 CCITT checksum. */
41 WS_DLL_PUBLIC uint16_t crc16_x25_ccitt_seed(const uint8_t *buf, unsigned len, uint16_t seed);
43 /** Compute CRC16 CCITT checksum of a buffer of data. If computing the
44 * checksum over multiple buffers and you want to feed the partial CRC16
45 * back in, remember to take the 1's complement of the partial CRC16 first.
46 @param buf The buffer containing the data.
47 @param len The number of bytes to include in the computation.
48 @param seed The seed to use.
49 @return The CRC16 CCITT checksum (using the given seed). */
50 WS_DLL_PUBLIC uint16_t crc16_ccitt_seed(const uint8_t *buf, unsigned len, uint16_t seed);
52 /** Compute the 16bit CRC_A value of a buffer as defined in ISO14443-3.
53 @param buf The buffer containing the data.
54 @param len The number of bytes to include in the computation.
55 @return the CRC16 checksum for the buffer */
56 WS_DLL_PUBLIC uint16_t crc16_iso14443a(const uint8_t *buf, unsigned len);
58 /** Compute the 16bit CRC value of a buffer as defined in USB Specification.
59 @param buf The buffer containing the data.
60 @param len The number of bytes to include in the computation.
61 @return the CRC16 checksum for the buffer */
62 WS_DLL_PUBLIC uint16_t crc16_usb(const uint8_t *buf, unsigned len);
64 /** Calculates a CRC16 checksum for the given buffer with the polynom
65 * 0x5935 using a precompiled CRC table
66 * @param buf a pointer to a buffer of the given length
67 * @param len the length of the given buffer
68 * @param seed The seed to use.
69 * @return the CRC16 checksum for the buffer
71 WS_DLL_PUBLIC uint16_t crc16_0x5935(const uint8_t *buf, uint32_t len, uint16_t seed);
73 /** Calculates a CRC16 checksum for the given buffer with the polynom
74 * 0x755B using a precompiled CRC table
75 * @param buf a pointer to a buffer of the given length
76 * @param len the length of the given buffer
77 * @param seed The seed to use.
78 * @return the CRC16 checksum for the buffer
80 WS_DLL_PUBLIC uint16_t crc16_0x755B(const uint8_t *buf, uint32_t len, uint16_t seed);
82 /** Computes CRC16 checksum for the given data with the polynom 0x9949 using
83 * precompiled CRC table
84 * @param buf a pointer to a buffer of the given length
85 * @param len the length of the given buffer
86 * @param seed The seed to use.
87 * @return the CRC16 checksum for the buffer
89 WS_DLL_PUBLIC uint16_t crc16_0x9949_seed(const uint8_t *buf, unsigned len, uint16_t seed);
91 /** Computes CRC16 checksum for the given data with the polynom 0x3D65 using
92 * precompiled CRC table
93 * @param buf a pointer to a buffer of the given length
94 * @param len the length of the given buffer
95 * @param seed The seed to use.
96 * @return the CRC16 checksum for the buffer
98 WS_DLL_PUBLIC uint16_t crc16_0x3D65_seed(const uint8_t *buf, unsigned len, uint16_t seed);
100 /** Computes CRC16 checksum for the given data with the polynom 0x080F using
101 * precompiled CRC table
102 * @param buf a pointer to a buffer of the given length
103 * @param len the length of the given buffer
104 * @param seed The seed to use.
105 * @return the CRC16 checksum for the buffer
107 WS_DLL_PUBLIC uint16_t crc16_0x080F_seed(const uint8_t *buf, unsigned len, uint16_t seed);
109 #ifdef __cplusplus
111 #endif /* __cplusplus */
113 #endif /* crc16.h */