Snort: speed up parsing of options by avoiding g_snprintf()
[metze/wireshark/wip.git] / epan / crc16-tvb.h
1 /* crc16-tvb.h
2  * Declaration of CRC-16 tvbuff routines
3  *
4  * 2004 Richard van der Hoff <richardv@mxtelecom.com>
5  *
6  * Wireshark - Network traffic analyzer
7  * By Gerald Combs <gerald@wireshark.org>
8  * Copyright 1998 Gerald Combs
9  *
10  * This program is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU General Public License
12  * as published by the Free Software Foundation; either version 2
13  * of the License, or (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 */
24
25 #ifndef __CRC16_TVB_H__
26 #define __CRC16_TVB_H__
27
28 #include "ws_symbol_export.h"
29
30 #ifdef __cplusplus
31 extern "C" {
32 #endif /* __cplusplus */
33
34 /** Compute CRC16 CCITT checksum of a tv buffer.
35  @param tvb The tv buffer containing the data.
36  @param len The number of bytes to include in the computation.
37  @return The CRC16 CCITT checksum. */
38 WS_DLL_PUBLIC guint16 crc16_ccitt_tvb(tvbuff_t *tvb, guint len);
39
40 /** Compute CRC16 X.25 CCITT checksum of a tv buffer.
41  @param tvb The tv buffer containing the data.
42  @param len The number of bytes to include in the computation.
43  @return The CRC16 X.25 CCITT checksum. */
44 WS_DLL_PUBLIC guint16 crc16_x25_ccitt_tvb(tvbuff_t *tvb, guint len);
45
46 /** Compute CRC16 ASSA R3 CCITT checksum of a tv buffer.
47  @param tvb The tv buffer containing the data.
48  @param offset The offset into tv buffer containing the data.
49  @param len The number of bytes to include in the computation.
50  @return The CRC16 X.25 CCITT checksum. */
51 WS_DLL_PUBLIC guint16 crc16_r3_ccitt_tvb(tvbuff_t *tvb, int offset, guint len);
52
53 /** Compute CRC16 CCITT checksum of a tv buffer.
54  @param tvb The tv buffer containing the data.
55  @param offset The offset into the tv buffer.
56  @param len The number of bytes to include in the computation.
57  @return The CRC16 CCITT checksum. */
58 WS_DLL_PUBLIC guint16 crc16_ccitt_tvb_offset(tvbuff_t *tvb, guint offset, guint len);
59
60 /** Compute CRC16 CCITT checksum of a tv buffer.  If computing the
61  *  checksum over multiple tv buffers and you want to feed the partial CRC16
62  *  back in, remember to take the 1's complement of the partial CRC16 first.
63  @param tvb The tv buffer containing the data.
64  @param len The number of bytes to include in the computation.
65  @param seed The seed to use.
66  @return The CRC16 CCITT checksum (using the given seed). */
67 WS_DLL_PUBLIC guint16 crc16_ccitt_tvb_seed(tvbuff_t *tvb, guint len, guint16 seed);
68
69 /** Compute CRC16 CCITT checksum of a tv buffer.  If computing the
70  *  checksum over multiple tv buffers and you want to feed the partial CRC16
71  *  back in, remember to take the 1's complement of the partial CRC16 first.
72  @param tvb The tv buffer containing the data.
73  @param offset The offset into the tv buffer.
74  @param len The number of bytes to include in the computation.
75  @param seed The seed to use.
76  @return The CRC16 CCITT checksum (using the given seed). */
77 WS_DLL_PUBLIC guint16 crc16_ccitt_tvb_offset_seed(tvbuff_t *tvb, guint offset,
78                                            guint len, guint16 seed);
79
80 /** Compute the 16bit CRC_A value of a tv buffer as defined in ISO14443-3.
81  @param tvb The tv buffer containing the data.
82  @param offset The offset into the tv buffer.
83  @param len The number of bytes to include in the computation.
84  @return The calculated CRC_A. */
85 WS_DLL_PUBLIC guint16 crc16_iso14443a_tvb_offset(tvbuff_t *tvb, guint offset, guint len);
86
87 /** Compute the "plain" CRC16 checksum of a tv buffer using the following
88  * parameters:
89  *    Width        = 16
90  *    Poly         = 0x8005
91  *    XorIn        = 0x0000
92  *    ReflectIn    = True
93  *    XorOut       = 0x0000
94  *    ReflectOut   = True
95  *    Algorithm    = table-driven
96  *    Direct       = True
97  @param tvb The tv buffer containing the data.
98  @param offset The offset into the tv buffer.
99  @param len The number of bytes to include in the computation.
100  @return The CRC16 checksum. */
101 WS_DLL_PUBLIC guint16 crc16_plain_tvb_offset(tvbuff_t *tvb, guint offset, guint len);
102
103 /** Compute the "plain" CRC16 checksum of a tv buffer using the following
104  * parameters:
105  *    Width        = 16
106  *    Poly         = 0x8005
107  *    XorIn        = 0x0000
108  *    ReflectIn    = True
109  *    XorOut       = 0x0000
110  *    ReflectOut   = True
111  *    Algorithm    = table-driven
112  *    Direct       = True
113  @param tvb The tv buffer containing the data.
114  @param offset The offset into the tv buffer.
115  @param len The number of bytes to include in the computation.
116  @param crc Starting CRC value
117  @return The CRC16 checksum. */
118 WS_DLL_PUBLIC guint16 crc16_plain_tvb_offset_seed(tvbuff_t *tvb, guint offset, guint len, guint16 crc);
119
120 /** Compute CRC16 checksum of a tv buffer using the parameters
121  *    Width        = 16 bits
122  *    Poly         = 0x9949
123  *    Reflection   = true
124  *    Algorithm    = table-driven
125  @param tvb The tv buffer containing the data.
126  @param offset The offset into the tv buffer.
127  @param len The number of bytes to include in the computation.
128  @param seed The seed to use.
129  @return The CRC16 checksum. */
130 WS_DLL_PUBLIC guint16 crc16_0x9949_tvb_offset_seed(tvbuff_t *tvb, guint offset, guint len, guint16 seed);
131
132 /** Compute CRC16 checksum of a tv buffer using the parameters
133  *    Width        = 16 bits
134  *    Poly         = 0x3D65
135  *    Reflection   = true
136  *    Algorithm    = table-driven
137  @param tvb The tv buffer containing the data.
138  @param offset The offset into the tv buffer.
139  @param len The number of bytes to include in the computation.
140  @param seed The seed to use.
141  @return The CRC16 checksum. */
142 WS_DLL_PUBLIC guint16 crc16_0x3D65_tvb_offset_seed(tvbuff_t *tvb, guint offset, guint len, guint16 seed);
143
144 #ifdef __cplusplus
145 }
146 #endif /* __cplusplus */
147
148 #endif /* crc16-tvb.h */