blob: a03b060918f55fcccd2b4f3f246febc9464baf06 [file] [log] [blame]
b.liue9582032025-04-17 19:18:16 +08001--- a/net/mac80211/Makefile
2+++ b/net/mac80211/Makefile
3@@ -7,7 +7,6 @@ mac80211-y := \
4 driver-ops.o \
5 sta_info.o \
6 wep.o \
7- aead_api.o \
8 wpa.o \
9 scan.o offchannel.o \
10 ht.o agg-tx.o agg-rx.o \
11@@ -19,8 +18,8 @@ mac80211-y := \
12 rate.o \
13 michael.o \
14 tkip.o \
15+ aes_ccm.o \
16 aes_cmac.o \
17- aes_gmac.o \
18 fils_aead.o \
19 cfg.o \
20 ethtool.o \
21--- a/net/mac80211/aead_api.c
22+++ /dev/null
23@@ -1,113 +0,0 @@
24-// SPDX-License-Identifier: GPL-2.0-only
25-/*
26- * Copyright 2003-2004, Instant802 Networks, Inc.
27- * Copyright 2005-2006, Devicescape Software, Inc.
28- * Copyright 2014-2015, Qualcomm Atheros, Inc.
29- *
30- * Rewrite: Copyright (C) 2013 Linaro Ltd <ard.biesheuvel@linaro.org>
31- */
32-
33-#include <linux/kernel.h>
34-#include <linux/types.h>
35-#include <linux/err.h>
36-#include <linux/scatterlist.h>
37-#include <crypto/aead.h>
38-
39-#include "aead_api.h"
40-
41-int aead_encrypt(struct crypto_aead *tfm, u8 *b_0, u8 *aad, size_t aad_len,
42- u8 *data, size_t data_len, u8 *mic)
43-{
44- size_t mic_len = crypto_aead_authsize(tfm);
45- struct scatterlist sg[3];
46- struct aead_request *aead_req;
47- int reqsize = sizeof(*aead_req) + crypto_aead_reqsize(tfm);
48- u8 *__aad;
49- int ret;
50-
51- aead_req = kzalloc(reqsize + aad_len, GFP_ATOMIC);
52- if (!aead_req)
53- return -ENOMEM;
54-
55- __aad = (u8 *)aead_req + reqsize;
56- memcpy(__aad, aad, aad_len);
57-
58- sg_init_table(sg, 3);
59- sg_set_buf(&sg[0], __aad, aad_len);
60- sg_set_buf(&sg[1], data, data_len);
61- sg_set_buf(&sg[2], mic, mic_len);
62-
63- aead_request_set_tfm(aead_req, tfm);
64- aead_request_set_crypt(aead_req, sg, sg, data_len, b_0);
65- aead_request_set_ad(aead_req, sg[0].length);
66-
67- ret = crypto_aead_encrypt(aead_req);
68- kfree_sensitive(aead_req);
69-
70- return ret;
71-}
72-
73-int aead_decrypt(struct crypto_aead *tfm, u8 *b_0, u8 *aad, size_t aad_len,
74- u8 *data, size_t data_len, u8 *mic)
75-{
76- size_t mic_len = crypto_aead_authsize(tfm);
77- struct scatterlist sg[3];
78- struct aead_request *aead_req;
79- int reqsize = sizeof(*aead_req) + crypto_aead_reqsize(tfm);
80- u8 *__aad;
81- int err;
82-
83- if (data_len == 0)
84- return -EINVAL;
85-
86- aead_req = kzalloc(reqsize + aad_len, GFP_ATOMIC);
87- if (!aead_req)
88- return -ENOMEM;
89-
90- __aad = (u8 *)aead_req + reqsize;
91- memcpy(__aad, aad, aad_len);
92-
93- sg_init_table(sg, 3);
94- sg_set_buf(&sg[0], __aad, aad_len);
95- sg_set_buf(&sg[1], data, data_len);
96- sg_set_buf(&sg[2], mic, mic_len);
97-
98- aead_request_set_tfm(aead_req, tfm);
99- aead_request_set_crypt(aead_req, sg, sg, data_len + mic_len, b_0);
100- aead_request_set_ad(aead_req, sg[0].length);
101-
102- err = crypto_aead_decrypt(aead_req);
103- kfree_sensitive(aead_req);
104-
105- return err;
106-}
107-
108-struct crypto_aead *
109-aead_key_setup_encrypt(const char *alg, const u8 key[],
110- size_t key_len, size_t mic_len)
111-{
112- struct crypto_aead *tfm;
113- int err;
114-
115- tfm = crypto_alloc_aead(alg, 0, CRYPTO_ALG_ASYNC);
116- if (IS_ERR(tfm))
117- return tfm;
118-
119- err = crypto_aead_setkey(tfm, key, key_len);
120- if (err)
121- goto free_aead;
122- err = crypto_aead_setauthsize(tfm, mic_len);
123- if (err)
124- goto free_aead;
125-
126- return tfm;
127-
128-free_aead:
129- crypto_free_aead(tfm);
130- return ERR_PTR(err);
131-}
132-
133-void aead_key_free(struct crypto_aead *tfm)
134-{
135- crypto_free_aead(tfm);
136-}
137--- a/net/mac80211/aead_api.h
138+++ /dev/null
139@@ -1,23 +0,0 @@
140-/* SPDX-License-Identifier: GPL-2.0-only */
141-
142-#ifndef _AEAD_API_H
143-#define _AEAD_API_H
144-
145-#include <crypto/aead.h>
146-#include <linux/crypto.h>
147-
148-struct crypto_aead *
149-aead_key_setup_encrypt(const char *alg, const u8 key[],
150- size_t key_len, size_t mic_len);
151-
152-int aead_encrypt(struct crypto_aead *tfm, u8 *b_0, u8 *aad,
153- size_t aad_len, u8 *data,
154- size_t data_len, u8 *mic);
155-
156-int aead_decrypt(struct crypto_aead *tfm, u8 *b_0, u8 *aad,
157- size_t aad_len, u8 *data,
158- size_t data_len, u8 *mic);
159-
160-void aead_key_free(struct crypto_aead *tfm);
161-
162-#endif /* _AEAD_API_H */
163--- a/net/mac80211/aes_ccm.h
164+++ b/net/mac80211/aes_ccm.h
165@@ -7,39 +7,17 @@
166 #ifndef AES_CCM_H
167 #define AES_CCM_H
168
169-#include "aead_api.h"
170+#include <linux/crypto.h>
171
172-#define CCM_AAD_LEN 32
173-
174-static inline struct crypto_aead *
175-ieee80211_aes_key_setup_encrypt(const u8 key[], size_t key_len, size_t mic_len)
176-{
177- return aead_key_setup_encrypt("ccm(aes)", key, key_len, mic_len);
178-}
179-
180-static inline int
181-ieee80211_aes_ccm_encrypt(struct crypto_aead *tfm,
182- u8 *b_0, u8 *aad, u8 *data,
183- size_t data_len, u8 *mic)
184-{
185- return aead_encrypt(tfm, b_0, aad + 2,
186- be16_to_cpup((__be16 *)aad),
187- data, data_len, mic);
188-}
189-
190-static inline int
191-ieee80211_aes_ccm_decrypt(struct crypto_aead *tfm,
192- u8 *b_0, u8 *aad, u8 *data,
193- size_t data_len, u8 *mic)
194-{
195- return aead_decrypt(tfm, b_0, aad + 2,
196- be16_to_cpup((__be16 *)aad),
197- data, data_len, mic);
198-}
199-
200-static inline void ieee80211_aes_key_free(struct crypto_aead *tfm)
201-{
202- return aead_key_free(tfm);
203-}
204+struct crypto_cipher *ieee80211_aes_key_setup_encrypt(const u8 key[],
205+ size_t key_len,
206+ size_t mic_len);
207+void ieee80211_aes_ccm_encrypt(struct crypto_cipher *tfm, u8 *b_0, u8 *aad,
208+ u8 *data, size_t data_len, u8 *mic,
209+ size_t mic_len);
210+int ieee80211_aes_ccm_decrypt(struct crypto_cipher *tfm, u8 *b_0, u8 *aad,
211+ u8 *data, size_t data_len, u8 *mic,
212+ size_t mic_len);
213+void ieee80211_aes_key_free(struct crypto_cipher *tfm);
214
215 #endif /* AES_CCM_H */
216--- /dev/null
217+++ b/net/mac80211/aes_gcm.c
218@@ -0,0 +1,109 @@
219+/*
220+ * Copyright 2014-2015, Qualcomm Atheros, Inc.
221+ *
222+ * This program is free software; you can redistribute it and/or modify
223+ * it under the terms of the GNU General Public License version 2 as
224+ * published by the Free Software Foundation.
225+ */
226+
227+#include <linux/kernel.h>
228+#include <linux/types.h>
229+#include <linux/err.h>
230+#include <crypto/aead.h>
231+
232+#include <net/mac80211.h>
233+#include "key.h"
234+#include "aes_gcm.h"
235+
236+int ieee80211_aes_gcm_encrypt(struct crypto_aead *tfm, u8 *j_0, u8 *aad,
237+ u8 *data, size_t data_len, u8 *mic)
238+{
239+ struct scatterlist sg[3];
240+ struct aead_request *aead_req;
241+ int reqsize = sizeof(*aead_req) + crypto_aead_reqsize(tfm);
242+ u8 *__aad;
243+
244+ aead_req = kzalloc(reqsize + GCM_AAD_LEN, GFP_ATOMIC);
245+ if (!aead_req)
246+ return -ENOMEM;
247+
248+ __aad = (u8 *)aead_req + reqsize;
249+ memcpy(__aad, aad, GCM_AAD_LEN);
250+
251+ sg_init_table(sg, 3);
252+ sg_set_buf(&sg[0], &__aad[2], be16_to_cpup((__be16 *)__aad));
253+ sg_set_buf(&sg[1], data, data_len);
254+ sg_set_buf(&sg[2], mic, IEEE80211_GCMP_MIC_LEN);
255+
256+ aead_request_set_tfm(aead_req, tfm);
257+ aead_request_set_crypt(aead_req, sg, sg, data_len, j_0);
258+ aead_request_set_ad(aead_req, sg[0].length);
259+
260+ crypto_aead_encrypt(aead_req);
261+ kzfree(aead_req);
262+ return 0;
263+}
264+
265+int ieee80211_aes_gcm_decrypt(struct crypto_aead *tfm, u8 *j_0, u8 *aad,
266+ u8 *data, size_t data_len, u8 *mic)
267+{
268+ struct scatterlist sg[3];
269+ struct aead_request *aead_req;
270+ int reqsize = sizeof(*aead_req) + crypto_aead_reqsize(tfm);
271+ u8 *__aad;
272+ int err;
273+
274+ if (data_len == 0)
275+ return -EINVAL;
276+
277+ aead_req = kzalloc(reqsize + GCM_AAD_LEN, GFP_ATOMIC);
278+ if (!aead_req)
279+ return -ENOMEM;
280+
281+ __aad = (u8 *)aead_req + reqsize;
282+ memcpy(__aad, aad, GCM_AAD_LEN);
283+
284+ sg_init_table(sg, 3);
285+ sg_set_buf(&sg[0], &__aad[2], be16_to_cpup((__be16 *)__aad));
286+ sg_set_buf(&sg[1], data, data_len);
287+ sg_set_buf(&sg[2], mic, IEEE80211_GCMP_MIC_LEN);
288+
289+ aead_request_set_tfm(aead_req, tfm);
290+ aead_request_set_crypt(aead_req, sg, sg,
291+ data_len + IEEE80211_GCMP_MIC_LEN, j_0);
292+ aead_request_set_ad(aead_req, sg[0].length);
293+
294+ err = crypto_aead_decrypt(aead_req);
295+ kzfree(aead_req);
296+
297+ return err;
298+}
299+
300+struct crypto_aead *ieee80211_aes_gcm_key_setup_encrypt(const u8 key[],
301+ size_t key_len)
302+{
303+ struct crypto_aead *tfm;
304+ int err;
305+
306+ tfm = crypto_alloc_aead("gcm(aes)", 0, CRYPTO_ALG_ASYNC);
307+ if (IS_ERR(tfm))
308+ return tfm;
309+
310+ err = crypto_aead_setkey(tfm, key, key_len);
311+ if (err)
312+ goto free_aead;
313+ err = crypto_aead_setauthsize(tfm, IEEE80211_GCMP_MIC_LEN);
314+ if (err)
315+ goto free_aead;
316+
317+ return tfm;
318+
319+free_aead:
320+ crypto_free_aead(tfm);
321+ return ERR_PTR(err);
322+}
323+
324+void ieee80211_aes_gcm_key_free(struct crypto_aead *tfm)
325+{
326+ crypto_free_aead(tfm);
327+}
328--- a/net/mac80211/aes_gcm.h
329+++ b/net/mac80211/aes_gcm.h
330@@ -6,38 +6,30 @@
331 #ifndef AES_GCM_H
332 #define AES_GCM_H
333
334-#include "aead_api.h"
335+#include <linux/crypto.h>
336
337-#define GCM_AAD_LEN 32
338-
339-static inline int ieee80211_aes_gcm_encrypt(struct crypto_aead *tfm,
340- u8 *j_0, u8 *aad, u8 *data,
341- size_t data_len, u8 *mic)
342+static inline void
343+ieee80211_aes_gcm_encrypt(struct crypto_aead *tfm, u8 *j_0, u8 *aad,
344+ u8 *data, size_t data_len, u8 *mic)
345 {
346- return aead_encrypt(tfm, j_0, aad + 2,
347- be16_to_cpup((__be16 *)aad),
348- data, data_len, mic);
349 }
350
351-static inline int ieee80211_aes_gcm_decrypt(struct crypto_aead *tfm,
352- u8 *j_0, u8 *aad, u8 *data,
353- size_t data_len, u8 *mic)
354+static inline int
355+ieee80211_aes_gcm_decrypt(struct crypto_aead *tfm, u8 *j_0, u8 *aad,
356+ u8 *data, size_t data_len, u8 *mic)
357 {
358- return aead_decrypt(tfm, j_0, aad + 2,
359- be16_to_cpup((__be16 *)aad),
360- data, data_len, mic);
361+ return -EOPNOTSUPP;
362 }
363
364 static inline struct crypto_aead *
365 ieee80211_aes_gcm_key_setup_encrypt(const u8 key[], size_t key_len)
366 {
367- return aead_key_setup_encrypt("gcm(aes)", key,
368- key_len, IEEE80211_GCMP_MIC_LEN);
369+ return NULL;
370 }
371
372-static inline void ieee80211_aes_gcm_key_free(struct crypto_aead *tfm)
373+static inline void
374+ieee80211_aes_gcm_key_free(struct crypto_aead *tfm)
375 {
376- return aead_key_free(tfm);
377 }
378
379 #endif /* AES_GCM_H */
380--- a/net/mac80211/wpa.c
381+++ b/net/mac80211/wpa.c
382@@ -312,7 +312,8 @@ ieee80211_crypto_tkip_decrypt(struct iee
383 }
384
385
386-static void ccmp_special_blocks(struct sk_buff *skb, u8 *pn, u8 *b_0, u8 *aad)
387+static void ccmp_special_blocks(struct sk_buff *skb, u8 *pn, u8 *b_0, u8 *aad,
388+ u16 data_len)
389 {
390 __le16 mask_fc;
391 int a4_included, mgmt;
392@@ -342,14 +343,8 @@ static void ccmp_special_blocks(struct s
393 else
394 qos_tid = 0;
395
396- /* In CCM, the initial vectors (IV) used for CTR mode encryption and CBC
397- * mode authentication are not allowed to collide, yet both are derived
398- * from this vector b_0. We only set L := 1 here to indicate that the
399- * data size can be represented in (L+1) bytes. The CCM layer will take
400- * care of storing the data length in the top (L+1) bytes and setting
401- * and clearing the other bits as is required to derive the two IVs.
402- */
403- b_0[0] = 0x1;
404+ /* First block, b_0 */
405+ b_0[0] = 0x59; /* flags: Adata: 1, M: 011, L: 001 */
406
407 /* Nonce: Nonce Flags | A2 | PN
408 * Nonce Flags: Priority (b0..b3) | Management (b4) | Reserved (b5..b7)
409@@ -357,6 +352,8 @@ static void ccmp_special_blocks(struct s
410 b_0[1] = qos_tid | (mgmt << 4);
411 memcpy(&b_0[2], hdr->addr2, ETH_ALEN);
412 memcpy(&b_0[8], pn, IEEE80211_CCMP_PN_LEN);
413+ /* l(m) */
414+ put_unaligned_be16(data_len, &b_0[14]);
415
416 /* AAD (extra authenticate-only data) / masked 802.11 header
417 * FC | A1 | A2 | A3 | SC | [A4] | [QC] */
418@@ -413,7 +410,7 @@ static int ccmp_encrypt_skb(struct ieee8
419 u8 *pos;
420 u8 pn[6];
421 u64 pn64;
422- u8 aad[CCM_AAD_LEN];
423+ u8 aad[2 * AES_BLOCK_SIZE];
424 u8 b_0[AES_BLOCK_SIZE];
425
426 if (info->control.hw_key &&
427@@ -468,9 +465,11 @@ static int ccmp_encrypt_skb(struct ieee8
428 return 0;
429
430 pos += IEEE80211_CCMP_HDR_LEN;
431- ccmp_special_blocks(skb, pn, b_0, aad);
432- return ieee80211_aes_ccm_encrypt(key->u.ccmp.tfm, b_0, aad, pos, len,
433- skb_put(skb, mic_len));
434+ ccmp_special_blocks(skb, pn, b_0, aad, len);
435+ ieee80211_aes_ccm_encrypt(key->u.ccmp.tfm, b_0, aad, pos, len,
436+ skb_put(skb, mic_len), mic_len);
437+
438+ return 0;
439 }
440
441
442@@ -546,13 +545,13 @@ ieee80211_crypto_ccmp_decrypt(struct iee
443 u8 aad[2 * AES_BLOCK_SIZE];
444 u8 b_0[AES_BLOCK_SIZE];
445 /* hardware didn't decrypt/verify MIC */
446- ccmp_special_blocks(skb, pn, b_0, aad);
447+ ccmp_special_blocks(skb, pn, b_0, aad, data_len);
448
449 if (ieee80211_aes_ccm_decrypt(
450 key->u.ccmp.tfm, b_0, aad,
451 skb->data + hdrlen + IEEE80211_CCMP_HDR_LEN,
452 data_len,
453- skb->data + skb->len - mic_len))
454+ skb->data + skb->len - mic_len, mic_len))
455 return RX_DROP_UNUSABLE;
456 }
457
458@@ -649,7 +648,7 @@ static int gcmp_encrypt_skb(struct ieee8
459 u8 *pos;
460 u8 pn[6];
461 u64 pn64;
462- u8 aad[GCM_AAD_LEN];
463+ u8 aad[2 * AES_BLOCK_SIZE];
464 u8 j_0[AES_BLOCK_SIZE];
465
466 if (info->control.hw_key &&
467@@ -706,8 +705,10 @@ static int gcmp_encrypt_skb(struct ieee8
468
469 pos += IEEE80211_GCMP_HDR_LEN;
470 gcmp_special_blocks(skb, pn, j_0, aad);
471- return ieee80211_aes_gcm_encrypt(key->u.gcmp.tfm, j_0, aad, pos, len,
472- skb_put(skb, IEEE80211_GCMP_MIC_LEN));
473+ ieee80211_aes_gcm_encrypt(key->u.gcmp.tfm, j_0, aad, pos, len,
474+ skb_put(skb, IEEE80211_GCMP_MIC_LEN));
475+
476+ return 0;
477 }
478
479 ieee80211_tx_result
480@@ -1139,9 +1140,9 @@ ieee80211_crypto_aes_gmac_encrypt(struct
481 struct ieee80211_key *key = tx->key;
482 struct ieee80211_mmie_16 *mmie;
483 struct ieee80211_hdr *hdr;
484- u8 aad[GMAC_AAD_LEN];
485+ u8 aad[20];
486 u64 pn64;
487- u8 nonce[GMAC_NONCE_LEN];
488+ u8 nonce[12];
489
490 if (WARN_ON(skb_queue_len(&tx->skbs) != 1))
491 return TX_DROP;
492@@ -1187,7 +1188,7 @@ ieee80211_crypto_aes_gmac_decrypt(struct
493 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
494 struct ieee80211_key *key = rx->key;
495 struct ieee80211_mmie_16 *mmie;
496- u8 aad[GMAC_AAD_LEN], *mic, ipn[6], nonce[GMAC_NONCE_LEN];
497+ u8 aad[20], *mic, ipn[6], nonce[12];
498 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
499
500 if (!ieee80211_is_mgmt(hdr->frame_control))
501--- /dev/null
502+++ b/net/mac80211/aes_ccm.c
503@@ -0,0 +1,144 @@
504+/*
505+ * Copyright 2003-2004, Instant802 Networks, Inc.
506+ * Copyright 2005-2006, Devicescape Software, Inc.
507+ *
508+ * Rewrite: Copyright (C) 2013 Linaro Ltd <ard.biesheuvel@linaro.org>
509+ *
510+ * This program is free software; you can redistribute it and/or modify
511+ * it under the terms of the GNU General Public License version 2 as
512+ * published by the Free Software Foundation.
513+ */
514+
515+#include <linux/kernel.h>
516+#include <linux/types.h>
517+#include <linux/err.h>
518+#include <crypto/aead.h>
519+#include <crypto/aes.h>
520+
521+#include <net/mac80211.h>
522+#include "key.h"
523+#include "aes_ccm.h"
524+
525+static void aes_ccm_prepare(struct crypto_cipher *tfm, u8 *b_0, u8 *aad, u8 *s_0,
526+ u8 *a, u8 *b)
527+{
528+ int i;
529+
530+ crypto_cipher_encrypt_one(tfm, b, b_0);
531+
532+ /* Extra Authenticate-only data (always two AES blocks) */
533+ for (i = 0; i < AES_BLOCK_SIZE; i++)
534+ aad[i] ^= b[i];
535+ crypto_cipher_encrypt_one(tfm, b, aad);
536+
537+ aad += AES_BLOCK_SIZE;
538+
539+ for (i = 0; i < AES_BLOCK_SIZE; i++)
540+ aad[i] ^= b[i];
541+ crypto_cipher_encrypt_one(tfm, a, aad);
542+
543+ /* Mask out bits from auth-only-b_0 */
544+ b_0[0] &= 0x07;
545+
546+ /* S_0 is used to encrypt T (= MIC) */
547+ b_0[14] = 0;
548+ b_0[15] = 0;
549+ crypto_cipher_encrypt_one(tfm, s_0, b_0);
550+}
551+
552+
553+void ieee80211_aes_ccm_encrypt(struct crypto_cipher *tfm, u8 *b_0, u8 *aad,
554+ u8 *data, size_t data_len, u8 *mic,
555+ size_t mic_len)
556+{
557+ int i, j, last_len, num_blocks;
558+ u8 b[AES_BLOCK_SIZE];
559+ u8 s_0[AES_BLOCK_SIZE];
560+ u8 e[AES_BLOCK_SIZE];
561+ u8 *pos, *cpos;
562+
563+ num_blocks = DIV_ROUND_UP(data_len, AES_BLOCK_SIZE);
564+ last_len = data_len % AES_BLOCK_SIZE;
565+ aes_ccm_prepare(tfm, b_0, aad, s_0, b, b);
566+
567+ /* Process payload blocks */
568+ pos = data;
569+ cpos = data;
570+ for (j = 1; j <= num_blocks; j++) {
571+ int blen = (j == num_blocks && last_len) ?
572+ last_len : AES_BLOCK_SIZE;
573+
574+ /* Authentication followed by encryption */
575+ for (i = 0; i < blen; i++)
576+ b[i] ^= pos[i];
577+ crypto_cipher_encrypt_one(tfm, b, b);
578+
579+ b_0[14] = (j >> 8) & 0xff;
580+ b_0[15] = j & 0xff;
581+ crypto_cipher_encrypt_one(tfm, e, b_0);
582+ for (i = 0; i < blen; i++)
583+ *cpos++ = *pos++ ^ e[i];
584+ }
585+
586+ for (i = 0; i < mic_len; i++)
587+ mic[i] = b[i] ^ s_0[i];
588+}
589+
590+int ieee80211_aes_ccm_decrypt(struct crypto_cipher *tfm, u8 *b_0, u8 *aad,
591+ u8 *data, size_t data_len, u8 *mic,
592+ size_t mic_len)
593+{
594+ int i, j, last_len, num_blocks;
595+ u8 *pos, *cpos;
596+ u8 a[AES_BLOCK_SIZE];
597+ u8 b[AES_BLOCK_SIZE];
598+ u8 s_0[AES_BLOCK_SIZE];
599+
600+ num_blocks = DIV_ROUND_UP(data_len, AES_BLOCK_SIZE);
601+ last_len = data_len % AES_BLOCK_SIZE;
602+ aes_ccm_prepare(tfm, b_0, aad, s_0, a, b);
603+
604+ /* Process payload blocks */
605+ cpos = data;
606+ pos = data;
607+ for (j = 1; j <= num_blocks; j++) {
608+ int blen = (j == num_blocks && last_len) ?
609+ last_len : AES_BLOCK_SIZE;
610+
611+ /* Decryption followed by authentication */
612+ b_0[14] = (j >> 8) & 0xff;
613+ b_0[15] = j & 0xff;
614+ crypto_cipher_encrypt_one(tfm, b, b_0);
615+ for (i = 0; i < blen; i++) {
616+ *pos = *cpos++ ^ b[i];
617+ a[i] ^= *pos++;
618+ }
619+ crypto_cipher_encrypt_one(tfm, a, a);
620+ }
621+
622+ for (i = 0; i < mic_len; i++) {
623+ if ((mic[i] ^ s_0[i]) != a[i])
624+ return -1;
625+ }
626+
627+ return 0;
628+}
629+
630+struct crypto_cipher *ieee80211_aes_key_setup_encrypt(const u8 key[],
631+ size_t key_len,
632+ size_t mic_len)
633+{
634+ struct crypto_cipher *tfm;
635+
636+ tfm = crypto_alloc_cipher("aes", 0, CRYPTO_ALG_ASYNC);
637+ if (!IS_ERR(tfm))
638+ crypto_cipher_setkey(tfm, key, key_len);
639+
640+ return tfm;
641+}
642+
643+
644+void ieee80211_aes_key_free(struct crypto_cipher *tfm)
645+{
646+ crypto_free_cipher(tfm);
647+}
648--- a/net/mac80211/Kconfig
649+++ b/net/mac80211/Kconfig
650@@ -6,8 +6,6 @@ config MAC80211
651 depends on CRYPTO
652 select BPAUTO_CRYPTO_LIB_ARC4
653 depends on CRYPTO_AES
654- depends on CRYPTO_CCM
655- depends on CRYPTO_GCM
656 depends on CRYPTO_CMAC
657 depends on CRC32
658 help
659--- a/net/mac80211/aes_gmac.h
660+++ b/net/mac80211/aes_gmac.h
661@@ -12,10 +12,22 @@
662 #define GMAC_MIC_LEN 16
663 #define GMAC_NONCE_LEN 12
664
665-struct crypto_aead *ieee80211_aes_gmac_key_setup(const u8 key[],
666- size_t key_len);
667-int ieee80211_aes_gmac(struct crypto_aead *tfm, const u8 *aad, u8 *nonce,
668- const u8 *data, size_t data_len, u8 *mic);
669-void ieee80211_aes_gmac_key_free(struct crypto_aead *tfm);
670+static inline struct crypto_aead *
671+ieee80211_aes_gmac_key_setup(const u8 key[], size_t key_len)
672+{
673+ return NULL;
674+}
675+
676+static inline int
677+ieee80211_aes_gmac(struct crypto_aead *tfm, const u8 *aad, u8 *nonce,
678+ const u8 *data, size_t data_len, u8 *mic)
679+{
680+ return -EOPNOTSUPP;
681+}
682+
683+static inline void
684+ieee80211_aes_gmac_key_free(struct crypto_aead *tfm)
685+{
686+}
687
688 #endif /* AES_GMAC_H */
689--- a/net/mac80211/key.h
690+++ b/net/mac80211/key.h
691@@ -89,7 +89,7 @@ struct ieee80211_key {
692 * Management frames.
693 */
694 u8 rx_pn[IEEE80211_NUM_TIDS + 1][IEEE80211_CCMP_PN_LEN];
695- struct crypto_aead *tfm;
696+ struct crypto_cipher *tfm;
697 u32 replays; /* dot11RSNAStatsCCMPReplays */
698 } ccmp;
699 struct {