4 * 2004 Richard van der Hoff <richardv@mxtelecom.com>
8 * Wireshark - Network traffic analyzer
9 * By Gerald Combs <gerald@wireshark.org>
10 * Copyright 1998 Gerald Combs
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
27 * "A Painless Guide to CRC Error Detection Algorithms", Ross Williams
28 * http://www.repairfaq.org/filipg/LINK/F_crc_v3.html
30 * ITU-T Recommendation V.42 (2002), "Error-Correcting Procedures for
31 * DCEs using asynchronous-to-synchronous conversion", Para. 8.1.1.6.1
37 #include <epan/tvbuff.h>
38 #include <wsutil/crc16.h>
39 #include <epan/crc16-tvb.h>
40 #include <wsutil/crc16-plain.h>
43 guint16 crc16_ccitt_tvb(tvbuff_t *tvb, guint len)
47 tvb_ensure_bytes_exist(tvb, 0, len); /* len == -1 not allowed */
48 buf = tvb_get_ptr(tvb, 0, len);
50 return crc16_ccitt(buf, len);
53 guint16 crc16_x25_ccitt_tvb(tvbuff_t *tvb, guint len)
57 tvb_ensure_bytes_exist(tvb, 0, len); /* len == -1 not allowed */
58 buf = tvb_get_ptr(tvb, 0, len);
60 return crc16_x25_ccitt(buf, len);
63 guint16 crc16_ccitt_tvb_offset(tvbuff_t *tvb, guint offset, guint len)
67 tvb_ensure_bytes_exist(tvb, offset, len); /* len == -1 not allowed */
68 buf = tvb_get_ptr(tvb, offset, len);
70 return crc16_ccitt(buf, len);
73 guint16 crc16_ccitt_tvb_seed(tvbuff_t *tvb, guint len, guint16 seed)
77 tvb_ensure_bytes_exist(tvb, 0, len); /* len == -1 not allowed */
78 buf = tvb_get_ptr(tvb, 0, len);
80 return crc16_ccitt_seed(buf, len, seed);
83 guint16 crc16_ccitt_tvb_offset_seed(tvbuff_t *tvb, guint offset, guint len, guint16 seed)
87 tvb_ensure_bytes_exist(tvb, offset, len); /* len == -1 not allowed */
88 buf = tvb_get_ptr(tvb, offset, len);
90 return crc16_ccitt_seed(buf, len, seed);
93 guint16 crc16_plain_tvb_offset(tvbuff_t *tvb, guint offset, guint len)
95 guint16 crc = crc16_plain_init();
98 tvb_ensure_bytes_exist(tvb, offset, len); /* len == -1 not allowed */
99 buf = tvb_get_ptr(tvb, offset, len);
101 crc = crc16_plain_update(crc, buf, len);
103 return crc16_plain_finalize(crc);
106 guint16 crc16_plain_tvb_offset_seed(tvbuff_t *tvb, guint offset, guint len, guint16 crc)
110 tvb_ensure_bytes_exist(tvb, offset, len); /* len == -1 not allowed */
111 buf = tvb_get_ptr(tvb, offset, len);
113 crc = crc16_plain_update(crc, buf, len);
115 return crc16_plain_finalize(crc);
118 guint16 crc16_0x9949_tvb_offset_seed(tvbuff_t *tvb, guint offset, guint len, guint16 seed)
122 tvb_ensure_bytes_exist(tvb, offset, len); /* len == -1 not allowed */
123 buf = tvb_get_ptr(tvb, offset, len);
125 return crc16_0x9949_seed(buf, len, seed);