3 * Wireshark - Network traffic analyzer
4 * By Gerald Combs <gerald@wireshark.org>
5 * Copyright 1998 Gerald Combs
7 * SPDX-License-Identifier: GPL-2.0-or-later
10 /****************************************************************************/
14 #include "dot11decrypt_debug.h"
15 #include "dot11decrypt_int.h"
16 #include "dot11decrypt_system.h"
17 #include "dot11decrypt_util.h"
19 #include <wsutil/wsgcrypt.h>
21 /****************************************************************************/
22 /* Internal definitions */
24 /****************************************************************************/
27 #define READ_6(b0, b1, b2, b3, b4, b5) \
28 ((((uint64_t)((uint16_t)((b4 << 0) | (b5 << 8)))) << 32) | \
29 ((uint32_t)((b0 << 0) | (b1 << 8) | (b2 << 16) | (b3 << 24))))
31 /****************************************************************************/
32 /* Internal function prototypes declarations */
34 /****************************************************************************/
35 /* Function definitions */
37 /* From IEEE 802.11 2016 Chapter 12.5.5.3.4 Construct GCM nonce */
40 PDOT11DECRYPT_MAC_FRAME wh
,
45 DOT11DECRYPT_ADDR_COPY(nonce
, wh
->addr2
);
46 nonce
[6] = (uint8_t)(pn
>> 40);
47 nonce
[7] = (uint8_t)(pn
>> 32);
48 nonce
[8] = (uint8_t)(pn
>> 24);
49 nonce
[9] = (uint8_t)(pn
>> 16);
50 nonce
[10] = (uint8_t)(pn
>> 8);
51 nonce
[11] = (uint8_t)(pn
>> 0);
54 int Dot11DecryptGcmpDecrypt(
61 PDOT11DECRYPT_MAC_FRAME wh
;
67 int z
= mac_header_len
;
68 gcry_cipher_hd_t handle
;
72 wh
= (PDOT11DECRYPT_MAC_FRAME
)m
;
73 data_len
= len
- (z
+ DOT11DECRYPT_GCMP_HEADER
+ sizeof(mic
));
78 memcpy(mic
, m
+ len
- sizeof(mic
), sizeof(mic
));
79 pn
= READ_6(ivp
[0], ivp
[1], ivp
[4], ivp
[5], ivp
[6], ivp
[7]);
80 gcmp_construct_nonce(wh
, pn
, nonce
);
81 dot11decrypt_construct_aad(wh
, aad
, &aad_len
);
83 if (gcry_cipher_open(&handle
, GCRY_CIPHER_AES
, GCRY_CIPHER_MODE_GCM
, 0)) {
86 if (gcry_cipher_setkey(handle
, TK1
, tk_len
)) {
89 if (gcry_cipher_setiv(handle
, nonce
, sizeof(nonce
))) {
92 if (gcry_cipher_authenticate(handle
, aad
, aad_len
)) {
95 if (gcry_cipher_decrypt(handle
, m
+ z
+ DOT11DECRYPT_GCMP_HEADER
, data_len
, NULL
, 0)) {
98 if (gcry_cipher_checktag(handle
, mic
, sizeof(mic
))) {
102 /* TODO replay check (IEEE 802.11i-2004, pg. 62) */
103 /* TODO PN must be incremental (IEEE 802.11i-2004, pg. 62) */
105 gcry_cipher_close(handle
);
108 gcry_cipher_close(handle
);