hc
2024-10-22 8ac6c7a54ed1b98d142dce24b11c6de6a1e239a5
kernel/net/mac80211/aes_gmac.c
....@@ -1,10 +1,7 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * AES-GMAC for IEEE 802.11 BIP-GMAC-128 and BIP-GMAC-256
34 * Copyright 2015, Qualcomm Atheros, Inc.
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>
....@@ -20,10 +17,12 @@
2017 int ieee80211_aes_gmac(struct crypto_aead *tfm, const u8 *aad, u8 *nonce,
2118 const u8 *data, size_t data_len, u8 *mic)
2219 {
23
- struct scatterlist sg[4];
20
+ struct scatterlist sg[5];
2421 u8 *zero, *__aad, iv[AES_BLOCK_SIZE];
2522 struct aead_request *aead_req;
2623 int reqsize = sizeof(*aead_req) + crypto_aead_reqsize(tfm);
24
+ const __le16 *fc;
25
+ int ret;
2726
2827 if (data_len < GMAC_MIC_LEN)
2928 return -EINVAL;
....@@ -36,11 +35,22 @@
3635 __aad = zero + GMAC_MIC_LEN;
3736 memcpy(__aad, aad, GMAC_AAD_LEN);
3837
39
- sg_init_table(sg, 4);
40
- sg_set_buf(&sg[0], __aad, GMAC_AAD_LEN);
41
- sg_set_buf(&sg[1], data, data_len - GMAC_MIC_LEN);
42
- sg_set_buf(&sg[2], zero, GMAC_MIC_LEN);
43
- sg_set_buf(&sg[3], mic, GMAC_MIC_LEN);
38
+ fc = (const __le16 *)aad;
39
+ if (ieee80211_is_beacon(*fc)) {
40
+ /* mask Timestamp field to zero */
41
+ sg_init_table(sg, 5);
42
+ sg_set_buf(&sg[0], __aad, GMAC_AAD_LEN);
43
+ sg_set_buf(&sg[1], zero, 8);
44
+ sg_set_buf(&sg[2], data + 8, data_len - 8 - GMAC_MIC_LEN);
45
+ sg_set_buf(&sg[3], zero, GMAC_MIC_LEN);
46
+ sg_set_buf(&sg[4], mic, GMAC_MIC_LEN);
47
+ } else {
48
+ sg_init_table(sg, 4);
49
+ sg_set_buf(&sg[0], __aad, GMAC_AAD_LEN);
50
+ sg_set_buf(&sg[1], data, data_len - GMAC_MIC_LEN);
51
+ sg_set_buf(&sg[2], zero, GMAC_MIC_LEN);
52
+ sg_set_buf(&sg[3], mic, GMAC_MIC_LEN);
53
+ }
4454
4555 memcpy(iv, nonce, GMAC_NONCE_LEN);
4656 memset(iv + GMAC_NONCE_LEN, 0, sizeof(iv) - GMAC_NONCE_LEN);
....@@ -50,10 +60,10 @@
5060 aead_request_set_crypt(aead_req, sg, sg, 0, iv);
5161 aead_request_set_ad(aead_req, GMAC_AAD_LEN + data_len);
5262
53
- crypto_aead_encrypt(aead_req);
54
- kzfree(aead_req);
63
+ ret = crypto_aead_encrypt(aead_req);
64
+ kfree_sensitive(aead_req);
5565
56
- return 0;
66
+ return ret;
5767 }
5868
5969 struct crypto_aead *ieee80211_aes_gmac_key_setup(const u8 key[],