2 * Declaration of CRC-32 routine and table
6 * Wireshark - Network traffic analyzer
7 * By Gerald Combs <gerald@wireshark.org>
8 * Copyright 1998 Gerald Combs
10 * Copied from README.developer
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.
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.
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.
32 #endif /* __cplusplus */
34 #define CRC32C_PRELOAD 0xffffffff
37 * Byte swap fix contributed by Dave Wysochanski <davidw@netapp.com>.
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))
45 #define CRC32C(c,d) (c=(c>>8)^crc32c_table[(c^(d))&0xFF])
47 extern const guint32 crc32c_table[256];
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);
56 extern const guint32 crc32_ccitt_table[256];
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);
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);
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);
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);
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);
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);
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);
114 #endif /* __cplusplus */