From Alexis La Goutte:
[obnox/wireshark/wip.git] / epan / crc32.h
1 /* crc32.h
2  * Declaration of CRC-32 routine and table
3  *
4  * $Id$
5  *
6  * Wireshark - Network traffic analyzer
7  * By Gerald Combs <gerald@wireshark.org>
8  * Copyright 1998 Gerald Combs
9  *
10  * Copied from README.developer
11  *
12  * This program is free software; you can redistribute it and/or
13  * modify it under the terms of the GNU General Public License
14  * as published by the Free Software Foundation; either version 2
15  * of the License, or (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with this program; if not, write to the Free Software
24  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25  */
26
27 #ifndef __CRC32_H_
28 #define __CRC32_H_
29
30 #ifdef __cplusplus
31 extern "C" {
32 #endif /* __cplusplus */
33
34 #define CRC32C_PRELOAD 0xffffffff
35
36 /*
37  * Byte swap fix contributed by Dave Wysochanski <davidw@netapp.com>.
38  */
39 #define CRC32C_SWAP(crc32c_value)                               \
40         (((crc32c_value & 0xff000000) >> 24)    |       \
41          ((crc32c_value & 0x00ff0000) >>  8)    |       \
42          ((crc32c_value & 0x0000ff00) <<  8)    |       \
43          ((crc32c_value & 0x000000ff) << 24))
44
45 #define CRC32C(c,d) (c=(c>>8)^crc32c_table[(c^(d))&0xFF])
46
47 extern const guint32 crc32c_table[256];
48
49 /** Compute CRC32C checksum of a buffer of data.
50  @param buf The buffer containing the data.
51  @param len The number of bytes to include in the computation.
52  @param crc The preload value for the CRC32C computation.
53  @return The CRC32C checksum. */
54 extern guint32 crc32c_calculate(const void *buf, int len, guint32 crc);
55
56 extern const guint32 crc32_ccitt_table[256];
57
58 /** Compute CRC32 CCITT checksum of a buffer of data.
59  @param buf The buffer containing the data.
60  @param len The number of bytes to include in the computation.
61  @return The CRC32 CCITT checksum. */
62 extern guint32 crc32_ccitt(const guint8 *buf, guint len);
63
64 /** Compute CRC32 CCITT checksum of a buffer of data.  If computing the
65  *  checksum over multiple buffers and you want to feed the partial CRC32
66  *  back in, remember to take the 1's complement of the partial CRC32 first.
67  @param buf The buffer containing the data.
68  @param len The number of bytes to include in the computation.
69  @param seed The seed to use.
70  @return The CRC32 CCITT checksum (using the given seed). */
71 extern guint32 crc32_ccitt_seed(const guint8 *buf, guint len, guint32 seed);
72
73 /** Compute CRC32 CCITT checksum of a tv buffer.
74  @param tvb The tv buffer containing the data.
75  @param len The number of bytes to include in the computation.
76  @return The CRC32 CCITT checksum. */
77 extern guint32 crc32_ccitt_tvb(tvbuff_t *tvb, guint len);
78
79 /** Compute CRC32 CCITT checksum of a tv buffer.
80  @param tvb The tv buffer containing the data.
81  @param offset The offset into the tv buffer.
82  @param len The number of bytes to include in the computation.
83  @return The CRC32 CCITT checksum. */
84 extern guint32 crc32_ccitt_tvb_offset(tvbuff_t *tvb, guint offset, guint len);
85
86 /** Compute CRC32 CCITT checksum of a tv buffer.  If computing the
87  *  checksum over multiple tv buffers and you want to feed the partial CRC32
88  *  back in, remember to take the 1's complement of the partial CRC32 first.
89  @param tvb The tv buffer containing the data.
90  @param len The number of bytes to include in the computation.
91  @param seed The seed to use.
92  @return The CRC32 CCITT checksum (using the given seed). */
93 extern guint32 crc32_ccitt_tvb_seed(tvbuff_t *tvb, guint len, guint32 seed);
94
95 /** Compute CRC32 CCITT checksum of a tv buffer.  If computing the
96  *  checksum over multiple tv buffers and you want to feed the partial CRC32
97  *  back in, remember to take the 1's complement of the partial CRC32 first.
98  @param tvb The tv buffer containing the data.
99  @param offset The offset into the tv buffer.
100  @param len The number of bytes to include in the computation.
101  @param seed The seed to use.
102  @return The CRC32 CCITT checksum (using the given seed). */
103 extern guint32 crc32_ccitt_tvb_offset_seed(tvbuff_t *tvb, guint offset,
104                                            guint len, guint32 seed);
105
106 /** Compute IEEE 802.x CRC32 checksum of a tv buffer.
107  @param tvb The tv buffer containing the data.
108  @param len The number of bytes to include in the computation.
109  @return The IEEE 802.x CRC32 checksum. */
110 extern guint32 crc32_802_tvb(tvbuff_t *tvb, guint len);
111
112 #ifdef __cplusplus
113 }
114 #endif /* __cplusplus */
115
116 #endif /* crc32.h */