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
11 This option enables the hardware independent IEEE 802.11
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 -void ieee80211_aes_ccm_encrypt(struct crypto_aead *tfm, u8 *b_0, u8 *aad,
37 +static void aes_ccm_prepare(struct crypto_cipher *tfm, u8 *b_0, u8 *aad, u8 *s_0,
42 + crypto_cipher_encrypt_one(tfm, b, b_0);
44 + /* Extra Authenticate-only data (always two AES blocks) */
45 + for (i = 0; i < AES_BLOCK_SIZE; i++)
47 + crypto_cipher_encrypt_one(tfm, b, aad);
49 + aad += AES_BLOCK_SIZE;
51 + for (i = 0; i < AES_BLOCK_SIZE; i++)
53 + crypto_cipher_encrypt_one(tfm, a, aad);
55 + /* Mask out bits from auth-only-b_0 */
58 + /* S_0 is used to encrypt T (= MIC) */
61 + crypto_cipher_encrypt_one(tfm, s_0, b_0);
65 +void ieee80211_aes_ccm_encrypt(struct crypto_cipher *tfm, u8 *b_0, u8 *aad,
66 u8 *data, size_t data_len, u8 *mic,
69 - struct scatterlist sg[3];
70 + int i, j, last_len, num_blocks;
71 + u8 b[AES_BLOCK_SIZE];
72 + u8 s_0[AES_BLOCK_SIZE];
73 + u8 e[AES_BLOCK_SIZE];
76 - char aead_req_data[sizeof(struct aead_request) +
77 - crypto_aead_reqsize(tfm)]
78 - __aligned(__alignof__(struct aead_request));
79 - struct aead_request *aead_req = (void *) aead_req_data;
80 + num_blocks = DIV_ROUND_UP(data_len, AES_BLOCK_SIZE);
81 + last_len = data_len % AES_BLOCK_SIZE;
82 + aes_ccm_prepare(tfm, b_0, aad, s_0, b, b);
84 - memset(aead_req, 0, sizeof(aead_req_data));
85 + /* Process payload blocks */
88 + for (j = 1; j <= num_blocks; j++) {
89 + int blen = (j == num_blocks && last_len) ?
90 + last_len : AES_BLOCK_SIZE;
92 - sg_init_table(sg, 3);
93 - sg_set_buf(&sg[0], &aad[2], be16_to_cpup((__be16 *)aad));
94 - sg_set_buf(&sg[1], data, data_len);
95 - sg_set_buf(&sg[2], mic, mic_len);
96 + /* Authentication followed by encryption */
97 + for (i = 0; i < blen; i++)
99 + crypto_cipher_encrypt_one(tfm, b, b);
101 - aead_request_set_tfm(aead_req, tfm);
102 - aead_request_set_crypt(aead_req, sg, sg, data_len, b_0);
103 - aead_request_set_ad(aead_req, sg[0].length);
104 + b_0[14] = (j >> 8) & 0xff;
105 + b_0[15] = j & 0xff;
106 + crypto_cipher_encrypt_one(tfm, e, b_0);
107 + for (i = 0; i < blen; i++)
108 + *cpos++ = *pos++ ^ e[i];
111 - crypto_aead_encrypt(aead_req);
112 + for (i = 0; i < mic_len; i++)
113 + mic[i] = b[i] ^ s_0[i];
116 -int ieee80211_aes_ccm_decrypt(struct crypto_aead *tfm, u8 *b_0, u8 *aad,
117 +int ieee80211_aes_ccm_decrypt(struct crypto_cipher *tfm, u8 *b_0, u8 *aad,
118 u8 *data, size_t data_len, u8 *mic,
121 - struct scatterlist sg[3];
122 - char aead_req_data[sizeof(struct aead_request) +
123 - crypto_aead_reqsize(tfm)]
124 - __aligned(__alignof__(struct aead_request));
125 - struct aead_request *aead_req = (void *) aead_req_data;
126 + int i, j, last_len, num_blocks;
128 + u8 a[AES_BLOCK_SIZE];
129 + u8 b[AES_BLOCK_SIZE];
130 + u8 s_0[AES_BLOCK_SIZE];
134 + num_blocks = DIV_ROUND_UP(data_len, AES_BLOCK_SIZE);
135 + last_len = data_len % AES_BLOCK_SIZE;
136 + aes_ccm_prepare(tfm, b_0, aad, s_0, a, b);
138 - memset(aead_req, 0, sizeof(aead_req_data));
139 + /* Process payload blocks */
142 + for (j = 1; j <= num_blocks; j++) {
143 + int blen = (j == num_blocks && last_len) ?
144 + last_len : AES_BLOCK_SIZE;
146 - sg_init_table(sg, 3);
147 - sg_set_buf(&sg[0], &aad[2], be16_to_cpup((__be16 *)aad));
148 - sg_set_buf(&sg[1], data, data_len);
149 - sg_set_buf(&sg[2], mic, mic_len);
150 + /* Decryption followed by authentication */
151 + b_0[14] = (j >> 8) & 0xff;
152 + b_0[15] = j & 0xff;
153 + crypto_cipher_encrypt_one(tfm, b, b_0);
154 + for (i = 0; i < blen; i++) {
155 + *pos = *cpos++ ^ b[i];
158 + crypto_cipher_encrypt_one(tfm, a, a);
161 - aead_request_set_tfm(aead_req, tfm);
162 - aead_request_set_crypt(aead_req, sg, sg, data_len + mic_len, b_0);
163 - aead_request_set_ad(aead_req, sg[0].length);
164 + for (i = 0; i < mic_len; i++) {
165 + if ((mic[i] ^ s_0[i]) != a[i])
169 - return crypto_aead_decrypt(aead_req);
173 -struct crypto_aead *ieee80211_aes_key_setup_encrypt(const u8 key[],
176 +struct crypto_cipher *ieee80211_aes_key_setup_encrypt(const u8 key[],
180 - struct crypto_aead *tfm;
183 - tfm = crypto_alloc_aead("ccm(aes)", 0, CRYPTO_ALG_ASYNC);
186 + struct crypto_cipher *tfm;
188 - err = crypto_aead_setkey(tfm, key, key_len);
191 - err = crypto_aead_setauthsize(tfm, mic_len);
194 + tfm = crypto_alloc_cipher("aes", 0, CRYPTO_ALG_ASYNC);
196 + crypto_cipher_setkey(tfm, key, key_len);
201 - crypto_free_aead(tfm);
202 - return ERR_PTR(err);
205 -void ieee80211_aes_key_free(struct crypto_aead *tfm)
207 +void ieee80211_aes_key_free(struct crypto_cipher *tfm)
209 - crypto_free_aead(tfm);
210 + crypto_free_cipher(tfm);
212 --- a/net/mac80211/aes_ccm.h
213 +++ b/net/mac80211/aes_ccm.h
216 #include <linux/crypto.h>
218 -struct crypto_aead *ieee80211_aes_key_setup_encrypt(const u8 key[],
221 -void ieee80211_aes_ccm_encrypt(struct crypto_aead *tfm, u8 *b_0, u8 *aad,
222 +struct crypto_cipher *ieee80211_aes_key_setup_encrypt(const u8 key[],
225 +void ieee80211_aes_ccm_encrypt(struct crypto_cipher *tfm, u8 *b_0, u8 *aad,
226 u8 *data, size_t data_len, u8 *mic,
228 -int ieee80211_aes_ccm_decrypt(struct crypto_aead *tfm, u8 *b_0, u8 *aad,
229 +int ieee80211_aes_ccm_decrypt(struct crypto_cipher *tfm, u8 *b_0, u8 *aad,
230 u8 *data, size_t data_len, u8 *mic,
232 -void ieee80211_aes_key_free(struct crypto_aead *tfm);
233 +void ieee80211_aes_key_free(struct crypto_cipher *tfm);
235 #endif /* AES_CCM_H */
236 --- a/net/mac80211/aes_gcm.h
237 +++ b/net/mac80211/aes_gcm.h
240 #include <linux/crypto.h>
242 -void ieee80211_aes_gcm_encrypt(struct crypto_aead *tfm, u8 *j_0, u8 *aad,
243 - u8 *data, size_t data_len, u8 *mic);
244 -int ieee80211_aes_gcm_decrypt(struct crypto_aead *tfm, u8 *j_0, u8 *aad,
245 - u8 *data, size_t data_len, u8 *mic);
246 -struct crypto_aead *ieee80211_aes_gcm_key_setup_encrypt(const u8 key[],
248 -void ieee80211_aes_gcm_key_free(struct crypto_aead *tfm);
250 +ieee80211_aes_gcm_encrypt(struct crypto_aead *tfm, u8 *j_0, u8 *aad,
251 + u8 *data, size_t data_len, u8 *mic)
256 +ieee80211_aes_gcm_decrypt(struct crypto_aead *tfm, u8 *j_0, u8 *aad,
257 + u8 *data, size_t data_len, u8 *mic)
259 + return -EOPNOTSUPP;
262 +static inline struct crypto_aead *
263 +ieee80211_aes_gcm_key_setup_encrypt(const u8 key[], size_t key_len)
269 +ieee80211_aes_gcm_key_free(struct crypto_aead *tfm)
273 #endif /* AES_GCM_H */
274 --- a/net/mac80211/aes_gmac.h
275 +++ b/net/mac80211/aes_gmac.h
278 #include <linux/crypto.h>
280 -struct crypto_aead *ieee80211_aes_gmac_key_setup(const u8 key[],
282 -int ieee80211_aes_gmac(struct crypto_aead *tfm, const u8 *aad, u8 *nonce,
283 - const u8 *data, size_t data_len, u8 *mic);
284 -void ieee80211_aes_gmac_key_free(struct crypto_aead *tfm);
285 +static inline struct crypto_aead *
286 +ieee80211_aes_gmac_key_setup(const u8 key[], size_t key_len)
292 +ieee80211_aes_gmac(struct crypto_aead *tfm, const u8 *aad, u8 *nonce,
293 + const u8 *data, size_t data_len, u8 *mic)
295 + return -EOPNOTSUPP;
299 +ieee80211_aes_gmac_key_free(struct crypto_aead *tfm)
303 #endif /* AES_GMAC_H */
304 --- a/net/mac80211/key.h
305 +++ b/net/mac80211/key.h
306 @@ -88,7 +88,7 @@ struct ieee80211_key {
309 u8 rx_pn[IEEE80211_NUM_TIDS + 1][IEEE80211_CCMP_PN_LEN];
310 - struct crypto_aead *tfm;
311 + struct crypto_cipher *tfm;
312 u32 replays; /* dot11RSNAStatsCCMPReplays */
315 --- a/net/mac80211/wpa.c
316 +++ b/net/mac80211/wpa.c
317 @@ -304,7 +304,8 @@ ieee80211_crypto_tkip_decrypt(struct iee
321 -static void ccmp_special_blocks(struct sk_buff *skb, u8 *pn, u8 *b_0, u8 *aad)
322 +static void ccmp_special_blocks(struct sk_buff *skb, u8 *pn, u8 *b_0, u8 *aad,
326 int a4_included, mgmt;
327 @@ -334,14 +335,8 @@ static void ccmp_special_blocks(struct s
331 - /* In CCM, the initial vectors (IV) used for CTR mode encryption and CBC
332 - * mode authentication are not allowed to collide, yet both are derived
333 - * from this vector b_0. We only set L := 1 here to indicate that the
334 - * data size can be represented in (L+1) bytes. The CCM layer will take
335 - * care of storing the data length in the top (L+1) bytes and setting
336 - * and clearing the other bits as is required to derive the two IVs.
339 + /* First block, b_0 */
340 + b_0[0] = 0x59; /* flags: Adata: 1, M: 011, L: 001 */
342 /* Nonce: Nonce Flags | A2 | PN
343 * Nonce Flags: Priority (b0..b3) | Management (b4) | Reserved (b5..b7)
344 @@ -349,6 +344,8 @@ static void ccmp_special_blocks(struct s
345 b_0[1] = qos_tid | (mgmt << 4);
346 memcpy(&b_0[2], hdr->addr2, ETH_ALEN);
347 memcpy(&b_0[8], pn, IEEE80211_CCMP_PN_LEN);
349 + put_unaligned_be16(data_len, &b_0[14]);
351 /* AAD (extra authenticate-only data) / masked 802.11 header
352 * FC | A1 | A2 | A3 | SC | [A4] | [QC] */
353 @@ -460,7 +457,7 @@ static int ccmp_encrypt_skb(struct ieee8
356 pos += IEEE80211_CCMP_HDR_LEN;
357 - ccmp_special_blocks(skb, pn, b_0, aad);
358 + ccmp_special_blocks(skb, pn, b_0, aad, len);
359 ieee80211_aes_ccm_encrypt(key->u.ccmp.tfm, b_0, aad, pos, len,
360 skb_put(skb, mic_len), mic_len);
362 @@ -537,7 +534,7 @@ ieee80211_crypto_ccmp_decrypt(struct iee
363 u8 aad[2 * AES_BLOCK_SIZE];
364 u8 b_0[AES_BLOCK_SIZE];
365 /* hardware didn't decrypt/verify MIC */
366 - ccmp_special_blocks(skb, pn, b_0, aad);
367 + ccmp_special_blocks(skb, pn, b_0, aad, data_len);
369 if (ieee80211_aes_ccm_decrypt(
370 key->u.ccmp.tfm, b_0, aad,