1 --- a/net/mac80211/Kconfig
2 +++ b/net/mac80211/Kconfig
3 @@ -5,8 +5,6 @@ config MAC80211
7 - select BPAUTO_CRYPTO_CCM
8 - depends on CRYPTO_GCM
12 --- a/net/mac80211/Makefile
13 +++ b/net/mac80211/Makefile
14 @@ -16,9 +16,7 @@ mac80211-y := \
24 --- a/net/mac80211/aes_ccm.c
25 +++ b/net/mac80211/aes_ccm.c
27 #include <linux/types.h>
28 #include <linux/err.h>
29 #include <crypto/aead.h>
30 +#include <crypto/aes.h>
32 #include <net/mac80211.h>
36 -int ieee80211_aes_ccm_encrypt(struct crypto_aead *tfm, u8 *b_0, u8 *aad,
37 - u8 *data, size_t data_len, u8 *mic,
39 +static void aes_ccm_prepare(struct crypto_cipher *tfm, u8 *b_0, u8 *aad, u8 *s_0,
42 - struct scatterlist sg[3];
43 - struct aead_request *aead_req;
44 - int reqsize = sizeof(*aead_req) + crypto_aead_reqsize(tfm);
47 - aead_req = kzalloc(reqsize + CCM_AAD_LEN, GFP_ATOMIC);
51 - __aad = (u8 *)aead_req + reqsize;
52 - memcpy(__aad, aad, CCM_AAD_LEN);
54 - sg_init_table(sg, 3);
55 - sg_set_buf(&sg[0], &__aad[2], be16_to_cpup((__be16 *)__aad));
56 - sg_set_buf(&sg[1], data, data_len);
57 - sg_set_buf(&sg[2], mic, mic_len);
59 - aead_request_set_tfm(aead_req, tfm);
60 - aead_request_set_crypt(aead_req, sg, sg, data_len, b_0);
61 - aead_request_set_ad(aead_req, sg[0].length);
64 - crypto_aead_encrypt(aead_req);
66 + crypto_cipher_encrypt_one(tfm, b, b_0);
69 + /* Extra Authenticate-only data (always two AES blocks) */
70 + for (i = 0; i < AES_BLOCK_SIZE; i++)
72 + crypto_cipher_encrypt_one(tfm, b, aad);
74 + aad += AES_BLOCK_SIZE;
76 + for (i = 0; i < AES_BLOCK_SIZE; i++)
78 + crypto_cipher_encrypt_one(tfm, a, aad);
80 + /* Mask out bits from auth-only-b_0 */
83 + /* S_0 is used to encrypt T (= MIC) */
86 + crypto_cipher_encrypt_one(tfm, s_0, b_0);
90 +void ieee80211_aes_ccm_encrypt(struct crypto_cipher *tfm, u8 *b_0, u8 *aad,
91 + u8 *data, size_t data_len, u8 *mic,
94 + int i, j, last_len, num_blocks;
95 + u8 b[AES_BLOCK_SIZE];
96 + u8 s_0[AES_BLOCK_SIZE];
97 + u8 e[AES_BLOCK_SIZE];
100 + num_blocks = DIV_ROUND_UP(data_len, AES_BLOCK_SIZE);
101 + last_len = data_len % AES_BLOCK_SIZE;
102 + aes_ccm_prepare(tfm, b_0, aad, s_0, b, b);
104 + /* Process payload blocks */
107 + for (j = 1; j <= num_blocks; j++) {
108 + int blen = (j == num_blocks && last_len) ?
109 + last_len : AES_BLOCK_SIZE;
111 + /* Authentication followed by encryption */
112 + for (i = 0; i < blen; i++)
114 + crypto_cipher_encrypt_one(tfm, b, b);
116 + b_0[14] = (j >> 8) & 0xff;
117 + b_0[15] = j & 0xff;
118 + crypto_cipher_encrypt_one(tfm, e, b_0);
119 + for (i = 0; i < blen; i++)
120 + *cpos++ = *pos++ ^ e[i];
123 + for (i = 0; i < mic_len; i++)
124 + mic[i] = b[i] ^ s_0[i];
127 -int ieee80211_aes_ccm_decrypt(struct crypto_aead *tfm, u8 *b_0, u8 *aad,
128 +int ieee80211_aes_ccm_decrypt(struct crypto_cipher *tfm, u8 *b_0, u8 *aad,
129 u8 *data, size_t data_len, u8 *mic,
132 - struct scatterlist sg[3];
133 - struct aead_request *aead_req;
134 - int reqsize = sizeof(*aead_req) + crypto_aead_reqsize(tfm);
141 - aead_req = kzalloc(reqsize + CCM_AAD_LEN, GFP_ATOMIC);
145 - __aad = (u8 *)aead_req + reqsize;
146 - memcpy(__aad, aad, CCM_AAD_LEN);
148 - sg_init_table(sg, 3);
149 - sg_set_buf(&sg[0], &__aad[2], be16_to_cpup((__be16 *)__aad));
150 - sg_set_buf(&sg[1], data, data_len);
151 - sg_set_buf(&sg[2], mic, mic_len);
153 - aead_request_set_tfm(aead_req, tfm);
154 - aead_request_set_crypt(aead_req, sg, sg, data_len + mic_len, b_0);
155 - aead_request_set_ad(aead_req, sg[0].length);
156 + int i, j, last_len, num_blocks;
158 + u8 a[AES_BLOCK_SIZE];
159 + u8 b[AES_BLOCK_SIZE];
160 + u8 s_0[AES_BLOCK_SIZE];
162 + num_blocks = DIV_ROUND_UP(data_len, AES_BLOCK_SIZE);
163 + last_len = data_len % AES_BLOCK_SIZE;
164 + aes_ccm_prepare(tfm, b_0, aad, s_0, a, b);
166 + /* Process payload blocks */
169 + for (j = 1; j <= num_blocks; j++) {
170 + int blen = (j == num_blocks && last_len) ?
171 + last_len : AES_BLOCK_SIZE;
173 + /* Decryption followed by authentication */
174 + b_0[14] = (j >> 8) & 0xff;
175 + b_0[15] = j & 0xff;
176 + crypto_cipher_encrypt_one(tfm, b, b_0);
177 + for (i = 0; i < blen; i++) {
178 + *pos = *cpos++ ^ b[i];
181 + crypto_cipher_encrypt_one(tfm, a, a);
184 + for (i = 0; i < mic_len; i++) {
185 + if ((mic[i] ^ s_0[i]) != a[i])
189 - err = crypto_aead_decrypt(aead_req);
196 -struct crypto_aead *ieee80211_aes_key_setup_encrypt(const u8 key[],
199 +struct crypto_cipher *ieee80211_aes_key_setup_encrypt(const u8 key[],
203 - struct crypto_aead *tfm;
205 + struct crypto_cipher *tfm;
207 - tfm = crypto_alloc_aead("ccm(aes)", 0, CRYPTO_ALG_ASYNC);
211 - err = crypto_aead_setkey(tfm, key, key_len);
214 - err = crypto_aead_setauthsize(tfm, mic_len);
217 + tfm = crypto_alloc_cipher("aes", 0, CRYPTO_ALG_ASYNC);
219 + crypto_cipher_setkey(tfm, key, key_len);
224 - crypto_free_aead(tfm);
225 - return ERR_PTR(err);
228 -void ieee80211_aes_key_free(struct crypto_aead *tfm)
230 +void ieee80211_aes_key_free(struct crypto_cipher *tfm)
232 - crypto_free_aead(tfm);
233 + crypto_free_cipher(tfm);
235 --- a/net/mac80211/aes_gmac.h
236 +++ b/net/mac80211/aes_gmac.h
238 #define GMAC_MIC_LEN 16
239 #define GMAC_NONCE_LEN 12
241 -struct crypto_aead *ieee80211_aes_gmac_key_setup(const u8 key[],
243 -int ieee80211_aes_gmac(struct crypto_aead *tfm, const u8 *aad, u8 *nonce,
244 - const u8 *data, size_t data_len, u8 *mic);
245 -void ieee80211_aes_gmac_key_free(struct crypto_aead *tfm);
246 +static inline struct crypto_aead *
247 +ieee80211_aes_gmac_key_setup(const u8 key[], size_t key_len)
253 +ieee80211_aes_gmac(struct crypto_aead *tfm, const u8 *aad, u8 *nonce,
254 + const u8 *data, size_t data_len, u8 *mic)
256 + return -EOPNOTSUPP;
260 +ieee80211_aes_gmac_key_free(struct crypto_aead *tfm)
264 #endif /* AES_GMAC_H */
265 --- a/net/mac80211/key.h
266 +++ b/net/mac80211/key.h
267 @@ -88,7 +88,7 @@ struct ieee80211_key {
270 u8 rx_pn[IEEE80211_NUM_TIDS + 1][IEEE80211_CCMP_PN_LEN];
271 - struct crypto_aead *tfm;
272 + struct crypto_cipher *tfm;
273 u32 replays; /* dot11RSNAStatsCCMPReplays */
276 --- a/net/mac80211/wpa.c
277 +++ b/net/mac80211/wpa.c
278 @@ -306,7 +306,8 @@ ieee80211_crypto_tkip_decrypt(struct iee
282 -static void ccmp_special_blocks(struct sk_buff *skb, u8 *pn, u8 *b_0, u8 *aad)
283 +static void ccmp_special_blocks(struct sk_buff *skb, u8 *pn, u8 *b_0, u8 *aad,
287 int a4_included, mgmt;
288 @@ -336,14 +337,8 @@ static void ccmp_special_blocks(struct s
292 - /* In CCM, the initial vectors (IV) used for CTR mode encryption and CBC
293 - * mode authentication are not allowed to collide, yet both are derived
294 - * from this vector b_0. We only set L := 1 here to indicate that the
295 - * data size can be represented in (L+1) bytes. The CCM layer will take
296 - * care of storing the data length in the top (L+1) bytes and setting
297 - * and clearing the other bits as is required to derive the two IVs.
300 + /* First block, b_0 */
301 + b_0[0] = 0x59; /* flags: Adata: 1, M: 011, L: 001 */
303 /* Nonce: Nonce Flags | A2 | PN
304 * Nonce Flags: Priority (b0..b3) | Management (b4) | Reserved (b5..b7)
305 @@ -351,6 +346,8 @@ static void ccmp_special_blocks(struct s
306 b_0[1] = qos_tid | (mgmt << 4);
307 memcpy(&b_0[2], hdr->addr2, ETH_ALEN);
308 memcpy(&b_0[8], pn, IEEE80211_CCMP_PN_LEN);
310 + put_unaligned_be16(data_len, &b_0[14]);
312 /* AAD (extra authenticate-only data) / masked 802.11 header
313 * FC | A1 | A2 | A3 | SC | [A4] | [QC] */
314 @@ -407,7 +404,7 @@ static int ccmp_encrypt_skb(struct ieee8
318 - u8 aad[CCM_AAD_LEN];
319 + u8 aad[2 * AES_BLOCK_SIZE];
320 u8 b_0[AES_BLOCK_SIZE];
322 if (info->control.hw_key &&
323 @@ -462,9 +459,11 @@ static int ccmp_encrypt_skb(struct ieee8
326 pos += IEEE80211_CCMP_HDR_LEN;
327 - ccmp_special_blocks(skb, pn, b_0, aad);
328 - return ieee80211_aes_ccm_encrypt(key->u.ccmp.tfm, b_0, aad, pos, len,
329 - skb_put(skb, mic_len), mic_len);
330 + ccmp_special_blocks(skb, pn, b_0, aad, len);
331 + ieee80211_aes_ccm_encrypt(key->u.ccmp.tfm, b_0, aad, pos, len,
332 + skb_put(skb, mic_len), mic_len);
338 @@ -537,7 +536,7 @@ ieee80211_crypto_ccmp_decrypt(struct iee
339 u8 aad[2 * AES_BLOCK_SIZE];
340 u8 b_0[AES_BLOCK_SIZE];
341 /* hardware didn't decrypt/verify MIC */
342 - ccmp_special_blocks(skb, pn, b_0, aad);
343 + ccmp_special_blocks(skb, pn, b_0, aad, data_len);
345 if (ieee80211_aes_ccm_decrypt(
346 key->u.ccmp.tfm, b_0, aad,
347 @@ -639,7 +638,7 @@ static int gcmp_encrypt_skb(struct ieee8
351 - u8 aad[GCM_AAD_LEN];
352 + u8 aad[2 * AES_BLOCK_SIZE];
353 u8 j_0[AES_BLOCK_SIZE];
355 if (info->control.hw_key &&
356 @@ -696,8 +695,10 @@ static int gcmp_encrypt_skb(struct ieee8
358 pos += IEEE80211_GCMP_HDR_LEN;
359 gcmp_special_blocks(skb, pn, j_0, aad);
360 - return ieee80211_aes_gcm_encrypt(key->u.gcmp.tfm, j_0, aad, pos, len,
361 - skb_put(skb, IEEE80211_GCMP_MIC_LEN));
362 + ieee80211_aes_gcm_encrypt(key->u.gcmp.tfm, j_0, aad, pos, len,
363 + skb_put(skb, IEEE80211_GCMP_MIC_LEN));
369 @@ -1121,9 +1122,9 @@ ieee80211_crypto_aes_gmac_encrypt(struct
370 struct ieee80211_key *key = tx->key;
371 struct ieee80211_mmie_16 *mmie;
372 struct ieee80211_hdr *hdr;
373 - u8 aad[GMAC_AAD_LEN];
376 - u8 nonce[GMAC_NONCE_LEN];
379 if (WARN_ON(skb_queue_len(&tx->skbs) != 1))
381 @@ -1169,7 +1170,7 @@ ieee80211_crypto_aes_gmac_decrypt(struct
382 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
383 struct ieee80211_key *key = rx->key;
384 struct ieee80211_mmie_16 *mmie;
385 - u8 aad[GMAC_AAD_LEN], mic[GMAC_MIC_LEN], ipn[6], nonce[GMAC_NONCE_LEN];
386 + u8 aad[20], mic[16], ipn[6], nonce[12];
387 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
389 if (!ieee80211_is_mgmt(hdr->frame_control))
390 --- a/net/mac80211/aes_ccm.h
391 +++ b/net/mac80211/aes_ccm.h
394 #include <linux/crypto.h>
396 -#define CCM_AAD_LEN 32
398 -struct crypto_aead *ieee80211_aes_key_setup_encrypt(const u8 key[],
401 -int ieee80211_aes_ccm_encrypt(struct crypto_aead *tfm, u8 *b_0, u8 *aad,
402 - u8 *data, size_t data_len, u8 *mic,
404 -int ieee80211_aes_ccm_decrypt(struct crypto_aead *tfm, u8 *b_0, u8 *aad,
405 +struct crypto_cipher *ieee80211_aes_key_setup_encrypt(const u8 key[],
408 +void ieee80211_aes_ccm_encrypt(struct crypto_cipher *tfm, u8 *b_0, u8 *aad,
409 + u8 *data, size_t data_len, u8 *mic,
411 +int ieee80211_aes_ccm_decrypt(struct crypto_cipher *tfm, u8 *b_0, u8 *aad,
412 u8 *data, size_t data_len, u8 *mic,
414 -void ieee80211_aes_key_free(struct crypto_aead *tfm);
415 +void ieee80211_aes_key_free(struct crypto_cipher *tfm);
417 #endif /* AES_CCM_H */
418 --- a/net/mac80211/aes_gcm.h
419 +++ b/net/mac80211/aes_gcm.h
422 #include <linux/crypto.h>
424 -#define GCM_AAD_LEN 32
426 +ieee80211_aes_gcm_encrypt(struct crypto_aead *tfm, u8 *j_0, u8 *aad,
427 + u8 *data, size_t data_len, u8 *mic)
431 -int ieee80211_aes_gcm_encrypt(struct crypto_aead *tfm, u8 *j_0, u8 *aad,
432 - u8 *data, size_t data_len, u8 *mic);
433 -int ieee80211_aes_gcm_decrypt(struct crypto_aead *tfm, u8 *j_0, u8 *aad,
434 - u8 *data, size_t data_len, u8 *mic);
435 -struct crypto_aead *ieee80211_aes_gcm_key_setup_encrypt(const u8 key[],
437 -void ieee80211_aes_gcm_key_free(struct crypto_aead *tfm);
439 +ieee80211_aes_gcm_decrypt(struct crypto_aead *tfm, u8 *j_0, u8 *aad,
440 + u8 *data, size_t data_len, u8 *mic)
442 + return -EOPNOTSUPP;
445 +static inline struct crypto_aead *
446 +ieee80211_aes_gcm_key_setup_encrypt(const u8 key[], size_t key_len)
452 +ieee80211_aes_gcm_key_free(struct crypto_aead *tfm)
456 #endif /* AES_GCM_H */