diff options
Diffstat (limited to 'net/mac80211/wpa.c')
-rw-r--r-- | net/mac80211/wpa.c | 152 |
1 files changed, 144 insertions, 8 deletions
diff --git a/net/mac80211/wpa.c b/net/mac80211/wpa.c index 7aa63caf8d50..9101b48ec2ae 100644 --- a/net/mac80211/wpa.c +++ b/net/mac80211/wpa.c | |||
@@ -1,5 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | * Copyright 2002-2004, Instant802 Networks, Inc. | 2 | * Copyright 2002-2004, Instant802 Networks, Inc. |
3 | * Copyright 2008, Jouni Malinen <j@w1.fi> | ||
3 | * | 4 | * |
4 | * This program is free software; you can redistribute it and/or modify | 5 | * This program is free software; you can redistribute it and/or modify |
5 | * it under the terms of the GNU General Public License version 2 as | 6 | * it under the terms of the GNU General Public License version 2 as |
@@ -19,6 +20,7 @@ | |||
19 | #include "michael.h" | 20 | #include "michael.h" |
20 | #include "tkip.h" | 21 | #include "tkip.h" |
21 | #include "aes_ccm.h" | 22 | #include "aes_ccm.h" |
23 | #include "aes_cmac.h" | ||
22 | #include "wpa.h" | 24 | #include "wpa.h" |
23 | 25 | ||
24 | ieee80211_tx_result | 26 | ieee80211_tx_result |
@@ -266,7 +268,7 @@ static void ccmp_special_blocks(struct sk_buff *skb, u8 *pn, u8 *scratch, | |||
266 | int encrypted) | 268 | int encrypted) |
267 | { | 269 | { |
268 | __le16 mask_fc; | 270 | __le16 mask_fc; |
269 | int a4_included; | 271 | int a4_included, mgmt; |
270 | u8 qos_tid; | 272 | u8 qos_tid; |
271 | u8 *b_0, *aad; | 273 | u8 *b_0, *aad; |
272 | u16 data_len, len_a; | 274 | u16 data_len, len_a; |
@@ -277,12 +279,15 @@ static void ccmp_special_blocks(struct sk_buff *skb, u8 *pn, u8 *scratch, | |||
277 | aad = scratch + 4 * AES_BLOCK_LEN; | 279 | aad = scratch + 4 * AES_BLOCK_LEN; |
278 | 280 | ||
279 | /* | 281 | /* |
280 | * Mask FC: zero subtype b4 b5 b6 | 282 | * Mask FC: zero subtype b4 b5 b6 (if not mgmt) |
281 | * Retry, PwrMgt, MoreData; set Protected | 283 | * Retry, PwrMgt, MoreData; set Protected |
282 | */ | 284 | */ |
285 | mgmt = ieee80211_is_mgmt(hdr->frame_control); | ||
283 | mask_fc = hdr->frame_control; | 286 | mask_fc = hdr->frame_control; |
284 | mask_fc &= ~cpu_to_le16(0x0070 | IEEE80211_FCTL_RETRY | | 287 | mask_fc &= ~cpu_to_le16(IEEE80211_FCTL_RETRY | |
285 | IEEE80211_FCTL_PM | IEEE80211_FCTL_MOREDATA); | 288 | IEEE80211_FCTL_PM | IEEE80211_FCTL_MOREDATA); |
289 | if (!mgmt) | ||
290 | mask_fc &= ~cpu_to_le16(0x0070); | ||
286 | mask_fc |= cpu_to_le16(IEEE80211_FCTL_PROTECTED); | 291 | mask_fc |= cpu_to_le16(IEEE80211_FCTL_PROTECTED); |
287 | 292 | ||
288 | hdrlen = ieee80211_hdrlen(hdr->frame_control); | 293 | hdrlen = ieee80211_hdrlen(hdr->frame_control); |
@@ -300,8 +305,10 @@ static void ccmp_special_blocks(struct sk_buff *skb, u8 *pn, u8 *scratch, | |||
300 | 305 | ||
301 | /* First block, b_0 */ | 306 | /* First block, b_0 */ |
302 | b_0[0] = 0x59; /* flags: Adata: 1, M: 011, L: 001 */ | 307 | b_0[0] = 0x59; /* flags: Adata: 1, M: 011, L: 001 */ |
303 | /* Nonce: QoS Priority | A2 | PN */ | 308 | /* Nonce: Nonce Flags | A2 | PN |
304 | b_0[1] = qos_tid; | 309 | * Nonce Flags: Priority (b0..b3) | Management (b4) | Reserved (b5..b7) |
310 | */ | ||
311 | b_0[1] = qos_tid | (mgmt << 4); | ||
305 | memcpy(&b_0[2], hdr->addr2, ETH_ALEN); | 312 | memcpy(&b_0[2], hdr->addr2, ETH_ALEN); |
306 | memcpy(&b_0[8], pn, CCMP_PN_LEN); | 313 | memcpy(&b_0[8], pn, CCMP_PN_LEN); |
307 | /* l(m) */ | 314 | /* l(m) */ |
@@ -360,9 +367,14 @@ static int ccmp_encrypt_skb(struct ieee80211_tx_data *tx, struct sk_buff *skb) | |||
360 | int hdrlen, len, tail; | 367 | int hdrlen, len, tail; |
361 | u8 *pos, *pn; | 368 | u8 *pos, *pn; |
362 | int i; | 369 | int i; |
370 | bool skip_hw; | ||
371 | |||
372 | skip_hw = (tx->key->conf.flags & IEEE80211_KEY_FLAG_SW_MGMT) && | ||
373 | ieee80211_is_mgmt(hdr->frame_control); | ||
363 | 374 | ||
364 | if ((tx->key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE) && | 375 | if ((tx->key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE) && |
365 | !(tx->key->conf.flags & IEEE80211_KEY_FLAG_GENERATE_IV)) { | 376 | !(tx->key->conf.flags & IEEE80211_KEY_FLAG_GENERATE_IV) && |
377 | !skip_hw) { | ||
366 | /* hwaccel - with no need for preallocated room for CCMP | 378 | /* hwaccel - with no need for preallocated room for CCMP |
367 | * header or MIC fields */ | 379 | * header or MIC fields */ |
368 | info->control.hw_key = &tx->key->conf; | 380 | info->control.hw_key = &tx->key->conf; |
@@ -397,7 +409,7 @@ static int ccmp_encrypt_skb(struct ieee80211_tx_data *tx, struct sk_buff *skb) | |||
397 | 409 | ||
398 | ccmp_pn2hdr(pos, pn, key->conf.keyidx); | 410 | ccmp_pn2hdr(pos, pn, key->conf.keyidx); |
399 | 411 | ||
400 | if (key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE) { | 412 | if ((key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE) && !skip_hw) { |
401 | /* hwaccel - with preallocated room for CCMP header */ | 413 | /* hwaccel - with preallocated room for CCMP header */ |
402 | info->control.hw_key = &tx->key->conf; | 414 | info->control.hw_key = &tx->key->conf; |
403 | return 0; | 415 | return 0; |
@@ -446,7 +458,8 @@ ieee80211_crypto_ccmp_decrypt(struct ieee80211_rx_data *rx) | |||
446 | 458 | ||
447 | hdrlen = ieee80211_hdrlen(hdr->frame_control); | 459 | hdrlen = ieee80211_hdrlen(hdr->frame_control); |
448 | 460 | ||
449 | if (!ieee80211_is_data(hdr->frame_control)) | 461 | if (!ieee80211_is_data(hdr->frame_control) && |
462 | !ieee80211_is_robust_mgmt_frame(hdr)) | ||
450 | return RX_CONTINUE; | 463 | return RX_CONTINUE; |
451 | 464 | ||
452 | data_len = skb->len - hdrlen - CCMP_HDR_LEN - CCMP_MIC_LEN; | 465 | data_len = skb->len - hdrlen - CCMP_HDR_LEN - CCMP_MIC_LEN; |
@@ -485,3 +498,126 @@ ieee80211_crypto_ccmp_decrypt(struct ieee80211_rx_data *rx) | |||
485 | 498 | ||
486 | return RX_CONTINUE; | 499 | return RX_CONTINUE; |
487 | } | 500 | } |
501 | |||
502 | |||
503 | static void bip_aad(struct sk_buff *skb, u8 *aad) | ||
504 | { | ||
505 | /* BIP AAD: FC(masked) || A1 || A2 || A3 */ | ||
506 | |||
507 | /* FC type/subtype */ | ||
508 | aad[0] = skb->data[0]; | ||
509 | /* Mask FC Retry, PwrMgt, MoreData flags to zero */ | ||
510 | aad[1] = skb->data[1] & ~(BIT(4) | BIT(5) | BIT(6)); | ||
511 | /* A1 || A2 || A3 */ | ||
512 | memcpy(aad + 2, skb->data + 4, 3 * ETH_ALEN); | ||
513 | } | ||
514 | |||
515 | |||
516 | static inline void bip_ipn_swap(u8 *d, const u8 *s) | ||
517 | { | ||
518 | *d++ = s[5]; | ||
519 | *d++ = s[4]; | ||
520 | *d++ = s[3]; | ||
521 | *d++ = s[2]; | ||
522 | *d++ = s[1]; | ||
523 | *d = s[0]; | ||
524 | } | ||
525 | |||
526 | |||
527 | ieee80211_tx_result | ||
528 | ieee80211_crypto_aes_cmac_encrypt(struct ieee80211_tx_data *tx) | ||
529 | { | ||
530 | struct sk_buff *skb = tx->skb; | ||
531 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); | ||
532 | struct ieee80211_key *key = tx->key; | ||
533 | struct ieee80211_mmie *mmie; | ||
534 | u8 *pn, aad[20]; | ||
535 | int i; | ||
536 | |||
537 | if (tx->key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE) { | ||
538 | /* hwaccel */ | ||
539 | info->control.hw_key = &tx->key->conf; | ||
540 | return 0; | ||
541 | } | ||
542 | |||
543 | if (WARN_ON(skb_tailroom(skb) < sizeof(*mmie))) | ||
544 | return TX_DROP; | ||
545 | |||
546 | mmie = (struct ieee80211_mmie *) skb_put(skb, sizeof(*mmie)); | ||
547 | mmie->element_id = WLAN_EID_MMIE; | ||
548 | mmie->length = sizeof(*mmie) - 2; | ||
549 | mmie->key_id = cpu_to_le16(key->conf.keyidx); | ||
550 | |||
551 | /* PN = PN + 1 */ | ||
552 | pn = key->u.aes_cmac.tx_pn; | ||
553 | |||
554 | for (i = sizeof(key->u.aes_cmac.tx_pn) - 1; i >= 0; i--) { | ||
555 | pn[i]++; | ||
556 | if (pn[i]) | ||
557 | break; | ||
558 | } | ||
559 | bip_ipn_swap(mmie->sequence_number, pn); | ||
560 | |||
561 | bip_aad(skb, aad); | ||
562 | |||
563 | /* | ||
564 | * MIC = AES-128-CMAC(IGTK, AAD || Management Frame Body || MMIE, 64) | ||
565 | */ | ||
566 | ieee80211_aes_cmac(key->u.aes_cmac.tfm, key->u.aes_cmac.tx_crypto_buf, | ||
567 | aad, skb->data + 24, skb->len - 24, mmie->mic); | ||
568 | |||
569 | return TX_CONTINUE; | ||
570 | } | ||
571 | |||
572 | |||
573 | ieee80211_rx_result | ||
574 | ieee80211_crypto_aes_cmac_decrypt(struct ieee80211_rx_data *rx) | ||
575 | { | ||
576 | struct sk_buff *skb = rx->skb; | ||
577 | struct ieee80211_key *key = rx->key; | ||
578 | struct ieee80211_mmie *mmie; | ||
579 | u8 aad[20], mic[8], ipn[6]; | ||
580 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data; | ||
581 | |||
582 | if (!ieee80211_is_mgmt(hdr->frame_control)) | ||
583 | return RX_CONTINUE; | ||
584 | |||
585 | if ((rx->status->flag & RX_FLAG_DECRYPTED) && | ||
586 | (rx->status->flag & RX_FLAG_IV_STRIPPED)) | ||
587 | return RX_CONTINUE; | ||
588 | |||
589 | if (skb->len < 24 + sizeof(*mmie)) | ||
590 | return RX_DROP_UNUSABLE; | ||
591 | |||
592 | mmie = (struct ieee80211_mmie *) | ||
593 | (skb->data + skb->len - sizeof(*mmie)); | ||
594 | if (mmie->element_id != WLAN_EID_MMIE || | ||
595 | mmie->length != sizeof(*mmie) - 2) | ||
596 | return RX_DROP_UNUSABLE; /* Invalid MMIE */ | ||
597 | |||
598 | bip_ipn_swap(ipn, mmie->sequence_number); | ||
599 | |||
600 | if (memcmp(ipn, key->u.aes_cmac.rx_pn, 6) <= 0) { | ||
601 | key->u.aes_cmac.replays++; | ||
602 | return RX_DROP_UNUSABLE; | ||
603 | } | ||
604 | |||
605 | if (!(rx->status->flag & RX_FLAG_DECRYPTED)) { | ||
606 | /* hardware didn't decrypt/verify MIC */ | ||
607 | bip_aad(skb, aad); | ||
608 | ieee80211_aes_cmac(key->u.aes_cmac.tfm, | ||
609 | key->u.aes_cmac.rx_crypto_buf, aad, | ||
610 | skb->data + 24, skb->len - 24, mic); | ||
611 | if (memcmp(mic, mmie->mic, sizeof(mmie->mic)) != 0) { | ||
612 | key->u.aes_cmac.icverrors++; | ||
613 | return RX_DROP_UNUSABLE; | ||
614 | } | ||
615 | } | ||
616 | |||
617 | memcpy(key->u.aes_cmac.rx_pn, ipn, 6); | ||
618 | |||
619 | /* Remove MMIE */ | ||
620 | skb_trim(skb, skb->len - sizeof(*mmie)); | ||
621 | |||
622 | return RX_CONTINUE; | ||
623 | } | ||