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