3 * Copyright (c) 2006 CACE Technologies, Davis (California)
6 * SPDX-License-Identifier: (BSD-3-Clause OR GPL-2.0-only)
9 #ifndef _DOT11DECRYPT_USER_H
10 #define _DOT11DECRYPT_USER_H
12 /******************************************************************************/
17 #include "ws_symbol_export.h"
21 /******************************************************************************/
23 /******************************************************************************/
24 /* Constant definitions */
26 /* Decryption key types */
27 #define DOT11DECRYPT_KEY_TYPE_WEP 0
28 #define DOT11DECRYPT_KEY_TYPE_WEP_40 1
29 #define DOT11DECRYPT_KEY_TYPE_WEP_104 2
30 #define DOT11DECRYPT_KEY_TYPE_WPA_PWD 3
31 #define DOT11DECRYPT_KEY_TYPE_WPA_PSK 4
32 #define DOT11DECRYPT_KEY_TYPE_WPA_PMK 5
33 #define DOT11DECRYPT_KEY_TYPE_TK 6
34 #define DOT11DECRYPT_KEY_TYPE_MSK 7
36 #define DOT11DECRYPT_KEY_TYPE_TKIP 100
37 #define DOT11DECRYPT_KEY_TYPE_CCMP 101
38 #define DOT11DECRYPT_KEY_TYPE_CCMP_256 102
39 #define DOT11DECRYPT_KEY_TYPE_GCMP 103
40 #define DOT11DECRYPT_KEY_TYPE_GCMP_256 104
41 #define DOT11DECRYPT_KEY_TYPE_UNKNOWN -1
43 /* Decryption algorithms fields size definition (bytes) */
44 #define DOT11DECRYPT_WEP_KEY_MINLEN 1
45 #define DOT11DECRYPT_WEP_KEY_MAXLEN 32
46 #define DOT11DECRYPT_WEP_40_KEY_LEN 5
47 #define DOT11DECRYPT_WEP_104_KEY_LEN 13
49 #define DOT11DECRYPT_WPA_PASSPHRASE_MIN_LEN 8
50 #define DOT11DECRYPT_WPA_PASSPHRASE_MAX_LEN 63 /* null-terminated string, the actual length of the storage is 64 */
51 #define DOT11DECRYPT_WPA_SSID_MIN_LEN 0
52 #define DOT11DECRYPT_WPA_SSID_MAX_LEN 32
53 #define DOT11DECRYPT_WPA_PMK_MAX_LEN 48
54 #define DOT11DECRYPT_WPA_PWD_PSK_LEN 32
55 #define DOT11DECRYPT_TK_MAX_LEN 32
56 #define DOT11DECRYPT_MSK_MIN_LEN 64
57 #define DOT11DECRYPT_MSK_MAX_LEN 128
60 /******************************************************************************/
62 /******************************************************************************/
63 /* Macro definitions */
66 /******************************************************************************/
68 /******************************************************************************/
69 /* Type definitions */
72 * Struct to store info about a specific decryption key.
82 * Key item used during the decryption process.
84 typedef struct _DOT11DECRYPT_KEY_ITEM
{
86 * Type of key. The type will remain unchanged during the
87 * processing, even if some fields could be changed (e.g., WPA
90 * You can use constants DOT11DECRYPT_KEY_TYPE_xxx to indicate the
97 * This field can be used for the following decryptographic
98 * algorithms: WEP-40, with a key of 40 bits (10 hex-digits);
99 * WEP-104, with a key of 104 bits (or 26 hex-digits); WPA or
102 * For WPA/WPA2, the PMK is calculated from the PSK, and the PSK
103 * is calculated from the passphrase-SSID pair. You can enter one
104 * of these 3 values and subsequent fields will be automatically
107 * For WPA and WPA2 this implementation will use standards as
108 * defined in 802.11i (2004) and 802.1X (2004).
110 union DOT11DECRYPT_KEY_ITEMDATA
{
111 struct DOT11DECRYPT_KEY_ITEMDATA_WEP
{
113 * The binary value of the WEP key.
115 * It is accepted a key of length between
116 * DOT11DECRYPT_WEP_KEY_MINLEN and
117 * DOT11DECRYPT_WEP_KEY_MAXLEN. A WEP key
118 * standard-compliante should be either 40 bits
119 * (10 hex-digits, 5 bytes) for WEP-40 or 104 bits
120 * (26 hex-digits, 13 bytes) for WEP-104.
122 unsigned char WepKey
[DOT11DECRYPT_WEP_KEY_MAXLEN
];
124 * The length of the WEP key. Acceptable range
125 * is [DOT11DECRYPT_WEP_KEY_MINLEN;DOT11DECRYPT_WEP_KEY_MAXLEN].
131 * WPA/WPA2 key data. Note that the decryption process
132 * will use the PMK (equal to PSK), that is calculated
133 * from passphrase-SSID pair. You can define one of these
134 * three fields and necessary fields will be automatically
137 struct DOT11DECRYPT_KEY_ITEMDATA_WPA
{
138 unsigned char Psk
[DOT11DECRYPT_WPA_PMK_MAX_LEN
];
139 unsigned char Ptk
[DOT11DECRYPT_WPA_PTK_MAX_LEN
];
148 struct DOT11DECRYPT_KEY_ITEMDATA_TK
{
149 uint8_t Tk
[DOT11DECRYPT_TK_MAX_LEN
];
153 struct DOT11DECRYPT_KEY_ITEMDATA_MSK
{
154 uint8_t Msk
[DOT11DECRYPT_MSK_MAX_LEN
];
158 struct DOT11DECRYPT_KEY_ITEMDATA_PWD
{
160 * The octet string value of the passphrase.
161 * (The passphrase is technically an opaque octet string, even
162 * if recommended to be ASCII printable. It could (unlikely)
163 * even include internal NULs, which a Wireshark user could
164 * enter into the UAT percent-encoded.)
166 char Passphrase
[DOT11DECRYPT_WPA_PASSPHRASE_MAX_LEN
];
168 *The length of the passphrase
170 size_t PassphraseLen
;
172 * The value of the SSID (up to
173 * DOT11DECRYPT_WPA_SSID_MAX_LEN octets).
175 * A zero-length SSID indicates broadcast.
177 char Ssid
[DOT11DECRYPT_WPA_SSID_MAX_LEN
];
179 *The length of the SSID
183 } DOT11DECRYPT_KEY_ITEM
, *PDOT11DECRYPT_KEY_ITEM
;
186 * Collection of keys to use to decrypt packets
188 typedef struct _DOT11DECRYPT_KEYS_COLLECTION
{
190 * Number of stored keys
195 * Array of nKeys keys
197 DOT11DECRYPT_KEY_ITEM Keys
[256];
198 } DOT11DECRYPT_KEYS_COLLECTION
, *PDOT11DECRYPT_KEYS_COLLECTION
;
200 /******************************************************************************/
202 /******************************************************************************/
203 /* Function prototype declarations */
206 * Returns the decryption_key_t struct given a string describing the key.
207 * @param key_string [IN] Key string in one of the following formats:
208 * - 0102030405 (40/64-bit WEP)
209 * - 01:02:03:04:05 (40/64-bit WEP)
210 * - 0102030405060708090a0b0c0d (104/128-bit WEP)
211 * - 01:02:03:04:05:06:07:08:09:0a:0b:0c:0d (104/128-bit WEP)
212 * - MyPassword (WPA + plaintext password + "wildcard" SSID)
213 * - MyPassword:MySSID (WPA + plaintext password + specific SSID)
214 * - 01020304... (WPA + 256-bit raw key)
215 * @param key_type [IN] Type of key used for string. Possibilities include:
216 * - DOT11DECRYPT_KEY_TYPE_WEP (40/64-bit and 104/128-bit WEP)
217 * - DOT11DECRYPT_KEY_TYPE_WPA_PWD (WPA + plaintext password + "wildcard" SSID or
218 * WPA + plaintext password + specific SSID)
219 * - DOT11DECRYPT_KEY_TYPE_WPA_PSK (WPA + 256-bit raw key)
220 * @param error [OUT] If not NULL, on failure will be set to point to an
221 * error message explaining why parsing failed. Must be freed.
222 * @return A pointer to a freshly-g_malloc()ed decryption_key_t struct on
223 * success, or NULL on failure.
224 * @see free_key_string()
228 parse_key_string(char* key_string
, uint8_t key_type
, char **error
);
231 * Releases memory associated with a given decryption_key_t struct.
232 * @param dk [IN] Pointer to the key to be freed
233 * @see parse_key_string()
237 free_key_string(decryption_key_t
*dk
);
239 /******************************************************************************/
241 #endif /* _DOT11DECRYPT_USER_H */