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);
48 - aead_req = kzalloc(reqsize + CCM_AAD_LEN, GFP_ATOMIC);
51 + crypto_cipher_encrypt_one(tfm, b, b_0);
53 - __aad = (u8 *)aead_req + reqsize;
54 - memcpy(__aad, aad, CCM_AAD_LEN);
55 + /* Extra Authenticate-only data (always two AES blocks) */
56 + for (i = 0; i < AES_BLOCK_SIZE; i++)
58 + crypto_cipher_encrypt_one(tfm, b, aad);
60 - sg_init_table(sg, 3);
61 - sg_set_buf(&sg[0], &__aad[2], be16_to_cpup((__be16 *)__aad));
62 - sg_set_buf(&sg[1], data, data_len);
63 - sg_set_buf(&sg[2], mic, mic_len);
64 + aad += AES_BLOCK_SIZE;
66 - aead_request_set_tfm(aead_req, tfm);
67 - aead_request_set_crypt(aead_req, sg, sg, data_len, b_0);
68 - aead_request_set_ad(aead_req, sg[0].length);
69 + for (i = 0; i < AES_BLOCK_SIZE; i++)
71 + crypto_cipher_encrypt_one(tfm, a, aad);
73 - crypto_aead_encrypt(aead_req);
75 + /* Mask out bits from auth-only-b_0 */
79 + /* S_0 is used to encrypt T (= MIC) */
82 + crypto_cipher_encrypt_one(tfm, s_0, b_0);
85 -int ieee80211_aes_ccm_decrypt(struct crypto_aead *tfm, u8 *b_0, u8 *aad,
86 - u8 *data, size_t data_len, u8 *mic,
89 +void ieee80211_aes_ccm_encrypt(struct crypto_cipher *tfm, u8 *b_0, u8 *aad,
90 + u8 *data, size_t data_len, u8 *mic,
93 - struct scatterlist sg[3];
94 - struct aead_request *aead_req;
95 - int reqsize = sizeof(*aead_req) + crypto_aead_reqsize(tfm);
98 + int i, j, last_len, num_blocks;
99 + u8 b[AES_BLOCK_SIZE];
100 + u8 s_0[AES_BLOCK_SIZE];
101 + u8 e[AES_BLOCK_SIZE];
106 + num_blocks = DIV_ROUND_UP(data_len, AES_BLOCK_SIZE);
107 + last_len = data_len % AES_BLOCK_SIZE;
108 + aes_ccm_prepare(tfm, b_0, aad, s_0, b, b);
110 - aead_req = kzalloc(reqsize + CCM_AAD_LEN, GFP_ATOMIC);
113 + /* Process payload blocks */
116 + for (j = 1; j <= num_blocks; j++) {
117 + int blen = (j == num_blocks && last_len) ?
118 + last_len : AES_BLOCK_SIZE;
120 - __aad = (u8 *)aead_req + reqsize;
121 - memcpy(__aad, aad, CCM_AAD_LEN);
122 + /* Authentication followed by encryption */
123 + for (i = 0; i < blen; i++)
125 + crypto_cipher_encrypt_one(tfm, b, b);
127 - sg_init_table(sg, 3);
128 - sg_set_buf(&sg[0], &__aad[2], be16_to_cpup((__be16 *)__aad));
129 - sg_set_buf(&sg[1], data, data_len);
130 - sg_set_buf(&sg[2], mic, mic_len);
131 + b_0[14] = (j >> 8) & 0xff;
132 + b_0[15] = j & 0xff;
133 + crypto_cipher_encrypt_one(tfm, e, b_0);
134 + for (i = 0; i < blen; i++)
135 + *cpos++ = *pos++ ^ e[i];
138 - aead_request_set_tfm(aead_req, tfm);
139 - aead_request_set_crypt(aead_req, sg, sg, data_len + mic_len, b_0);
140 - aead_request_set_ad(aead_req, sg[0].length);
141 + for (i = 0; i < mic_len; i++)
142 + mic[i] = b[i] ^ s_0[i];
145 - err = crypto_aead_decrypt(aead_req);
147 +int ieee80211_aes_ccm_decrypt(struct crypto_cipher *tfm, u8 *b_0, u8 *aad,
148 + u8 *data, size_t data_len, u8 *mic,
151 + int i, j, last_len, num_blocks;
153 + u8 a[AES_BLOCK_SIZE];
154 + u8 b[AES_BLOCK_SIZE];
155 + u8 s_0[AES_BLOCK_SIZE];
158 + num_blocks = DIV_ROUND_UP(data_len, AES_BLOCK_SIZE);
159 + last_len = data_len % AES_BLOCK_SIZE;
160 + aes_ccm_prepare(tfm, b_0, aad, s_0, a, b);
162 + /* Process payload blocks */
165 + for (j = 1; j <= num_blocks; j++) {
166 + int blen = (j == num_blocks && last_len) ?
167 + last_len : AES_BLOCK_SIZE;
169 + /* Decryption followed by authentication */
170 + b_0[14] = (j >> 8) & 0xff;
171 + b_0[15] = j & 0xff;
172 + crypto_cipher_encrypt_one(tfm, b, b_0);
173 + for (i = 0; i < blen; i++) {
174 + *pos = *cpos++ ^ b[i];
177 + crypto_cipher_encrypt_one(tfm, a, a);
180 + for (i = 0; i < mic_len; i++) {
181 + if ((mic[i] ^ s_0[i]) != a[i])
188 -struct crypto_aead *ieee80211_aes_key_setup_encrypt(const u8 key[],
191 +struct crypto_cipher *ieee80211_aes_key_setup_encrypt(const u8 key[],
195 - struct crypto_aead *tfm;
198 - tfm = crypto_alloc_aead("ccm(aes)", 0, CRYPTO_ALG_ASYNC);
201 + struct crypto_cipher *tfm;
203 - err = crypto_aead_setkey(tfm, key, key_len);
206 - err = crypto_aead_setauthsize(tfm, mic_len);
209 + tfm = crypto_alloc_cipher("aes", 0, CRYPTO_ALG_ASYNC);
211 + crypto_cipher_setkey(tfm, key, key_len);
216 - crypto_free_aead(tfm);
217 - return ERR_PTR(err);
220 -void ieee80211_aes_key_free(struct crypto_aead *tfm)
222 +void ieee80211_aes_key_free(struct crypto_cipher *tfm)
224 - crypto_free_aead(tfm);
225 + crypto_free_cipher(tfm);
227 --- a/net/mac80211/aes_gmac.h
228 +++ b/net/mac80211/aes_gmac.h
230 #define GMAC_MIC_LEN 16
231 #define GMAC_NONCE_LEN 12
233 -struct crypto_aead *ieee80211_aes_gmac_key_setup(const u8 key[],
235 -int ieee80211_aes_gmac(struct crypto_aead *tfm, const u8 *aad, u8 *nonce,
236 - const u8 *data, size_t data_len, u8 *mic);
237 -void ieee80211_aes_gmac_key_free(struct crypto_aead *tfm);
238 +static inline struct crypto_aead *
239 +ieee80211_aes_gmac_key_setup(const u8 key[], size_t key_len)
245 +ieee80211_aes_gmac(struct crypto_aead *tfm, const u8 *aad, u8 *nonce,
246 + const u8 *data, size_t data_len, u8 *mic)
248 + return -EOPNOTSUPP;
252 +ieee80211_aes_gmac_key_free(struct crypto_aead *tfm)
256 #endif /* AES_GMAC_H */
257 --- a/net/mac80211/key.h
258 +++ b/net/mac80211/key.h
259 @@ -88,7 +88,7 @@ struct ieee80211_key {
262 u8 rx_pn[IEEE80211_NUM_TIDS + 1][IEEE80211_CCMP_PN_LEN];
263 - struct crypto_aead *tfm;
264 + struct crypto_cipher *tfm;
265 u32 replays; /* dot11RSNAStatsCCMPReplays */
268 --- a/net/mac80211/wpa.c
269 +++ b/net/mac80211/wpa.c
270 @@ -306,7 +306,8 @@ ieee80211_crypto_tkip_decrypt(struct iee
274 -static void ccmp_special_blocks(struct sk_buff *skb, u8 *pn, u8 *b_0, u8 *aad)
275 +static void ccmp_special_blocks(struct sk_buff *skb, u8 *pn, u8 *b_0, u8 *aad,
279 int a4_included, mgmt;
280 @@ -336,14 +337,8 @@ static void ccmp_special_blocks(struct s
284 - /* In CCM, the initial vectors (IV) used for CTR mode encryption and CBC
285 - * mode authentication are not allowed to collide, yet both are derived
286 - * from this vector b_0. We only set L := 1 here to indicate that the
287 - * data size can be represented in (L+1) bytes. The CCM layer will take
288 - * care of storing the data length in the top (L+1) bytes and setting
289 - * and clearing the other bits as is required to derive the two IVs.
292 + /* First block, b_0 */
293 + b_0[0] = 0x59; /* flags: Adata: 1, M: 011, L: 001 */
295 /* Nonce: Nonce Flags | A2 | PN
296 * Nonce Flags: Priority (b0..b3) | Management (b4) | Reserved (b5..b7)
297 @@ -351,6 +346,8 @@ static void ccmp_special_blocks(struct s
298 b_0[1] = qos_tid | (mgmt << 4);
299 memcpy(&b_0[2], hdr->addr2, ETH_ALEN);
300 memcpy(&b_0[8], pn, IEEE80211_CCMP_PN_LEN);
302 + put_unaligned_be16(data_len, &b_0[14]);
304 /* AAD (extra authenticate-only data) / masked 802.11 header
305 * FC | A1 | A2 | A3 | SC | [A4] | [QC] */
306 @@ -407,7 +404,7 @@ static int ccmp_encrypt_skb(struct ieee8
310 - u8 aad[CCM_AAD_LEN];
311 + u8 aad[2 * AES_BLOCK_SIZE];
312 u8 b_0[AES_BLOCK_SIZE];
314 if (info->control.hw_key &&
315 @@ -462,9 +459,11 @@ static int ccmp_encrypt_skb(struct ieee8
318 pos += IEEE80211_CCMP_HDR_LEN;
319 - ccmp_special_blocks(skb, pn, b_0, aad);
320 - return ieee80211_aes_ccm_encrypt(key->u.ccmp.tfm, b_0, aad, pos, len,
321 - skb_put(skb, mic_len), mic_len);
322 + ccmp_special_blocks(skb, pn, b_0, aad, len);
323 + ieee80211_aes_ccm_encrypt(key->u.ccmp.tfm, b_0, aad, pos, len,
324 + skb_put(skb, mic_len), mic_len);
330 @@ -537,7 +536,7 @@ ieee80211_crypto_ccmp_decrypt(struct iee
331 u8 aad[2 * AES_BLOCK_SIZE];
332 u8 b_0[AES_BLOCK_SIZE];
333 /* hardware didn't decrypt/verify MIC */
334 - ccmp_special_blocks(skb, pn, b_0, aad);
335 + ccmp_special_blocks(skb, pn, b_0, aad, data_len);
337 if (ieee80211_aes_ccm_decrypt(
338 key->u.ccmp.tfm, b_0, aad,
339 @@ -639,7 +638,7 @@ static int gcmp_encrypt_skb(struct ieee8
343 - u8 aad[GCM_AAD_LEN];
344 + u8 aad[2 * AES_BLOCK_SIZE];
345 u8 j_0[AES_BLOCK_SIZE];
347 if (info->control.hw_key &&
348 @@ -696,8 +695,10 @@ static int gcmp_encrypt_skb(struct ieee8
350 pos += IEEE80211_GCMP_HDR_LEN;
351 gcmp_special_blocks(skb, pn, j_0, aad);
352 - return ieee80211_aes_gcm_encrypt(key->u.gcmp.tfm, j_0, aad, pos, len,
353 - skb_put(skb, IEEE80211_GCMP_MIC_LEN));
354 + ieee80211_aes_gcm_encrypt(key->u.gcmp.tfm, j_0, aad, pos, len,
355 + skb_put(skb, IEEE80211_GCMP_MIC_LEN));
361 @@ -1121,9 +1122,9 @@ ieee80211_crypto_aes_gmac_encrypt(struct
362 struct ieee80211_key *key = tx->key;
363 struct ieee80211_mmie_16 *mmie;
364 struct ieee80211_hdr *hdr;
365 - u8 aad[GMAC_AAD_LEN];
368 - u8 nonce[GMAC_NONCE_LEN];
371 if (WARN_ON(skb_queue_len(&tx->skbs) != 1))
373 @@ -1169,7 +1170,7 @@ ieee80211_crypto_aes_gmac_decrypt(struct
374 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
375 struct ieee80211_key *key = rx->key;
376 struct ieee80211_mmie_16 *mmie;
377 - u8 aad[GMAC_AAD_LEN], mic[GMAC_MIC_LEN], ipn[6], nonce[GMAC_NONCE_LEN];
378 + u8 aad[20], mic[16], ipn[6], nonce[12];
379 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
381 if (!ieee80211_is_mgmt(hdr->frame_control))
382 --- a/net/mac80211/aes_ccm.h
383 +++ b/net/mac80211/aes_ccm.h
386 #include <linux/crypto.h>
388 -#define CCM_AAD_LEN 32
390 -struct crypto_aead *ieee80211_aes_key_setup_encrypt(const u8 key[],
393 -int ieee80211_aes_ccm_encrypt(struct crypto_aead *tfm, u8 *b_0, u8 *aad,
394 - u8 *data, size_t data_len, u8 *mic,
396 -int ieee80211_aes_ccm_decrypt(struct crypto_aead *tfm, u8 *b_0, u8 *aad,
397 +struct crypto_cipher *ieee80211_aes_key_setup_encrypt(const u8 key[],
400 +void ieee80211_aes_ccm_encrypt(struct crypto_cipher *tfm, u8 *b_0, u8 *aad,
401 + u8 *data, size_t data_len, u8 *mic,
403 +int ieee80211_aes_ccm_decrypt(struct crypto_cipher *tfm, u8 *b_0, u8 *aad,
404 u8 *data, size_t data_len, u8 *mic,
406 -void ieee80211_aes_key_free(struct crypto_aead *tfm);
407 +void ieee80211_aes_key_free(struct crypto_cipher *tfm);
409 #endif /* AES_CCM_H */
410 --- a/net/mac80211/aes_gcm.h
411 +++ b/net/mac80211/aes_gcm.h
414 #include <linux/crypto.h>
416 -#define GCM_AAD_LEN 32
418 +ieee80211_aes_gcm_encrypt(struct crypto_aead *tfm, u8 *j_0, u8 *aad,
419 + u8 *data, size_t data_len, u8 *mic)
423 -int ieee80211_aes_gcm_encrypt(struct crypto_aead *tfm, u8 *j_0, u8 *aad,
424 - u8 *data, size_t data_len, u8 *mic);
425 -int ieee80211_aes_gcm_decrypt(struct crypto_aead *tfm, u8 *j_0, u8 *aad,
426 - u8 *data, size_t data_len, u8 *mic);
427 -struct crypto_aead *ieee80211_aes_gcm_key_setup_encrypt(const u8 key[],
429 -void ieee80211_aes_gcm_key_free(struct crypto_aead *tfm);
431 +ieee80211_aes_gcm_decrypt(struct crypto_aead *tfm, u8 *j_0, u8 *aad,
432 + u8 *data, size_t data_len, u8 *mic)
434 + return -EOPNOTSUPP;
437 +static inline struct crypto_aead *
438 +ieee80211_aes_gcm_key_setup_encrypt(const u8 key[], size_t key_len)
444 +ieee80211_aes_gcm_key_free(struct crypto_aead *tfm)
448 #endif /* AES_GCM_H */