1 --- a/net/mac80211/Makefile
2 +++ b/net/mac80211/Makefile
3 @@ -15,9 +15,7 @@ mac80211-y := \
13 --- a/net/mac80211/aes_gcm.h
14 +++ b/net/mac80211/aes_gcm.h
17 #include <linux/crypto.h>
19 -void ieee80211_aes_gcm_encrypt(struct crypto_aead *tfm, u8 *j_0, u8 *aad,
20 - u8 *data, size_t data_len, u8 *mic);
21 -int ieee80211_aes_gcm_decrypt(struct crypto_aead *tfm, u8 *j_0, u8 *aad,
22 - u8 *data, size_t data_len, u8 *mic);
23 -struct crypto_aead *ieee80211_aes_gcm_key_setup_encrypt(const u8 key[],
25 -void ieee80211_aes_gcm_key_free(struct crypto_aead *tfm);
27 +ieee80211_aes_gcm_encrypt(struct crypto_aead *tfm, u8 *j_0, u8 *aad,
28 + u8 *data, size_t data_len, u8 *mic)
33 +ieee80211_aes_gcm_decrypt(struct crypto_aead *tfm, u8 *j_0, u8 *aad,
34 + u8 *data, size_t data_len, u8 *mic)
39 +static inline struct crypto_aead *
40 +ieee80211_aes_gcm_key_setup_encrypt(const u8 key[], size_t key_len)
46 +ieee80211_aes_gcm_key_free(struct crypto_aead *tfm)
50 #endif /* AES_GCM_H */
51 --- a/net/mac80211/aes_gmac.h
52 +++ b/net/mac80211/aes_gmac.h
55 #include <linux/crypto.h>
57 -struct crypto_aead *ieee80211_aes_gmac_key_setup(const u8 key[],
59 -int ieee80211_aes_gmac(struct crypto_aead *tfm, const u8 *aad, u8 *nonce,
60 - const u8 *data, size_t data_len, u8 *mic);
61 -void ieee80211_aes_gmac_key_free(struct crypto_aead *tfm);
62 +static inline struct crypto_aead *
63 +ieee80211_aes_gmac_key_setup(const u8 key[], size_t key_len)
69 +ieee80211_aes_gmac(struct crypto_aead *tfm, const u8 *aad, u8 *nonce,
70 + const u8 *data, size_t data_len, u8 *mic)
76 +ieee80211_aes_gmac_key_free(struct crypto_aead *tfm)
80 #endif /* AES_GMAC_H */
81 --- a/net/mac80211/aes_ccm.c
82 +++ b/net/mac80211/aes_ccm.c
87 -void ieee80211_aes_ccm_encrypt(struct crypto_aead *tfm, u8 *b_0, u8 *aad,
88 +static void aes_ccm_prepare(struct crypto_cipher *tfm, u8 *b_0, u8 *aad, u8 *s_0,
93 + crypto_cipher_encrypt_one(tfm, b, b_0);
95 + /* Extra Authenticate-only data (always two AES blocks) */
96 + for (i = 0; i < AES_BLOCK_SIZE; i++)
98 + crypto_cipher_encrypt_one(tfm, b, aad);
100 + aad += AES_BLOCK_SIZE;
102 + for (i = 0; i < AES_BLOCK_SIZE; i++)
104 + crypto_cipher_encrypt_one(tfm, a, aad);
106 + /* Mask out bits from auth-only-b_0 */
109 + /* S_0 is used to encrypt T (= MIC) */
112 + crypto_cipher_encrypt_one(tfm, s_0, b_0);
116 +void ieee80211_aes_ccm_encrypt(struct crypto_cipher *tfm, u8 *b_0, u8 *aad,
117 u8 *data, size_t data_len, u8 *mic,
120 - struct scatterlist assoc, pt, ct[2];
121 + int i, j, last_len, num_blocks;
122 + u8 b[AES_BLOCK_SIZE];
123 + u8 s_0[AES_BLOCK_SIZE];
124 + u8 e[AES_BLOCK_SIZE];
127 + num_blocks = DIV_ROUND_UP(data_len, AES_BLOCK_SIZE);
128 + last_len = data_len % AES_BLOCK_SIZE;
129 + aes_ccm_prepare(tfm, b_0, aad, s_0, b, b);
131 + /* Process payload blocks */
134 + for (j = 1; j <= num_blocks; j++) {
135 + int blen = (j == num_blocks && last_len) ?
136 + last_len : AES_BLOCK_SIZE;
138 + /* Authentication followed by encryption */
139 + for (i = 0; i < blen; i++)
141 + crypto_cipher_encrypt_one(tfm, b, b);
143 + b_0[14] = (j >> 8) & 0xff;
144 + b_0[15] = j & 0xff;
145 + crypto_cipher_encrypt_one(tfm, e, b_0);
146 + for (i = 0; i < blen; i++)
147 + *cpos++ = *pos++ ^ e[i];
150 - char aead_req_data[sizeof(struct aead_request) +
151 - crypto_aead_reqsize(tfm)]
152 - __aligned(__alignof__(struct aead_request));
153 - struct aead_request *aead_req = (void *) aead_req_data;
155 - memset(aead_req, 0, sizeof(aead_req_data));
157 - sg_init_one(&pt, data, data_len);
158 - sg_init_one(&assoc, &aad[2], be16_to_cpup((__be16 *)aad));
159 - sg_init_table(ct, 2);
160 - sg_set_buf(&ct[0], data, data_len);
161 - sg_set_buf(&ct[1], mic, mic_len);
163 - aead_request_set_tfm(aead_req, tfm);
164 - aead_request_set_assoc(aead_req, &assoc, assoc.length);
165 - aead_request_set_crypt(aead_req, &pt, ct, data_len, b_0);
167 - crypto_aead_encrypt(aead_req);
168 + for (i = 0; i < mic_len; i++)
169 + mic[i] = b[i] ^ s_0[i];
172 -int ieee80211_aes_ccm_decrypt(struct crypto_aead *tfm, u8 *b_0, u8 *aad,
173 +int ieee80211_aes_ccm_decrypt(struct crypto_cipher *tfm, u8 *b_0, u8 *aad,
174 u8 *data, size_t data_len, u8 *mic,
177 - struct scatterlist assoc, pt, ct[2];
178 - char aead_req_data[sizeof(struct aead_request) +
179 - crypto_aead_reqsize(tfm)]
180 - __aligned(__alignof__(struct aead_request));
181 - struct aead_request *aead_req = (void *) aead_req_data;
186 - memset(aead_req, 0, sizeof(aead_req_data));
188 - sg_init_one(&pt, data, data_len);
189 - sg_init_one(&assoc, &aad[2], be16_to_cpup((__be16 *)aad));
190 - sg_init_table(ct, 2);
191 - sg_set_buf(&ct[0], data, data_len);
192 - sg_set_buf(&ct[1], mic, mic_len);
194 - aead_request_set_tfm(aead_req, tfm);
195 - aead_request_set_assoc(aead_req, &assoc, assoc.length);
196 - aead_request_set_crypt(aead_req, ct, &pt, data_len + mic_len, b_0);
197 + int i, j, last_len, num_blocks;
199 + u8 a[AES_BLOCK_SIZE];
200 + u8 b[AES_BLOCK_SIZE];
201 + u8 s_0[AES_BLOCK_SIZE];
203 + num_blocks = DIV_ROUND_UP(data_len, AES_BLOCK_SIZE);
204 + last_len = data_len % AES_BLOCK_SIZE;
205 + aes_ccm_prepare(tfm, b_0, aad, s_0, a, b);
207 + /* Process payload blocks */
210 + for (j = 1; j <= num_blocks; j++) {
211 + int blen = (j == num_blocks && last_len) ?
212 + last_len : AES_BLOCK_SIZE;
214 + /* Decryption followed by authentication */
215 + b_0[14] = (j >> 8) & 0xff;
216 + b_0[15] = j & 0xff;
217 + crypto_cipher_encrypt_one(tfm, b, b_0);
218 + for (i = 0; i < blen; i++) {
219 + *pos = *cpos++ ^ b[i];
222 + crypto_cipher_encrypt_one(tfm, a, a);
225 + for (i = 0; i < mic_len; i++) {
226 + if ((mic[i] ^ s_0[i]) != a[i])
230 - return crypto_aead_decrypt(aead_req);
234 -struct crypto_aead *ieee80211_aes_key_setup_encrypt(const u8 key[],
237 +struct crypto_cipher *ieee80211_aes_key_setup_encrypt(const u8 key[],
241 - struct crypto_aead *tfm;
243 + struct crypto_cipher *tfm;
245 - tfm = crypto_alloc_aead("ccm(aes)", 0, CRYPTO_ALG_ASYNC);
249 - err = crypto_aead_setkey(tfm, key, key_len);
252 - err = crypto_aead_setauthsize(tfm, mic_len);
255 + tfm = crypto_alloc_cipher("aes", 0, CRYPTO_ALG_ASYNC);
257 + crypto_cipher_setkey(tfm, key, key_len);
262 - crypto_free_aead(tfm);
263 - return ERR_PTR(err);
266 -void ieee80211_aes_key_free(struct crypto_aead *tfm)
268 +void ieee80211_aes_key_free(struct crypto_cipher *tfm)
270 - crypto_free_aead(tfm);
271 + crypto_free_cipher(tfm);
273 --- a/net/mac80211/key.h
274 +++ b/net/mac80211/key.h
275 @@ -84,7 +84,7 @@ struct ieee80211_key {
278 u8 rx_pn[IEEE80211_NUM_TIDS + 1][IEEE80211_CCMP_PN_LEN];
279 - struct crypto_aead *tfm;
280 + struct crypto_cipher *tfm;
281 u32 replays; /* dot11RSNAStatsCCMPReplays */
284 --- a/net/mac80211/wpa.c
285 +++ b/net/mac80211/wpa.c
286 @@ -304,7 +304,8 @@ ieee80211_crypto_tkip_decrypt(struct iee
290 -static void ccmp_special_blocks(struct sk_buff *skb, u8 *pn, u8 *b_0, u8 *aad)
291 +static void ccmp_special_blocks(struct sk_buff *skb, u8 *pn, u8 *b_0, u8 *aad,
295 int a4_included, mgmt;
296 @@ -334,14 +335,8 @@ static void ccmp_special_blocks(struct s
300 - /* In CCM, the initial vectors (IV) used for CTR mode encryption and CBC
301 - * mode authentication are not allowed to collide, yet both are derived
302 - * from this vector b_0. We only set L := 1 here to indicate that the
303 - * data size can be represented in (L+1) bytes. The CCM layer will take
304 - * care of storing the data length in the top (L+1) bytes and setting
305 - * and clearing the other bits as is required to derive the two IVs.
308 + /* First block, b_0 */
309 + b_0[0] = 0x59; /* flags: Adata: 1, M: 011, L: 001 */
311 /* Nonce: Nonce Flags | A2 | PN
312 * Nonce Flags: Priority (b0..b3) | Management (b4) | Reserved (b5..b7)
313 @@ -349,6 +344,8 @@ static void ccmp_special_blocks(struct s
314 b_0[1] = qos_tid | (mgmt << 4);
315 memcpy(&b_0[2], hdr->addr2, ETH_ALEN);
316 memcpy(&b_0[8], pn, IEEE80211_CCMP_PN_LEN);
318 + put_unaligned_be16(data_len, &b_0[14]);
320 /* AAD (extra authenticate-only data) / masked 802.11 header
321 * FC | A1 | A2 | A3 | SC | [A4] | [QC] */
322 @@ -460,7 +457,7 @@ static int ccmp_encrypt_skb(struct ieee8
325 pos += IEEE80211_CCMP_HDR_LEN;
326 - ccmp_special_blocks(skb, pn, b_0, aad);
327 + ccmp_special_blocks(skb, pn, b_0, aad, len);
328 ieee80211_aes_ccm_encrypt(key->u.ccmp.tfm, b_0, aad, pos, len,
329 skb_put(skb, mic_len), mic_len);
331 @@ -531,7 +528,7 @@ ieee80211_crypto_ccmp_decrypt(struct iee
332 u8 aad[2 * AES_BLOCK_SIZE];
333 u8 b_0[AES_BLOCK_SIZE];
334 /* hardware didn't decrypt/verify MIC */
335 - ccmp_special_blocks(skb, pn, b_0, aad);
336 + ccmp_special_blocks(skb, pn, b_0, aad, data_len);
338 if (ieee80211_aes_ccm_decrypt(
339 key->u.ccmp.tfm, b_0, aad,
340 --- a/net/mac80211/aes_ccm.h
341 +++ b/net/mac80211/aes_ccm.h
344 #include <linux/crypto.h>
346 -struct crypto_aead *ieee80211_aes_key_setup_encrypt(const u8 key[],
349 -void ieee80211_aes_ccm_encrypt(struct crypto_aead *tfm, u8 *b_0, u8 *aad,
350 +struct crypto_cipher *ieee80211_aes_key_setup_encrypt(const u8 key[],
353 +void ieee80211_aes_ccm_encrypt(struct crypto_cipher *tfm, u8 *b_0, u8 *aad,
354 u8 *data, size_t data_len, u8 *mic,
356 -int ieee80211_aes_ccm_decrypt(struct crypto_aead *tfm, u8 *b_0, u8 *aad,
357 +int ieee80211_aes_ccm_decrypt(struct crypto_cipher *tfm, u8 *b_0, u8 *aad,
358 u8 *data, size_t data_len, u8 *mic,
360 -void ieee80211_aes_key_free(struct crypto_aead *tfm);
361 +void ieee80211_aes_key_free(struct crypto_cipher *tfm);
363 #endif /* AES_CCM_H */
364 --- a/net/mac80211/Kconfig
365 +++ b/net/mac80211/Kconfig
366 @@ -5,8 +5,6 @@ config MAC80211
368 depends on CRYPTO_ARC4
369 depends on CRYPTO_AES
370 - select BPAUTO_CRYPTO_CCM
371 - depends on CRYPTO_GCM
373 select BPAUTO_AVERAGE