| Wireshark 4.7.0 The Wireshark network protocol analyzer

Loading...
Searching...
No Matches
dot11decrypt_int.h
Go to the documentation of this file.
1
9#ifndef _DOT11DECRYPT_INT_H
10#define _DOT11DECRYPT_INT_H
11
12/****************************************************************************/
13/* File includes */
14
15#include "dot11decrypt_system.h"
16
17#include "ws_attributes.h"
18#include <wsutil/wsgcrypt.h>
19
20/****************************************************************************/
21
22/****************************************************************************/
23/* Definitions */
24
25/* IEEE 802.11 packet type values */
26#define DOT11DECRYPT_TYPE_MANAGEMENT 0
27#define DOT11DECRYPT_TYPE_CONTROL 1
28#define DOT11DECRYPT_TYPE_DATA 2
29
30/* IEEE 802.11 packet subtype values */
31#define DOT11DECRYPT_SUBTYPE_ASSOC_REQ 0
32#define DOT11DECRYPT_SUBTYPE_ASSOC_RESP 1
33#define DOT11DECRYPT_SUBTYPE_REASSOC_REQ 2
34#define DOT11DECRYPT_SUBTYPE_REASSOC_RESP 3
35#define DOT11DECRYPT_SUBTYPE_PROBE_REQ 4
36#define DOT11DECRYPT_SUBTYPE_PROBE_RESP 5
37#define DOT11DECRYPT_SUBTYPE_MEASUREMENT_PILOT 6
38#define DOT11DECRYPT_SUBTYPE_BEACON 8
39#define DOT11DECRYPT_SUBTYPE_ATIM 9
40#define DOT11DECRYPT_SUBTYPE_DISASS 10
41#define DOT11DECRYPT_SUBTYPE_AUTHENTICATION 11
42#define DOT11DECRYPT_SUBTYPE_DEAUTHENTICATION 12
43#define DOT11DECRYPT_SUBTYPE_ACTION 13
44#define DOT11DECRYPT_SUBTYPE_ACTION_NO_ACK 14
45
46/* IEEE 802.11 cipher suite selectors */
47#define DOT11DECRYPT_CIPHER_USE_GROUP 0
48#define DOT11DECRYPT_CIPHER_WEP40 1
49#define DOT11DECRYPT_CIPHER_TKIP 2
50#define DOT11DECRYPT_CIPHER_CCMP 4
51#define DOT11DECRYPT_CIPHER_WEP104 5
52#define DOT11DECRYPT_CIPHER_BIP_CMAC 6
53#define DOT11DECRYPT_CIPHER_GROUP_NA 7
54#define DOT11DECRYPT_CIPHER_GCMP 8
55#define DOT11DECRYPT_CIPHER_GCMP256 9
56#define DOT11DECRYPT_CIPHER_CCMP256 10
57#define DOT11DECRYPT_CIPHER_BIP_GMAC 11
58#define DOT11DECRYPT_CIPHER_BIP_GMAC256 12
59#define DOT11DECRYPT_CIPHER_BIP_CMAC256 13
60
61/*
62 * Min length of encrypted data (WEP=9bytes, TKIP=21bytes, CCMP=17bytes, GCMP=25bytes)
63 * WEP = 4 octets of IV, 1 octet of data, 4 octets of ICV.
64 * TKIP = 4 octets of IV/Key ID, 4 octets of Extended IV, 1 octet of data,
65 * 8 octets of MIC, 4 octets of ICV.
66 * CCMP = 8 octets of CCMP header, 1 octet of data, 8 octets of MIC.
67 * GCMP = 8 octets of GCMP header, 1 octet of data, 16 octets of MIC.
68 */
69#define DOT11DECRYPT_CRYPTED_DATA_MINLEN 9
70
71#define DOT11DECRYPT_TA_OFFSET 10
72
73/* */
74/****************************************************************************/
75
76/****************************************************************************/
77/* Macro definitions */
78
82#define DOT11DECRYPT_TYPE(FrameControl_0) (uint8_t)((FrameControl_0 >> 2) & 0x3)
83#define DOT11DECRYPT_SUBTYPE(FrameControl_0) (uint8_t)((FrameControl_0 >> 4) & 0xF)
84#define DOT11DECRYPT_DS_BITS(FrameControl_1) (uint8_t)(FrameControl_1 & 0x3)
85#define DOT11DECRYPT_TO_DS(FrameControl_1) (uint8_t)(FrameControl_1 & 0x1)
86#define DOT11DECRYPT_FROM_DS(FrameControl_1) (uint8_t)((FrameControl_1 >> 1) & 0x1)
87#define DOT11DECRYPT_WEP(FrameControl_1) (uint8_t)((FrameControl_1 >> 6) & 0x1)
88
92#define DOT11DECRYPT_EXTIV(KeyID) ((KeyID >> 5) & 0x1)
93
94#define DOT11DECRYPT_KEY_INDEX(KeyID) ((KeyID >> 6) & 0x3)
96/* Macros to get various bits of an EAPOL frame */
97#define DOT11DECRYPT_EAP_KEY_DESCR_VER(KeyInfo_1) ((unsigned char)(KeyInfo_1 & 0x3))
98#define DOT11DECRYPT_EAP_KEY(KeyInfo_1) ((KeyInfo_1 >> 3) & 0x1)
99#define DOT11DECRYPT_EAP_INST(KeyInfo_1) ((KeyInfo_1 >> 6) & 0x1)
100#define DOT11DECRYPT_EAP_ACK(KeyInfo_1) ((KeyInfo_1 >> 7) & 0x1)
101#define DOT11DECRYPT_EAP_MIC(KeyInfo_0) (KeyInfo_0 & 0x1)
102#define DOT11DECRYPT_EAP_SEC(KeyInfo_0) ((KeyInfo_0 >> 1) & 0x1)
103
104/* Note: copied from net80211/ieee80211.h */
105#define DOT11DECRYPT_FC1_DIR_MASK 0x03
106#define DOT11DECRYPT_FC1_DIR_DSTODS 0x03 /* AP ->AP */
107#define DOT11DECRYPT_FC0_SUBTYPE_QOS 0x80
108#define DOT11DECRYPT_FC0_TYPE_DATA 0x08
109#define DOT11DECRYPT_FC0_TYPE_MASK 0x0c
110#define DOT11DECRYPT_SEQ_FRAG_MASK 0x000f
111#define DOT11DECRYPT_QOS_HAS_SEQ(wh) \
112 (((wh)->fc[0] & \
113 (DOT11DECRYPT_FC0_TYPE_MASK | DOT11DECRYPT_FC0_SUBTYPE_QOS)) == \
114 (DOT11DECRYPT_FC0_TYPE_DATA | DOT11DECRYPT_FC0_SUBTYPE_QOS))
115
116#define DOT11DECRYPT_ADDR_COPY(dst,src) memcpy(dst, src, DOT11DECRYPT_MAC_LEN)
117
118#define DOT11DECRYPT_IS_4ADDRESS(wh) \
119 ((wh->fc[1] & DOT11DECRYPT_FC1_DIR_MASK) == DOT11DECRYPT_FC1_DIR_DSTODS)
120#define DOT11DECRYPT_IS_QOS_DATA(wh) DOT11DECRYPT_QOS_HAS_SEQ(wh)
121
122/****************************************************************************/
123
124/****************************************************************************/
125/* Structure definitions */
126
127/*
128 * XXX - According to the thread at
129 * https://lists.wireshark.org/archives/wireshark-dev/200612/msg00384.html we
130 * shouldn't have to worry about packing our structs, since the largest
131 * elements are 8 bits wide.
132 */
133#ifdef _MSC_VER /* MS Visual C++ */
134#pragma pack(push)
135#pragma pack(1)
136#endif
137
138/* Definition of IEEE 802.11 frame (without the address 4) */
139 typedef struct _DOT11DECRYPT_MAC_FRAME {
140 unsigned char fc[2];
141 unsigned char dur[2];
142 unsigned char addr1[DOT11DECRYPT_MAC_LEN];
143 unsigned char addr2[DOT11DECRYPT_MAC_LEN];
144 unsigned char addr3[DOT11DECRYPT_MAC_LEN];
145 unsigned char seq[2];
146} DOT11DECRYPT_MAC_FRAME, *PDOT11DECRYPT_MAC_FRAME;
147
148/* Definition of IEEE 802.11 frame (with the address 4) */
149 typedef struct _DOT11DECRYPT_MAC_FRAME_ADDR4 {
150 unsigned char fc[2];
151 unsigned char dur[2];
152 unsigned char addr1[DOT11DECRYPT_MAC_LEN];
153 unsigned char addr2[DOT11DECRYPT_MAC_LEN];
154 unsigned char addr3[DOT11DECRYPT_MAC_LEN];
155 unsigned char seq[2];
156 unsigned char addr4[DOT11DECRYPT_MAC_LEN];
157} DOT11DECRYPT_MAC_FRAME_ADDR4, *PDOT11DECRYPT_MAC_FRAME_ADDR4;
158
159/* Definition of IEEE 802.11 frame (without the address 4, with QOS) */
160 typedef struct _DOT11DECRYPT_MAC_FRAME_QOS {
161 unsigned char fc[2];
162 unsigned char dur[2];
163 unsigned char addr1[DOT11DECRYPT_MAC_LEN];
164 unsigned char addr2[DOT11DECRYPT_MAC_LEN];
165 unsigned char addr3[DOT11DECRYPT_MAC_LEN];
166 unsigned char seq[2];
167 unsigned char qos[2];
168} DOT11DECRYPT_MAC_FRAME_QOS, *PDOT11DECRYPT_MAC_FRAME_QOS;
169
170/* Definition of IEEE 802.11 frame (with the address 4 and QOS) */
171 typedef struct _DOT11DECRYPT_MAC_FRAME_ADDR4_QOS {
172 unsigned char fc[2];
173 unsigned char dur[2];
174 unsigned char addr1[DOT11DECRYPT_MAC_LEN];
175 unsigned char addr2[DOT11DECRYPT_MAC_LEN];
176 unsigned char addr3[DOT11DECRYPT_MAC_LEN];
177 unsigned char seq[2];
178 unsigned char addr4[DOT11DECRYPT_MAC_LEN];
179 unsigned char qos[2];
180} DOT11DECRYPT_MAC_FRAME_ADDR4_QOS, *PDOT11DECRYPT_MAC_FRAME_ADDR4_QOS;
181
182#ifdef _MSC_VER /* MS Visual C++ */
183#pragma pack(pop)
184#endif
185
186/******************************************************************************/
187
188/*
189 * Decrypt CCMP encrypted MPDU.
190 *
191 * @Return
192 * - -1: Length constraint is not satisfied indicating that decryption is impossible
193 * - 1: Decryption fails
194 * - 0: Decryption succeeds
195 */
196 int Dot11DecryptCcmpDecrypt(
197 uint8_t *m,
198 int mac_header_len,
199 int len,
200 uint8_t *TK1,
201 int tk_len,
202 int mic_len);
203
204/*
205 * Decrypt GCMP encrypted MPDU.
206 *
207 * @Return
208 * - -1: Length constraint is not satisfied indicating that decryption is impossible
209 * - 1: Decryption fails
210 * - 0: Decryption succeeds
211 */
212 int Dot11DecryptGcmpDecrypt(
213 uint8_t *m,
214 int mac_header_len,
215 int len,
216 uint8_t *TK1,
217 int tk_len);
218
219/*
220 * Decrypt TKIP encrypted MPDU.
221 *
222 * @Return
223 * - -1: Length constraint is not satisfied indicating that decryption is impossible
224 * - 1: Decryption fails
225 * - 0: Decryption succeeds
226 */
227 int Dot11DecryptTkipDecrypt(
228 uint8_t *mpdu,
229 size_t mac_header_len,
230 size_t mpdu_len,
231 unsigned char TK[DOT11DECRYPT_TK_LEN]);
232
233/*
234 * Decrypt WEP-encrypted 802.11 payload using RC4 stream cipher.
235 *
236 * Performs WEP decryption on the provided `cypher_text` buffer using the RC4
237 * algorithm seeded with the specified initialization vector and WEP key.
238 * The decryption is done in-place, modifying `cypher_text` directly.
239 *
240 * This function assumes the input data is WEP-encrypted and that the seed
241 * contains both the IV and the shared WEP key. It verifies the ICV assumed
242 * to follow right after the cypher_text.
243 *
244 * @param seed Pointer to the RC4 seed (IV + WEP key).
245 * @param seed_len Length of the seed in bytes.
246 * @param cypher_text Pointer to the encrypted data buffer (will be decrypted in-place).
247 * @param data_len Length of the encrypted data in bytes.
248 * @return 0 on success, non-zero on failure.
249 */
250WS_DLL_PUBLIC int Dot11DecryptWepDecrypt(
251 const unsigned char *seed,
252 size_t seed_len,
253 unsigned char *cypher_text,
254 size_t data_len);
255
256#endif
dot11decrypt_system.h
_DOT11DECRYPT_MAC_FRAME_ADDR4_QOS
Definition dot11decrypt_int.h:171
_DOT11DECRYPT_MAC_FRAME_ADDR4
Definition dot11decrypt_int.h:149
_DOT11DECRYPT_MAC_FRAME_QOS
Definition dot11decrypt_int.h:160
_DOT11DECRYPT_MAC_FRAME
Definition dot11decrypt_int.h:139
wsgcrypt.h