2 * CRC-32 tvbuff routines
4 * Wireshark - Network traffic analyzer
5 * By Gerald Combs <gerald@wireshark.org>
6 * Copyright 1998 Gerald Combs
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 * Table from Solomon Peachy
25 * Routine from Chris Waters
31 #include <epan/tvbuff.h>
32 #include <wsutil/crc32.h>
33 #include <epan/crc32-tvb.h>
37 crc32_ccitt_tvb(tvbuff_t *tvb, guint len)
41 tvb_ensure_bytes_exist(tvb, 0, len); /* len == -1 not allowed */
42 buf = tvb_get_ptr(tvb, 0, len);
44 return ( crc32_ccitt_seed(buf, len, CRC32_CCITT_SEED) );
48 crc32_ccitt_tvb_offset(tvbuff_t *tvb, guint offset, guint len)
52 tvb_ensure_bytes_exist(tvb, offset, len); /* len == -1 not allowed */
53 buf = tvb_get_ptr(tvb, offset, len);
55 return ( crc32_ccitt(buf, len) );
59 crc32_ccitt_tvb_seed(tvbuff_t *tvb, guint len, guint32 seed)
63 tvb_ensure_bytes_exist(tvb, 0, len); /* len == -1 not allowed */
64 buf = tvb_get_ptr(tvb, 0, len);
66 return ( crc32_ccitt_seed(buf, len, seed) );
70 crc32_ccitt_tvb_offset_seed(tvbuff_t *tvb, guint offset, guint len,
75 tvb_ensure_bytes_exist(tvb, offset, len); /* len == -1 not allowed */
76 buf = tvb_get_ptr(tvb, offset, len);
78 return ( crc32_ccitt_seed(buf, len, seed) );
82 crc32c_tvb_offset_calculate(tvbuff_t *tvb, guint offset, guint len, guint32 seed)
86 tvb_ensure_bytes_exist(tvb, offset, len); /* len == -1 not allowed */
87 buf = tvb_get_ptr(tvb, offset, len);
89 return ( crc32c_calculate(buf, len, seed) );
93 * IEEE 802.x version (Ethernet and 802.11, at least) - byte-swap
94 * the result of "crc32()".
96 * XXX - does this mean we should fetch the Ethernet and 802.11
97 * FCS with "tvb_get_letohl()" rather than "tvb_get_ntohl()",
98 * or is fetching it big-endian and byte-swapping the CRC done
99 * to cope with 802.x sending stuff out in reverse bit order?
102 crc32_802_tvb(tvbuff_t *tvb, guint len)
106 c_crc = crc32_ccitt_tvb(tvb, len);
109 c_crc = GUINT32_SWAP_LE_BE(c_crc);
115 crc32_mpeg2_tvb_offset_seed(tvbuff_t *tvb, guint offset,
116 guint len, guint32 seed)
120 tvb_ensure_bytes_exist(tvb, offset, len); /* len == -1 not allowed */
121 buf = tvb_get_ptr(tvb, offset, len);
123 return ( crc32_mpeg2_seed(buf, len, seed) );
127 crc32_mpeg2_tvb(tvbuff_t *tvb, guint len)
129 return ( crc32_mpeg2_tvb_offset_seed(tvb, 0, len, CRC32_MPEG2_SEED) );
133 crc32_mpeg2_tvb_offset(tvbuff_t *tvb, guint offset, guint len)
135 return ( crc32_mpeg2_tvb_offset_seed(tvb, offset, len, CRC32_MPEG2_SEED) );
139 crc32_mpeg2_tvb_seed(tvbuff_t *tvb, guint len, guint32 seed)
141 return ( crc32_mpeg2_tvb_offset_seed(tvb, 0, len, seed) );
144 guint32 crc32_0x0AA725CF_tvb_offset_seed(tvbuff_t *tvb,
145 guint offset, guint len, guint32 seed)
149 tvb_ensure_bytes_exist(tvb, offset, len); /* len == -1 not allowed */
150 buf = tvb_get_ptr(tvb, offset, len);
152 return crc32_0x0AA725CF_seed(buf, len, seed);
156 * Editor modelines - http://www.wireshark.org/tools/modelines.html
161 * indent-tabs-mode: t
164 * vi: set shiftwidth=8 tabstop=8 noexpandtab:
165 * :indentSize=8:tabSize=8:noTabs=false: