1 /*
2  * crc16-plain.h
3  * http://www.tty1.net/pycrc/faq_en.html#code-ownership
4  *
5  * Wireshark - Network traffic analyzer
6  * By Gerald Combs <gerald@wireshark.org>
7  * Copyright 1998 Gerald Combs
8  *
9  * SPDX-License-Identifier: GPL-2.0-or-later
10  */
11 
12 /**
13  * \file crc16-plain.h
14  * Functions and types for CRC checks.
15  *
16  * Generated on Wed Mar 18 14:12:15 2009,
17  * by pycrc v0.7, http://www.tty1.net/pycrc/
18  * using the configuration:
19  *    Width        = 16
20  *    Poly         = 0x8005
21  *    XorIn        = 0x0000
22  *    ReflectIn    = True
23  *    XorOut       = 0x0000
24  *    ReflectOut   = True
25  *    Algorithm    = table-driven
26  *    Direct       = True
27  *
28  * Modified 2009-03-16 not to include <stdint.h> as our Win32 environment
29  * appears not to have it; we're using GLib types, instead.
30  *****************************************************************************/
31 #ifndef __CRC____PLAIN_H__
32 #define __CRC____PLAIN_H__
33 
34 #include "ws_symbol_export.h"
35 
36 #include <glib.h>
37 #include <stdlib.h>
38 
39 #ifdef __cplusplus
40 extern "C" {
41 #endif
42 
43 /**
44  * The definition of the used algorithm.
45  *****************************************************************************/
46 #define CRC_ALGO_TABLE_DRIVEN 1
47 
48 /**
49  * The type of the CRC values.
50  *
51  * This type must be big enough to contain at least 16 bits.
52  *****************************************************************************/
53 typedef guint16 crc16_plain_t;
54 
55 /**
56  * Reflect all bits of a \a data word of \a data_len bytes.
57  *
58  * \param data         The data word to be reflected.
59  * \param data_len     The width of \a data expressed in number of bits.
60  * \return     The reflected data.
61  *****************************************************************************/
62 long crc16_plain_reflect(long data, size_t data_len);
63 
64 /**
65  * Calculate the initial crc value.
66  *
67  * \return     The initial crc value.
68  *****************************************************************************/
crc16_plain_init(void)69 static inline crc16_plain_t crc16_plain_init(void)
70 {
71     return 0x0000;
72 }
73 
74 /**
75  * Update the crc value with new data.
76  *
77  * \param crc      The current crc value.
78  * \param data     Pointer to a buffer of \a data_len bytes.
79  * \param data_len Number of bytes in the \a data buffer.
80  * \return         The updated crc value.
81  *****************************************************************************/
82 WS_DLL_PUBLIC
83 crc16_plain_t crc16_plain_update(crc16_plain_t crc, const unsigned char *data, size_t data_len);
84 
85 /**
86  * Calculate the final crc value.
87  *
88  * \param crc  The current crc value.
89  * \return     The final crc value.
90  *****************************************************************************/
crc16_plain_finalize(crc16_plain_t crc)91 static inline crc16_plain_t crc16_plain_finalize(crc16_plain_t crc)
92 {
93     return crc ^ 0x0000;
94 }
95 
96 /* Generated on Tue Jul 24 09:08:46 2012,
97  * by pycrc v0.7.10, http://www.tty1.net/pycrc/
98  * using the configuration:
99  *    Width        = 16
100  *    Poly         = 0x8005
101  *    XorIn        = 0x0000
102  *    ReflectIn    = False
103  *    XorOut       = 0x0000
104  *    ReflectOut   = False
105  *    Algorithm    = table-driven
106  *
107  * Calculate the crc-16 (x^16 + x^15 + x^2 + 1) value for data. Note that this
108  * CRC is not equal to crc16_plain.
109  *
110  * \param data     Pointer to a buffer of \a data_len bytes.
111  * \param data_len Number of bytes in the \a data buffer.
112  * \return         The crc value.
113  *****************************************************************************/
114 WS_DLL_PUBLIC
115 guint16 crc16_8005_noreflect_noxor(const guint8 *data, guint64 data_len);
116 
117 
118 #ifdef __cplusplus
119 }           /* closing brace for extern "C" */
120 #endif
121 
122 #endif      /* __CRC____PLAIN_H__ */
123