2 * CRC-32 tvbuff routines
6 * Wireshark - Network traffic analyzer
7 * By Gerald Combs <gerald@wireshark.org>
8 * Copyright 1998 Gerald Combs
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.
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.
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.
26 * Table from Solomon Peachy
27 * Routine from Chris Waters
33 #include <epan/tvbuff.h>
34 #include <wsutil/crc32.h>
35 #include <epan/crc32-tvb.h>
39 crc32_ccitt_tvb(tvbuff_t
*tvb
, guint len
)
43 tvb_ensure_bytes_exist(tvb
, 0, len
); /* len == -1 not allowed */
44 buf
= tvb_get_ptr(tvb
, 0, len
);
46 return ( crc32_ccitt_seed(buf
, len
, CRC32_CCITT_SEED
) );
50 crc32_ccitt_tvb_offset(tvbuff_t
*tvb
, guint offset
, guint len
)
54 tvb_ensure_bytes_exist(tvb
, offset
, len
); /* len == -1 not allowed */
55 buf
= tvb_get_ptr(tvb
, offset
, len
);
57 return ( crc32_ccitt(buf
, len
) );
61 crc32_ccitt_tvb_seed(tvbuff_t
*tvb
, guint len
, guint32 seed
)
65 tvb_ensure_bytes_exist(tvb
, 0, len
); /* len == -1 not allowed */
66 buf
= tvb_get_ptr(tvb
, 0, len
);
68 return ( crc32_ccitt_seed(buf
, len
, seed
) );
72 crc32_ccitt_tvb_offset_seed(tvbuff_t
*tvb
, guint offset
, guint len
,
77 tvb_ensure_bytes_exist(tvb
, offset
, len
); /* len == -1 not allowed */
78 buf
= tvb_get_ptr(tvb
, offset
, len
);
80 return ( crc32_ccitt_seed(buf
, len
, seed
) );
84 * IEEE 802.x version (Ethernet and 802.11, at least) - byte-swap
85 * the result of "crc32()".
87 * XXX - does this mean we should fetch the Ethernet and 802.11
88 * FCS with "tvb_get_letohl()" rather than "tvb_get_ntohl()",
89 * or is fetching it big-endian and byte-swapping the CRC done
90 * to cope with 802.x sending stuff out in reverse bit order?
93 crc32_802_tvb(tvbuff_t
*tvb
, guint len
)
97 c_crc
= crc32_ccitt_tvb(tvb
, len
);
100 c_crc
= GUINT32_SWAP_LE_BE(c_crc
);
106 crc32_mpeg2_tvb_offset_seed(tvbuff_t
*tvb
, guint offset
,
107 guint len
, guint32 seed
)
111 tvb_ensure_bytes_exist(tvb
, offset
, len
); /* len == -1 not allowed */
112 buf
= tvb_get_ptr(tvb
, offset
, len
);
114 return ( crc32_mpeg2_seed(buf
, len
, seed
) );
118 crc32_mpeg2_tvb(tvbuff_t
*tvb
, guint len
)
120 return ( crc32_mpeg2_tvb_offset_seed(tvb
, 0, len
, CRC32_MPEG2_SEED
) );
124 crc32_mpeg2_tvb_offset(tvbuff_t
*tvb
, guint offset
, guint len
)
126 return ( crc32_mpeg2_tvb_offset_seed(tvb
, offset
, len
, CRC32_MPEG2_SEED
) );
130 crc32_mpeg2_tvb_seed(tvbuff_t
*tvb
, guint len
, guint32 seed
)
132 return ( crc32_mpeg2_tvb_offset_seed(tvb
, 0, len
, seed
) );
135 guint32
crc32_0x0AA725CF_tvb_offset_seed(tvbuff_t
*tvb
,
136 guint offset
, guint len
, guint32 seed
)
140 tvb_ensure_bytes_exist(tvb
, offset
, len
); /* len == -1 not allowed */
141 buf
= tvb_get_ptr(tvb
, offset
, len
);
143 return crc32_0x0AA725CF_seed(buf
, len
, seed
);