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
16 #include "ws_symbol_export.h"
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);
27 XOR result with 0xFFFF;
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 guint16 crc16_ccitt(const guint8 *buf, guint 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 guint16 crc16_x25_ccitt_seed(const guint8 *buf, guint len, guint16 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 guint16 crc16_ccitt_seed(const guint8 *buf, guint len, guint16 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 guint16 crc16_iso14443a(const guint8 *buf, guint len);
58 /** Calculates a CRC16 checksum for the given buffer with the polynom
59 * 0x5935 using a precompiled CRC table
60 * @param buf a pointer to a buffer of the given length
61 * @param len the length of the given buffer
62 * @param seed The seed to use.
63 * @return the CRC16 checksum for the buffer
65 WS_DLL_PUBLIC guint16 crc16_0x5935(const guint8 *buf, guint32 len, guint16 seed);
67 /** Calculates a CRC16 checksum for the given buffer with the polynom
68 * 0x755B using a precompiled CRC table
69 * @param buf a pointer to a buffer of the given length
70 * @param len the length of the given buffer
71 * @param seed The seed to use.
72 * @return the CRC16 checksum for the buffer
74 WS_DLL_PUBLIC guint16 crc16_0x755B(const guint8 *buf, guint32 len, guint16 seed);
76 /** Computes CRC16 checksum for the given data with the polynom 0x9949 using
77 * precompiled CRC table
78 * @param buf a pointer to a buffer of the given length
79 * @param len the length of the given buffer
80 * @param seed The seed to use.
81 * @return the CRC16 checksum for the buffer
83 WS_DLL_PUBLIC guint16 crc16_0x9949_seed(const guint8 *buf, guint len, guint16 seed);
85 /** Computes CRC16 checksum for the given data with the polynom 0x3D65 using
86 * precompiled CRC table
87 * @param buf a pointer to a buffer of the given length
88 * @param len the length of the given buffer
89 * @param seed The seed to use.
90 * @return the CRC16 checksum for the buffer
92 WS_DLL_PUBLIC guint16 crc16_0x3D65_seed(const guint8 *buf, guint len, guint16 seed);
94 /** Computes CRC16 checksum for the given data with the polynom 0x080F using
95 * precompiled CRC table
96 * @param buf a pointer to a buffer of the given length
97 * @param len the length of the given buffer
98 * @param seed The seed to use.
99 * @return the CRC16 checksum for the buffer
101 WS_DLL_PUBLIC guint16 crc16_0x080F_seed(const guint8 *buf, guint len, guint16 seed);
105 #endif /* __cplusplus */