Revert "LATER... ei_kerberos_kdc_session_key ..."
[wireshark-sm.git] / epan / crc32-tvb.c
blobe1ece4c4672e34ed48141e813c564bf177a5d2c1
1 /* crc32-tvb.c
2 * CRC-32 tvbuff routines
4 * Wireshark - Network traffic analyzer
5 * By Gerald Combs <gerald@wireshark.org>
6 * Copyright 1998 Gerald Combs
8 * SPDX-License-Identifier: GPL-2.0-or-later
10 * Credits:
12 * Table from Solomon Peachy
13 * Routine from Chris Waters
16 #include "config.h"
18 #include <glib.h>
19 #include <epan/tvbuff.h>
20 #include <wsutil/crc32.h>
21 #include <epan/crc32-tvb.h>
24 uint32_t
25 crc32_ccitt_tvb(tvbuff_t *tvb, unsigned len)
27 const uint8_t* buf;
29 tvb_ensure_bytes_exist(tvb, 0, len); /* len == -1 not allowed */
30 buf = tvb_get_ptr(tvb, 0, len);
32 return ( crc32_ccitt_seed(buf, len, CRC32_CCITT_SEED) );
35 uint32_t
36 crc32_ccitt_tvb_offset(tvbuff_t *tvb, unsigned offset, unsigned len)
38 const uint8_t* buf;
40 tvb_ensure_bytes_exist(tvb, offset, len); /* len == -1 not allowed */
41 buf = tvb_get_ptr(tvb, offset, len);
43 return ( crc32_ccitt(buf, len) );
46 uint32_t
47 crc32_ccitt_tvb_seed(tvbuff_t *tvb, unsigned len, uint32_t seed)
49 const uint8_t* buf;
51 tvb_ensure_bytes_exist(tvb, 0, len); /* len == -1 not allowed */
52 buf = tvb_get_ptr(tvb, 0, len);
54 return ( crc32_ccitt_seed(buf, len, seed) );
57 uint32_t
58 crc32_ccitt_tvb_offset_seed(tvbuff_t *tvb, unsigned offset, unsigned len,
59 uint32_t seed)
61 const uint8_t* buf;
63 tvb_ensure_bytes_exist(tvb, offset, len); /* len == -1 not allowed */
64 buf = tvb_get_ptr(tvb, offset, len);
66 return ( crc32_ccitt_seed(buf, len, seed) );
69 uint32_t
70 crc32c_tvb_offset_calculate(tvbuff_t *tvb, unsigned offset, unsigned len, uint32_t seed)
72 const uint8_t* buf;
74 tvb_ensure_bytes_exist(tvb, offset, len); /* len == -1 not allowed */
75 buf = tvb_get_ptr(tvb, offset, len);
77 return ( crc32c_calculate(buf, len, seed) );
81 * IEEE 802.x version (Ethernet and 802.11, at least) - byte-swap
82 * the result of "crc32()".
84 * XXX - does this mean we should fetch the Ethernet and 802.11
85 * FCS with "tvb_get_letohl()" rather than "tvb_get_ntohl()",
86 * or is fetching it big-endian and byte-swapping the CRC done
87 * to cope with 802.x sending stuff out in reverse bit order?
89 uint32_t
90 crc32_802_tvb(tvbuff_t *tvb, unsigned len)
92 uint32_t c_crc;
94 c_crc = crc32_ccitt_tvb(tvb, len);
96 /* Byte reverse. */
97 c_crc = GUINT32_SWAP_LE_BE(c_crc);
99 return ( c_crc );
102 uint32_t
103 crc32_mpeg2_tvb_offset_seed(tvbuff_t *tvb, unsigned offset,
104 unsigned len, uint32_t seed)
106 const uint8_t* buf;
108 tvb_ensure_bytes_exist(tvb, offset, len); /* len == -1 not allowed */
109 buf = tvb_get_ptr(tvb, offset, len);
111 return ( crc32_mpeg2_seed(buf, len, seed) );
114 uint32_t
115 crc32_mpeg2_tvb(tvbuff_t *tvb, unsigned len)
117 return ( crc32_mpeg2_tvb_offset_seed(tvb, 0, len, CRC32_MPEG2_SEED) );
120 uint32_t
121 crc32_mpeg2_tvb_offset(tvbuff_t *tvb, unsigned offset, unsigned len)
123 return ( crc32_mpeg2_tvb_offset_seed(tvb, offset, len, CRC32_MPEG2_SEED) );
126 uint32_t
127 crc32_mpeg2_tvb_seed(tvbuff_t *tvb, unsigned len, uint32_t seed)
129 return ( crc32_mpeg2_tvb_offset_seed(tvb, 0, len, seed) );
132 uint32_t crc32_0x0AA725CF_tvb_offset_seed(tvbuff_t *tvb,
133 unsigned offset, unsigned len, uint32_t seed)
135 const uint8_t *buf;
137 tvb_ensure_bytes_exist(tvb, offset, len); /* len == -1 not allowed */
138 buf = tvb_get_ptr(tvb, offset, len);
140 return crc32_0x0AA725CF_seed(buf, len, seed);
144 * Editor modelines - https://www.wireshark.org/tools/modelines.html
146 * Local variables:
147 * c-basic-offset: 8
148 * tab-width: 8
149 * indent-tabs-mode: t
150 * End:
152 * vi: set shiftwidth=8 tabstop=8 noexpandtab:
153 * :indentSize=8:tabSize=8:noTabs=false: