Commit feccb466944cb1aeaabc701cfde6771f3be74919
Committed by
John W. Linville
1 parent
c34498b9e6
Exists in
master
and in
4 other branches
mac80211: pass scratch buffer directly, remove additional pointers
Recalculate the offset pointers in the ccmp calculations rather than in the callers. Signed-off-by: Harvey Harrison <harvey.harrison@gmail.com> Signed-off-by: John W. Linville <linville@tuxdriver.com>
Showing 3 changed files with 20 additions and 23 deletions Side-by-side Diff
net/mac80211/aes_ccm.c
... | ... | @@ -53,15 +53,17 @@ |
53 | 53 | |
54 | 54 | |
55 | 55 | void ieee80211_aes_ccm_encrypt(struct crypto_cipher *tfm, u8 *scratch, |
56 | - u8 *b_0, u8 *aad, u8 *data, size_t data_len, | |
56 | + u8 *data, size_t data_len, | |
57 | 57 | u8 *cdata, u8 *mic) |
58 | 58 | { |
59 | 59 | int i, j, last_len, num_blocks; |
60 | - u8 *pos, *cpos, *b, *s_0, *e; | |
60 | + u8 *pos, *cpos, *b, *s_0, *e, *b_0, *aad; | |
61 | 61 | |
62 | 62 | b = scratch; |
63 | 63 | s_0 = scratch + AES_BLOCK_LEN; |
64 | 64 | e = scratch + 2 * AES_BLOCK_LEN; |
65 | + b_0 = scratch + 3 * AES_BLOCK_LEN; | |
66 | + aad = scratch + 4 * AES_BLOCK_LEN; | |
65 | 67 | |
66 | 68 | num_blocks = DIV_ROUND_UP(data_len, AES_BLOCK_LEN); |
67 | 69 | last_len = data_len % AES_BLOCK_LEN; |
68 | 70 | |
69 | 71 | |
... | ... | @@ -92,15 +94,16 @@ |
92 | 94 | |
93 | 95 | |
94 | 96 | int ieee80211_aes_ccm_decrypt(struct crypto_cipher *tfm, u8 *scratch, |
95 | - u8 *b_0, u8 *aad, u8 *cdata, size_t data_len, | |
96 | - u8 *mic, u8 *data) | |
97 | + u8 *cdata, size_t data_len, u8 *mic, u8 *data) | |
97 | 98 | { |
98 | 99 | int i, j, last_len, num_blocks; |
99 | - u8 *pos, *cpos, *b, *s_0, *a; | |
100 | + u8 *pos, *cpos, *b, *s_0, *a, *b_0, *aad; | |
100 | 101 | |
101 | 102 | b = scratch; |
102 | 103 | s_0 = scratch + AES_BLOCK_LEN; |
103 | 104 | a = scratch + 2 * AES_BLOCK_LEN; |
105 | + b_0 = scratch + 3 * AES_BLOCK_LEN; | |
106 | + aad = scratch + 4 * AES_BLOCK_LEN; | |
104 | 107 | |
105 | 108 | num_blocks = DIV_ROUND_UP(data_len, AES_BLOCK_LEN); |
106 | 109 | last_len = data_len % AES_BLOCK_LEN; |
net/mac80211/aes_ccm.h
... | ... | @@ -16,10 +16,10 @@ |
16 | 16 | |
17 | 17 | struct crypto_cipher *ieee80211_aes_key_setup_encrypt(const u8 key[]); |
18 | 18 | void ieee80211_aes_ccm_encrypt(struct crypto_cipher *tfm, u8 *scratch, |
19 | - u8 *b_0, u8 *aad, u8 *data, size_t data_len, | |
19 | + u8 *data, size_t data_len, | |
20 | 20 | u8 *cdata, u8 *mic); |
21 | 21 | int ieee80211_aes_ccm_decrypt(struct crypto_cipher *tfm, u8 *scratch, |
22 | - u8 *b_0, u8 *aad, u8 *cdata, size_t data_len, | |
22 | + u8 *cdata, size_t data_len, | |
23 | 23 | u8 *mic, u8 *data); |
24 | 24 | void ieee80211_aes_key_free(struct crypto_cipher *tfm); |
25 | 25 |
net/mac80211/wpa.c
... | ... | @@ -274,16 +274,20 @@ |
274 | 274 | } |
275 | 275 | |
276 | 276 | |
277 | -static void ccmp_special_blocks(struct sk_buff *skb, u8 *pn, u8 *b_0, u8 *aad, | |
277 | +static void ccmp_special_blocks(struct sk_buff *skb, u8 *pn, u8 *scratch, | |
278 | 278 | int encrypted) |
279 | 279 | { |
280 | 280 | __le16 mask_fc; |
281 | 281 | int a4_included; |
282 | 282 | u8 qos_tid; |
283 | + u8 *b_0, *aad; | |
283 | 284 | u16 data_len, len_a; |
284 | 285 | unsigned int hdrlen; |
285 | 286 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; |
286 | 287 | |
288 | + b_0 = scratch + 3 * AES_BLOCK_LEN; | |
289 | + aad = scratch + 4 * AES_BLOCK_LEN; | |
290 | + | |
287 | 291 | /* |
288 | 292 | * Mask FC: zero subtype b4 b5 b6 |
289 | 293 | * Retry, PwrMgt, MoreData; set Protected |
... | ... | @@ -367,7 +371,7 @@ |
367 | 371 | struct ieee80211_key *key = tx->key; |
368 | 372 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); |
369 | 373 | int hdrlen, len, tail; |
370 | - u8 *pos, *pn, *b_0, *aad, *scratch; | |
374 | + u8 *pos, *pn; | |
371 | 375 | int i; |
372 | 376 | |
373 | 377 | info->control.icv_len = CCMP_MIC_LEN; |
... | ... | @@ -381,10 +385,6 @@ |
381 | 385 | return 0; |
382 | 386 | } |
383 | 387 | |
384 | - scratch = key->u.ccmp.tx_crypto_buf; | |
385 | - b_0 = scratch + 3 * AES_BLOCK_LEN; | |
386 | - aad = scratch + 4 * AES_BLOCK_LEN; | |
387 | - | |
388 | 388 | hdrlen = ieee80211_hdrlen(hdr->frame_control); |
389 | 389 | len = skb->len - hdrlen; |
390 | 390 | |
... | ... | @@ -420,8 +420,8 @@ |
420 | 420 | } |
421 | 421 | |
422 | 422 | pos += CCMP_HDR_LEN; |
423 | - ccmp_special_blocks(skb, pn, b_0, aad, 0); | |
424 | - ieee80211_aes_ccm_encrypt(key->u.ccmp.tfm, scratch, b_0, aad, pos, len, | |
423 | + ccmp_special_blocks(skb, pn, key->u.ccmp.tx_crypto_buf, 0); | |
424 | + ieee80211_aes_ccm_encrypt(key->u.ccmp.tfm, key->u.ccmp.tx_crypto_buf, pos, len, | |
425 | 425 | pos, skb_put(skb, CCMP_MIC_LEN)); |
426 | 426 | |
427 | 427 | return 0; |
428 | 428 | |
429 | 429 | |
... | ... | @@ -483,16 +483,10 @@ |
483 | 483 | |
484 | 484 | if (!(rx->status->flag & RX_FLAG_DECRYPTED)) { |
485 | 485 | /* hardware didn't decrypt/verify MIC */ |
486 | - u8 *scratch, *b_0, *aad; | |
486 | + ccmp_special_blocks(skb, pn, key->u.ccmp.rx_crypto_buf, 1); | |
487 | 487 | |
488 | - scratch = key->u.ccmp.rx_crypto_buf; | |
489 | - b_0 = scratch + 3 * AES_BLOCK_LEN; | |
490 | - aad = scratch + 4 * AES_BLOCK_LEN; | |
491 | - | |
492 | - ccmp_special_blocks(skb, pn, b_0, aad, 1); | |
493 | - | |
494 | 488 | if (ieee80211_aes_ccm_decrypt( |
495 | - key->u.ccmp.tfm, scratch, b_0, aad, | |
489 | + key->u.ccmp.tfm, key->u.ccmp.rx_crypto_buf, | |
496 | 490 | skb->data + hdrlen + CCMP_HDR_LEN, data_len, |
497 | 491 | skb->data + skb->len - CCMP_MIC_LEN, |
498 | 492 | skb->data + hdrlen + CCMP_HDR_LEN)) { |