WIP: fsctl_pipe_wait
[metze/wireshark/wip.git] / wsutil / crc32.h
1 /* crc32.h
2  * Declaration of CRC-32 routine and table
3  *
4  * $Id$
5  *
6  * Wireshark - Network traffic analyzer
7  * By Gerald Combs <gerald@wireshark.org>
8  * Copyright 1998 Gerald Combs
9  *
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.
14  *
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.
19  *
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.
23  */
24
25 #ifndef __CRC32_H__
26 #define __CRC32_H__
27
28 #include "ws_symbol_export.h"
29
30 #ifdef __cplusplus
31 extern "C" {
32 #endif /* __cplusplus */
33
34 #define CRC32_CCITT_SEED 0xFFFFFFFF
35 #define CRC32C_PRELOAD   0xffffffff
36 #define CRC32_MPEG2_SEED 0xFFFFFFFF
37
38 /*
39  * Byte swap fix contributed by Dave Wysochanski <davidw@netapp.com>.
40  */
41 #define CRC32C_SWAP(crc32c_value)                               \
42         (((crc32c_value & 0xff000000) >> 24)    |       \
43          ((crc32c_value & 0x00ff0000) >>  8)    |       \
44          ((crc32c_value & 0x0000ff00) <<  8)    |       \
45          ((crc32c_value & 0x000000ff) << 24))
46
47 /** Lookup the crc value in the crc32_ccitt_table
48  @param pos Position in the table. */
49 WS_DLL_PUBLIC guint32 crc32_ccitt_table_lookup (guchar pos);
50
51 /** Lookup the crc value in the crc32c_table
52  @param pos Position in the table. */
53 WS_DLL_PUBLIC guint32 crc32c_table_lookup (guchar pos);
54
55 /** Compute CRC32C checksum of a buffer of data.
56  @param buf The buffer containing the data.
57  @param len The number of bytes to include in the computation.
58  @param crc The preload value for the CRC32C computation.
59  @return The CRC32C checksum. */
60 WS_DLL_PUBLIC guint32 crc32c_calculate(const void *buf, int len, guint32 crc);
61
62 /** Compute CRC32C checksum of a buffer of data without swapping seed crc
63  or completed checksum
64  @param buf The buffer containing the data.
65  @param len The number of bytes to include in the computation.
66  @param crc The preload value for the CRC32C computation.
67  @return The CRC32C checksum. */
68 WS_DLL_PUBLIC guint32 crc32c_calculate_no_swap(const void *buf, int len, guint32 crc);
69
70 /** Compute CRC32 CCITT checksum of a buffer of data.
71  @param buf The buffer containing the data.
72  @param len The number of bytes to include in the computation.
73  @return The CRC32 CCITT checksum. */
74 WS_DLL_PUBLIC guint32 crc32_ccitt(const guint8 *buf, guint len);
75
76 /** Compute CRC32 CCITT checksum of a buffer of data.  If computing the
77  *  checksum over multiple buffers and you want to feed the partial CRC32
78  *  back in, remember to take the 1's complement of the partial CRC32 first.
79  @param buf The buffer containing the data.
80  @param len The number of bytes to include in the computation.
81  @param seed The seed to use.
82  @return The CRC32 CCITT checksum (using the given seed). */
83 WS_DLL_PUBLIC guint32 crc32_ccitt_seed(const guint8 *buf, guint len, guint32 seed);
84
85 /** Compute MPEG-2 CRC32 checksum of a buffer of data.
86  @param buf The buffer containing the data.
87  @param len The number of bytes to include in the computation.
88  @param seed The seed to use.
89  @return The CRC32 MPEG-2 checksum (using the given seed). */
90 WS_DLL_PUBLIC guint32 crc32_mpeg2_seed(const guint8 *buf, guint len, guint32 seed);
91
92 /** Computes CRC32 checksum for the given data with the polynom 0x0AA725CF using
93  *  precompiled CRC table
94  * @param buf a pointer to a buffer of the given length
95  * @param len the length of the given buffer
96  * @param seed The seed to use.
97  * @return the CRC32 checksum for the buffer
98  */
99 WS_DLL_PUBLIC guint32 crc32_0x0AA725CF_seed(const guint8 *buf, guint len, guint32 seed);
100
101 WS_DLL_PUBLIC int AirPDcapWepDecrypt(
102         const guchar *seed,
103         const size_t seed_len,
104         guchar *cypher_text,
105         const size_t data_len);
106
107 #ifdef __cplusplus
108 }
109 #endif /* __cplusplus */
110
111 #endif /* crc32.h */