hc
2023-12-11 d2ccde1c8e90d38cee87a1b0309ad2827f3fd30d
kernel/net/mac80211/aes_cmac.c
....@@ -1,10 +1,7 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * AES-128-CMAC with TLen 16 for IEEE 802.11w BIP
34 * Copyright 2008, Jouni Malinen <j@w1.fi>
4
- *
5
- * This program is free software; you can redistribute it and/or modify
6
- * it under the terms of the GNU General Public License version 2 as
7
- * published by the Free Software Foundation.
85 */
96
107 #include <linux/kernel.h>
....@@ -29,12 +26,20 @@
2926 {
3027 SHASH_DESC_ON_STACK(desc, tfm);
3128 u8 out[AES_BLOCK_SIZE];
29
+ const __le16 *fc;
3230
3331 desc->tfm = tfm;
3432
3533 crypto_shash_init(desc);
3634 crypto_shash_update(desc, aad, AAD_LEN);
37
- crypto_shash_update(desc, data, data_len - CMAC_TLEN);
35
+ fc = (const __le16 *)aad;
36
+ if (ieee80211_is_beacon(*fc)) {
37
+ /* mask Timestamp field to zero */
38
+ crypto_shash_update(desc, zero, 8);
39
+ crypto_shash_update(desc, data + 8, data_len - 8 - CMAC_TLEN);
40
+ } else {
41
+ crypto_shash_update(desc, data, data_len - CMAC_TLEN);
42
+ }
3843 crypto_shash_finup(desc, zero, CMAC_TLEN, out);
3944
4045 memcpy(mic, out, CMAC_TLEN);
....@@ -44,12 +49,21 @@
4449 const u8 *data, size_t data_len, u8 *mic)
4550 {
4651 SHASH_DESC_ON_STACK(desc, tfm);
52
+ const __le16 *fc;
4753
4854 desc->tfm = tfm;
4955
5056 crypto_shash_init(desc);
5157 crypto_shash_update(desc, aad, AAD_LEN);
52
- crypto_shash_update(desc, data, data_len - CMAC_TLEN_256);
58
+ fc = (const __le16 *)aad;
59
+ if (ieee80211_is_beacon(*fc)) {
60
+ /* mask Timestamp field to zero */
61
+ crypto_shash_update(desc, zero, 8);
62
+ crypto_shash_update(desc, data + 8,
63
+ data_len - 8 - CMAC_TLEN_256);
64
+ } else {
65
+ crypto_shash_update(desc, data, data_len - CMAC_TLEN_256);
66
+ }
5367 crypto_shash_finup(desc, zero, CMAC_TLEN_256, mic);
5468 }
5569