| 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 IEEE80211_FC1_DIR_NODS 0x00 /* STA->STA */
107#define IEEE80211_FC1_DIR_TODS 0x01 /* STA->AP */
108#define IEEE80211_FC1_DIR_FROMDS 0x02 /* AP ->STA */
109#define DOT11DECRYPT_FC1_DIR_DSTODS 0x03 /* AP ->AP */
110#define DOT11DECRYPT_FC0_SUBTYPE_QOS 0x80
111#define DOT11DECRYPT_FC0_TYPE_DATA 0x08
112#define DOT11DECRYPT_FC0_TYPE_MASK 0x0c
113#define DOT11DECRYPT_SEQ_FRAG_MASK 0x000f
114#define DOT11DECRYPT_QOS_HAS_SEQ(wh) \
115 (((wh)->fc[0] & \
116 (DOT11DECRYPT_FC0_TYPE_MASK | DOT11DECRYPT_FC0_SUBTYPE_QOS)) == \
117 (DOT11DECRYPT_FC0_TYPE_DATA | DOT11DECRYPT_FC0_SUBTYPE_QOS))
118
119#define DOT11DECRYPT_ADDR_COPY(dst,src) memcpy(dst, src, DOT11DECRYPT_MAC_LEN)
120
121#define DOT11DECRYPT_IS_4ADDRESS(wh) \
122 ((wh->fc[1] & DOT11DECRYPT_FC1_DIR_MASK) == DOT11DECRYPT_FC1_DIR_DSTODS)
123#define DOT11DECRYPT_IS_QOS_DATA(wh) DOT11DECRYPT_QOS_HAS_SEQ(wh)
124
125/****************************************************************************/
126
127/****************************************************************************/
128/* Structure definitions */
129
130/*
131 * XXX - According to the thread at
132 * https://lists.wireshark.org/archives/wireshark-dev/200612/msg00384.html we
133 * shouldn't have to worry about packing our structs, since the largest
134 * elements are 8 bits wide.
135 */
136#ifdef _MSC_VER /* MS Visual C++ */
137#pragma pack(push)
138#pragma pack(1)
139#endif
140
141/* Definition of IEEE 802.11 frame (without the address 4) */
142 typedef struct _DOT11DECRYPT_MAC_FRAME {
143 unsigned char fc[2];
144 unsigned char dur[2];
145 unsigned char addr1[DOT11DECRYPT_MAC_LEN];
146 unsigned char addr2[DOT11DECRYPT_MAC_LEN];
147 unsigned char addr3[DOT11DECRYPT_MAC_LEN];
148 unsigned char seq[2];
149} DOT11DECRYPT_MAC_FRAME, *PDOT11DECRYPT_MAC_FRAME;
150
151/* Definition of IEEE 802.11 frame (with the address 4) */
152 typedef struct _DOT11DECRYPT_MAC_FRAME_ADDR4 {
153 unsigned char fc[2];
154 unsigned char dur[2];
155 unsigned char addr1[DOT11DECRYPT_MAC_LEN];
156 unsigned char addr2[DOT11DECRYPT_MAC_LEN];
157 unsigned char addr3[DOT11DECRYPT_MAC_LEN];
158 unsigned char seq[2];
159 unsigned char addr4[DOT11DECRYPT_MAC_LEN];
160} DOT11DECRYPT_MAC_FRAME_ADDR4, *PDOT11DECRYPT_MAC_FRAME_ADDR4;
161
162/* Definition of IEEE 802.11 frame (without the address 4, with QOS) */
163 typedef struct _DOT11DECRYPT_MAC_FRAME_QOS {
164 unsigned char fc[2];
165 unsigned char dur[2];
166 unsigned char addr1[DOT11DECRYPT_MAC_LEN];
167 unsigned char addr2[DOT11DECRYPT_MAC_LEN];
168 unsigned char addr3[DOT11DECRYPT_MAC_LEN];
169 unsigned char seq[2];
170 unsigned char qos[2];
171} DOT11DECRYPT_MAC_FRAME_QOS, *PDOT11DECRYPT_MAC_FRAME_QOS;
172
173/* Definition of IEEE 802.11 frame (with the address 4 and QOS) */
174 typedef struct _DOT11DECRYPT_MAC_FRAME_ADDR4_QOS {
175 unsigned char fc[2];
176 unsigned char dur[2];
177 unsigned char addr1[DOT11DECRYPT_MAC_LEN];
178 unsigned char addr2[DOT11DECRYPT_MAC_LEN];
179 unsigned char addr3[DOT11DECRYPT_MAC_LEN];
180 unsigned char seq[2];
181 unsigned char addr4[DOT11DECRYPT_MAC_LEN];
182 unsigned char qos[2];
183} DOT11DECRYPT_MAC_FRAME_ADDR4_QOS, *PDOT11DECRYPT_MAC_FRAME_ADDR4_QOS;
184
185#ifdef _MSC_VER /* MS Visual C++ */
186#pragma pack(pop)
187#endif
188
189/******************************************************************************/
190
191/*
192 * Decrypt CCMP encrypted MPDU.
193 *
194 * @Return
195 * - -1: Length constraint is not satisfied indicating that decryption is impossible
196 * - 1: Decryption fails
197 * - 0: Decryption succeeds
198 */
199 int Dot11DecryptCcmpDecrypt(
200 uint8_t *m,
201 int mac_header_len,
202 int len,
203 uint8_t *TK1,
204 int tk_len,
205 int mic_len,
206 const uint8_t *ap_mld_mac,
207 const uint8_t *sta_mld_mac);
208
209/*
210 * Decrypt GCMP encrypted MPDU.
211 *
212 * @Return
213 * - -1: Length constraint is not satisfied indicating that decryption is impossible
214 * - 1: Decryption fails
215 * - 0: Decryption succeeds
216 */
217 int Dot11DecryptGcmpDecrypt(
218 uint8_t *m,
219 int mac_header_len,
220 int len,
221 uint8_t *TK1,
222 int tk_len,
223 const uint8_t *ap_mld_mac,
224 const uint8_t *sta_mld_mac);
225
226/*
227 * Decrypt TKIP encrypted MPDU.
228 *
229 * @Return
230 * - -1: Length constraint is not satisfied indicating that decryption is impossible
231 * - 1: Decryption fails
232 * - 0: Decryption succeeds
233 */
234 int Dot11DecryptTkipDecrypt(
235 uint8_t *mpdu,
236 size_t mac_header_len,
237 size_t mpdu_len,
238 unsigned char TK[DOT11DECRYPT_TK_LEN]);
239
240/*
241 * Decrypt WEP-encrypted 802.11 payload using RC4 stream cipher.
242 *
243 * Performs WEP decryption on the provided `cypher_text` buffer using the RC4
244 * algorithm seeded with the specified initialization vector and WEP key.
245 * The decryption is done in-place, modifying `cypher_text` directly.
246 *
247 * This function assumes the input data is WEP-encrypted and that the seed
248 * contains both the IV and the shared WEP key. It verifies the ICV assumed
249 * to follow right after the cypher_text.
250 *
251 * @param seed Pointer to the RC4 seed (IV + WEP key).
252 * @param seed_len Length of the seed in bytes.
253 * @param cypher_text Pointer to the encrypted data buffer (will be decrypted in-place).
254 * @param data_len Length of the encrypted data in bytes.
255 * @return 0 on success, non-zero on failure.
256 */
257WS_DLL_PUBLIC int Dot11DecryptWepDecrypt(
258 const unsigned char *seed,
259 size_t seed_len,
260 unsigned char *cypher_text,
261 size_t data_len);
262
263#endif
dot11decrypt_system.h
_DOT11DECRYPT_MAC_FRAME_ADDR4_QOS
Definition dot11decrypt_int.h:174
_DOT11DECRYPT_MAC_FRAME_ADDR4
Definition dot11decrypt_int.h:152
_DOT11DECRYPT_MAC_FRAME_QOS
Definition dot11decrypt_int.h:163
_DOT11DECRYPT_MAC_FRAME
Definition dot11decrypt_int.h:142
wsgcrypt.h