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 - 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];
45 + crypto_cipher_encrypt_one(tfm, b, b_0);
47 + /* Extra Authenticate-only data (always two AES blocks) */
48 + for (i = 0; i < AES_BLOCK_SIZE; i++)
50 + crypto_cipher_encrypt_one(tfm, b, aad);
52 + aad += AES_BLOCK_SIZE;
54 + for (i = 0; i < AES_BLOCK_SIZE; i++)
56 + crypto_cipher_encrypt_one(tfm, a, aad);
58 - char aead_req_data[sizeof(struct aead_request) +
59 - crypto_aead_reqsize(tfm)]
60 - __aligned(__alignof__(struct aead_request));
61 - struct aead_request *aead_req = (void *) aead_req_data;
62 + /* Mask out bits from auth-only-b_0 */
65 - memset(aead_req, 0, sizeof(aead_req_data));
66 + /* S_0 is used to encrypt T (= MIC) */
69 + crypto_cipher_encrypt_one(tfm, s_0, b_0);
72 - sg_init_table(sg, 3);
73 - sg_set_buf(&sg[0], &aad[2], be16_to_cpup((__be16 *)aad));
74 - sg_set_buf(&sg[1], data, data_len);
75 - sg_set_buf(&sg[2], mic, mic_len);
77 - aead_request_set_tfm(aead_req, tfm);
78 - aead_request_set_crypt(aead_req, sg, sg, data_len, b_0);
79 - aead_request_set_ad(aead_req, sg[0].length);
80 +void ieee80211_aes_ccm_encrypt(struct crypto_cipher *tfm, u8 *b_0, u8 *aad,
81 + u8 *data, size_t data_len, u8 *mic,
84 + int i, j, last_len, num_blocks;
85 + u8 b[AES_BLOCK_SIZE];
86 + u8 s_0[AES_BLOCK_SIZE];
87 + u8 e[AES_BLOCK_SIZE];
90 + num_blocks = DIV_ROUND_UP(data_len, AES_BLOCK_SIZE);
91 + last_len = data_len % AES_BLOCK_SIZE;
92 + aes_ccm_prepare(tfm, b_0, aad, s_0, b, b);
94 + /* Process payload blocks */
97 + for (j = 1; j <= num_blocks; j++) {
98 + int blen = (j == num_blocks && last_len) ?
99 + last_len : AES_BLOCK_SIZE;
101 + /* Authentication followed by encryption */
102 + for (i = 0; i < blen; i++)
104 + crypto_cipher_encrypt_one(tfm, b, b);
106 + b_0[14] = (j >> 8) & 0xff;
107 + b_0[15] = j & 0xff;
108 + crypto_cipher_encrypt_one(tfm, e, b_0);
109 + for (i = 0; i < blen; i++)
110 + *cpos++ = *pos++ ^ e[i];
113 - crypto_aead_encrypt(aead_req);
114 + for (i = 0; i < mic_len; i++)
115 + mic[i] = b[i] ^ s_0[i];
118 -int ieee80211_aes_ccm_decrypt(struct crypto_aead *tfm, u8 *b_0, u8 *aad,
119 +int ieee80211_aes_ccm_decrypt(struct crypto_cipher *tfm, u8 *b_0, u8 *aad,
120 u8 *data, size_t data_len, u8 *mic,
123 - struct scatterlist sg[3];
124 - char aead_req_data[sizeof(struct aead_request) +
125 - crypto_aead_reqsize(tfm)]
126 - __aligned(__alignof__(struct aead_request));
127 - struct aead_request *aead_req = (void *) aead_req_data;
132 - memset(aead_req, 0, sizeof(aead_req_data));
134 - sg_init_table(sg, 3);
135 - sg_set_buf(&sg[0], &aad[2], be16_to_cpup((__be16 *)aad));
136 - sg_set_buf(&sg[1], data, data_len);
137 - sg_set_buf(&sg[2], mic, mic_len);
139 - aead_request_set_tfm(aead_req, tfm);
140 - aead_request_set_crypt(aead_req, sg, sg, data_len + mic_len, b_0);
141 - aead_request_set_ad(aead_req, sg[0].length);
142 + int i, j, last_len, num_blocks;
144 + u8 a[AES_BLOCK_SIZE];
145 + u8 b[AES_BLOCK_SIZE];
146 + u8 s_0[AES_BLOCK_SIZE];
148 + num_blocks = DIV_ROUND_UP(data_len, AES_BLOCK_SIZE);
149 + last_len = data_len % AES_BLOCK_SIZE;
150 + aes_ccm_prepare(tfm, b_0, aad, s_0, a, b);
152 + /* Process payload blocks */
155 + for (j = 1; j <= num_blocks; j++) {
156 + int blen = (j == num_blocks && last_len) ?
157 + last_len : AES_BLOCK_SIZE;
159 + /* Decryption followed by authentication */
160 + b_0[14] = (j >> 8) & 0xff;
161 + b_0[15] = j & 0xff;
162 + crypto_cipher_encrypt_one(tfm, b, b_0);
163 + for (i = 0; i < blen; i++) {
164 + *pos = *cpos++ ^ b[i];
167 + crypto_cipher_encrypt_one(tfm, a, a);
170 + for (i = 0; i < mic_len; i++) {
171 + if ((mic[i] ^ s_0[i]) != a[i])
175 - return crypto_aead_decrypt(aead_req);
179 -struct crypto_aead *ieee80211_aes_key_setup_encrypt(const u8 key[],
182 +struct crypto_cipher *ieee80211_aes_key_setup_encrypt(const u8 key[],
186 - struct crypto_aead *tfm;
188 + struct crypto_cipher *tfm;
190 - tfm = crypto_alloc_aead("ccm(aes)", 0, CRYPTO_ALG_ASYNC);
194 - err = crypto_aead_setkey(tfm, key, key_len);
197 - err = crypto_aead_setauthsize(tfm, mic_len);
200 + tfm = crypto_alloc_cipher("aes", 0, CRYPTO_ALG_ASYNC);
202 + crypto_cipher_setkey(tfm, key, key_len);
207 - crypto_free_aead(tfm);
208 - return ERR_PTR(err);
211 -void ieee80211_aes_key_free(struct crypto_aead *tfm)
213 +void ieee80211_aes_key_free(struct crypto_cipher *tfm)
215 - crypto_free_aead(tfm);
216 + crypto_free_cipher(tfm);
218 --- a/net/mac80211/aes_ccm.h
219 +++ b/net/mac80211/aes_ccm.h
222 #include <linux/crypto.h>
224 -struct crypto_aead *ieee80211_aes_key_setup_encrypt(const u8 key[],
227 -void ieee80211_aes_ccm_encrypt(struct crypto_aead *tfm, u8 *b_0, u8 *aad,
228 +struct crypto_cipher *ieee80211_aes_key_setup_encrypt(const u8 key[],
231 +void ieee80211_aes_ccm_encrypt(struct crypto_cipher *tfm, u8 *b_0, u8 *aad,
232 u8 *data, size_t data_len, u8 *mic,
234 -int ieee80211_aes_ccm_decrypt(struct crypto_aead *tfm, u8 *b_0, u8 *aad,
235 +int ieee80211_aes_ccm_decrypt(struct crypto_cipher *tfm, u8 *b_0, u8 *aad,
236 u8 *data, size_t data_len, u8 *mic,
238 -void ieee80211_aes_key_free(struct crypto_aead *tfm);
239 +void ieee80211_aes_key_free(struct crypto_cipher *tfm);
241 #endif /* AES_CCM_H */
242 --- a/net/mac80211/aes_gcm.h
243 +++ b/net/mac80211/aes_gcm.h
246 #include <linux/crypto.h>
248 -void ieee80211_aes_gcm_encrypt(struct crypto_aead *tfm, u8 *j_0, u8 *aad,
249 - u8 *data, size_t data_len, u8 *mic);
250 -int ieee80211_aes_gcm_decrypt(struct crypto_aead *tfm, u8 *j_0, u8 *aad,
251 - u8 *data, size_t data_len, u8 *mic);
252 -struct crypto_aead *ieee80211_aes_gcm_key_setup_encrypt(const u8 key[],
254 -void ieee80211_aes_gcm_key_free(struct crypto_aead *tfm);
256 +ieee80211_aes_gcm_encrypt(struct crypto_aead *tfm, u8 *j_0, u8 *aad,
257 + u8 *data, size_t data_len, u8 *mic)
262 +ieee80211_aes_gcm_decrypt(struct crypto_aead *tfm, u8 *j_0, u8 *aad,
263 + u8 *data, size_t data_len, u8 *mic)
265 + return -EOPNOTSUPP;
268 +static inline struct crypto_aead *
269 +ieee80211_aes_gcm_key_setup_encrypt(const u8 key[], size_t key_len)
275 +ieee80211_aes_gcm_key_free(struct crypto_aead *tfm)
279 #endif /* AES_GCM_H */
280 --- a/net/mac80211/aes_gmac.h
281 +++ b/net/mac80211/aes_gmac.h
284 #include <linux/crypto.h>
286 -struct crypto_aead *ieee80211_aes_gmac_key_setup(const u8 key[],
288 -int ieee80211_aes_gmac(struct crypto_aead *tfm, const u8 *aad, u8 *nonce,
289 - const u8 *data, size_t data_len, u8 *mic);
290 -void ieee80211_aes_gmac_key_free(struct crypto_aead *tfm);
291 +static inline struct crypto_aead *
292 +ieee80211_aes_gmac_key_setup(const u8 key[], size_t key_len)
298 +ieee80211_aes_gmac(struct crypto_aead *tfm, const u8 *aad, u8 *nonce,
299 + const u8 *data, size_t data_len, u8 *mic)
301 + return -EOPNOTSUPP;
305 +ieee80211_aes_gmac_key_free(struct crypto_aead *tfm)
309 #endif /* AES_GMAC_H */
310 --- a/net/mac80211/key.h
311 +++ b/net/mac80211/key.h
312 @@ -84,7 +84,7 @@ struct ieee80211_key {
315 u8 rx_pn[IEEE80211_NUM_TIDS + 1][IEEE80211_CCMP_PN_LEN];
316 - struct crypto_aead *tfm;
317 + struct crypto_cipher *tfm;
318 u32 replays; /* dot11RSNAStatsCCMPReplays */
321 --- a/net/mac80211/wpa.c
322 +++ b/net/mac80211/wpa.c
323 @@ -307,7 +307,8 @@ ieee80211_crypto_tkip_decrypt(struct iee
327 -static void ccmp_special_blocks(struct sk_buff *skb, u8 *pn, u8 *b_0, u8 *aad)
328 +static void ccmp_special_blocks(struct sk_buff *skb, u8 *pn, u8 *b_0, u8 *aad,
332 int a4_included, mgmt;
333 @@ -337,14 +338,8 @@ static void ccmp_special_blocks(struct s
337 - /* In CCM, the initial vectors (IV) used for CTR mode encryption and CBC
338 - * mode authentication are not allowed to collide, yet both are derived
339 - * from this vector b_0. We only set L := 1 here to indicate that the
340 - * data size can be represented in (L+1) bytes. The CCM layer will take
341 - * care of storing the data length in the top (L+1) bytes and setting
342 - * and clearing the other bits as is required to derive the two IVs.
345 + /* First block, b_0 */
346 + b_0[0] = 0x59; /* flags: Adata: 1, M: 011, L: 001 */
348 /* Nonce: Nonce Flags | A2 | PN
349 * Nonce Flags: Priority (b0..b3) | Management (b4) | Reserved (b5..b7)
350 @@ -352,6 +347,8 @@ static void ccmp_special_blocks(struct s
351 b_0[1] = qos_tid | (mgmt << 4);
352 memcpy(&b_0[2], hdr->addr2, ETH_ALEN);
353 memcpy(&b_0[8], pn, IEEE80211_CCMP_PN_LEN);
355 + put_unaligned_be16(data_len, &b_0[14]);
357 /* AAD (extra authenticate-only data) / masked 802.11 header
358 * FC | A1 | A2 | A3 | SC | [A4] | [QC] */
359 @@ -463,7 +460,7 @@ static int ccmp_encrypt_skb(struct ieee8
362 pos += IEEE80211_CCMP_HDR_LEN;
363 - ccmp_special_blocks(skb, pn, b_0, aad);
364 + ccmp_special_blocks(skb, pn, b_0, aad, len);
365 ieee80211_aes_ccm_encrypt(key->u.ccmp.tfm, b_0, aad, pos, len,
366 skb_put(skb, mic_len), mic_len);
368 @@ -534,7 +531,7 @@ ieee80211_crypto_ccmp_decrypt(struct iee
369 u8 aad[2 * AES_BLOCK_SIZE];
370 u8 b_0[AES_BLOCK_SIZE];
371 /* hardware didn't decrypt/verify MIC */
372 - ccmp_special_blocks(skb, pn, b_0, aad);
373 + ccmp_special_blocks(skb, pn, b_0, aad, data_len);
375 if (ieee80211_aes_ccm_decrypt(
376 key->u.ccmp.tfm, b_0, aad,