Lines Matching +full:mic +full:- +full:pos

1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright 2002-2004, Instant802 Networks, Inc.
5 * Copyright (C) 2016-2017 Intel Deutschland GmbH
6 * Copyright (C) 2020-2022 Intel Corporation
32 u8 *data, *key, *mic; in ieee80211_tx_h_michael_mic_add() local
36 struct sk_buff *skb = tx->skb; in ieee80211_tx_h_michael_mic_add()
40 hdr = (struct ieee80211_hdr *)skb->data; in ieee80211_tx_h_michael_mic_add()
41 if (!tx->key || tx->key->conf.cipher != WLAN_CIPHER_SUITE_TKIP || in ieee80211_tx_h_michael_mic_add()
42 skb->len < 24 || !ieee80211_is_data_present(hdr->frame_control)) in ieee80211_tx_h_michael_mic_add()
45 hdrlen = ieee80211_hdrlen(hdr->frame_control); in ieee80211_tx_h_michael_mic_add()
46 if (skb->len < hdrlen) in ieee80211_tx_h_michael_mic_add()
49 data = skb->data + hdrlen; in ieee80211_tx_h_michael_mic_add()
50 data_len = skb->len - hdrlen; in ieee80211_tx_h_michael_mic_add()
52 if (unlikely(info->flags & IEEE80211_TX_INTFL_TKIP_MIC_FAILURE)) { in ieee80211_tx_h_michael_mic_add()
54 info->control.hw_key = NULL; in ieee80211_tx_h_michael_mic_add()
57 if (info->control.hw_key && in ieee80211_tx_h_michael_mic_add()
58 (info->flags & IEEE80211_TX_CTL_DONTFRAG || in ieee80211_tx_h_michael_mic_add()
59 ieee80211_hw_check(&tx->local->hw, SUPPORTS_TX_FRAG)) && in ieee80211_tx_h_michael_mic_add()
60 !(tx->key->conf.flags & (IEEE80211_KEY_FLAG_GENERATE_MMIC | in ieee80211_tx_h_michael_mic_add()
62 /* hwaccel - with no need for SW-generated MMIC or MIC space */ in ieee80211_tx_h_michael_mic_add()
67 if (!info->control.hw_key) in ieee80211_tx_h_michael_mic_add()
77 mic = skb_put(skb, MICHAEL_MIC_LEN); in ieee80211_tx_h_michael_mic_add()
79 if (tx->key->conf.flags & IEEE80211_KEY_FLAG_PUT_MIC_SPACE) { in ieee80211_tx_h_michael_mic_add()
80 /* Zeroed MIC can help with debug */ in ieee80211_tx_h_michael_mic_add()
81 memset(mic, 0, MICHAEL_MIC_LEN); in ieee80211_tx_h_michael_mic_add()
85 key = &tx->key->conf.key[NL80211_TKIP_DATA_OFFSET_TX_MIC_KEY]; in ieee80211_tx_h_michael_mic_add()
86 michael_mic(key, hdr, data, data_len, mic); in ieee80211_tx_h_michael_mic_add()
87 if (unlikely(info->flags & IEEE80211_TX_INTFL_TKIP_MIC_FAILURE)) in ieee80211_tx_h_michael_mic_add()
88 mic[0]++; in ieee80211_tx_h_michael_mic_add()
100 u8 mic[MICHAEL_MIC_LEN]; in ieee80211_rx_h_michael_mic_verify() local
101 struct sk_buff *skb = rx->skb; in ieee80211_rx_h_michael_mic_verify()
103 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; in ieee80211_rx_h_michael_mic_verify()
106 * it makes no sense to check for MIC errors on anything other in ieee80211_rx_h_michael_mic_verify()
109 if (!ieee80211_is_data_present(hdr->frame_control)) in ieee80211_rx_h_michael_mic_verify()
113 * No way to verify the MIC if the hardware stripped it or in ieee80211_rx_h_michael_mic_verify()
116 * MIC failure report. in ieee80211_rx_h_michael_mic_verify()
118 if (status->flag & (RX_FLAG_MMIC_STRIPPED | RX_FLAG_IV_STRIPPED)) { in ieee80211_rx_h_michael_mic_verify()
119 if (status->flag & RX_FLAG_MMIC_ERROR) in ieee80211_rx_h_michael_mic_verify()
122 if (!(status->flag & RX_FLAG_IV_STRIPPED) && rx->key && in ieee80211_rx_h_michael_mic_verify()
123 rx->key->conf.cipher == WLAN_CIPHER_SUITE_TKIP) in ieee80211_rx_h_michael_mic_verify()
130 * Some hardware seems to generate Michael MIC failure reports; even in ieee80211_rx_h_michael_mic_verify()
132 * MIC. Ignore the flag them to avoid triggering countermeasures. in ieee80211_rx_h_michael_mic_verify()
134 if (!rx->key || rx->key->conf.cipher != WLAN_CIPHER_SUITE_TKIP || in ieee80211_rx_h_michael_mic_verify()
135 !(status->flag & RX_FLAG_DECRYPTED)) in ieee80211_rx_h_michael_mic_verify()
138 if (rx->sdata->vif.type == NL80211_IFTYPE_AP && rx->key->conf.keyidx) { in ieee80211_rx_h_michael_mic_verify()
140 * APs with pairwise keys should never receive Michael MIC in ieee80211_rx_h_michael_mic_verify()
141 * errors for non-zero keyidx because these are reserved for in ieee80211_rx_h_michael_mic_verify()
148 if (status->flag & RX_FLAG_MMIC_ERROR) in ieee80211_rx_h_michael_mic_verify()
151 hdrlen = ieee80211_hdrlen(hdr->frame_control); in ieee80211_rx_h_michael_mic_verify()
152 if (skb->len < hdrlen + MICHAEL_MIC_LEN) in ieee80211_rx_h_michael_mic_verify()
155 if (skb_linearize(rx->skb)) in ieee80211_rx_h_michael_mic_verify()
157 hdr = (void *)skb->data; in ieee80211_rx_h_michael_mic_verify()
159 data = skb->data + hdrlen; in ieee80211_rx_h_michael_mic_verify()
160 data_len = skb->len - hdrlen - MICHAEL_MIC_LEN; in ieee80211_rx_h_michael_mic_verify()
161 key = &rx->key->conf.key[NL80211_TKIP_DATA_OFFSET_RX_MIC_KEY]; in ieee80211_rx_h_michael_mic_verify()
162 michael_mic(key, hdr, data, data_len, mic); in ieee80211_rx_h_michael_mic_verify()
163 if (crypto_memneq(mic, data + data_len, MICHAEL_MIC_LEN)) in ieee80211_rx_h_michael_mic_verify()
166 /* remove Michael MIC from payload */ in ieee80211_rx_h_michael_mic_verify()
167 skb_trim(skb, skb->len - MICHAEL_MIC_LEN); in ieee80211_rx_h_michael_mic_verify()
171 rx->key->u.tkip.rx[rx->security_idx].iv32 = rx->tkip.iv32; in ieee80211_rx_h_michael_mic_verify()
172 rx->key->u.tkip.rx[rx->security_idx].iv16 = rx->tkip.iv16; in ieee80211_rx_h_michael_mic_verify()
177 rx->key->u.tkip.mic_failures++; in ieee80211_rx_h_michael_mic_verify()
181 * In some cases the key can be unset - e.g. a multicast packet, in in ieee80211_rx_h_michael_mic_verify()
185 cfg80211_michael_mic_failure(rx->sdata->dev, hdr->addr2, in ieee80211_rx_h_michael_mic_verify()
186 is_multicast_ether_addr(hdr->addr1) ? in ieee80211_rx_h_michael_mic_verify()
189 rx->key ? rx->key->conf.keyidx : -1, in ieee80211_rx_h_michael_mic_verify()
196 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data; in tkip_encrypt_skb()
197 struct ieee80211_key *key = tx->key; in tkip_encrypt_skb()
202 u8 *pos; in tkip_encrypt_skb() local
204 if (info->control.hw_key && in tkip_encrypt_skb()
205 !(info->control.hw_key->flags & IEEE80211_KEY_FLAG_GENERATE_IV) && in tkip_encrypt_skb()
206 !(info->control.hw_key->flags & IEEE80211_KEY_FLAG_PUT_IV_SPACE)) { in tkip_encrypt_skb()
207 /* hwaccel - with no need for software-generated IV */ in tkip_encrypt_skb()
211 hdrlen = ieee80211_hdrlen(hdr->frame_control); in tkip_encrypt_skb()
212 len = skb->len - hdrlen; in tkip_encrypt_skb()
214 if (info->control.hw_key) in tkip_encrypt_skb()
221 return -1; in tkip_encrypt_skb()
223 pos = skb_push(skb, IEEE80211_TKIP_IV_LEN); in tkip_encrypt_skb()
224 memmove(pos, pos + IEEE80211_TKIP_IV_LEN, hdrlen); in tkip_encrypt_skb()
225 pos += hdrlen; in tkip_encrypt_skb()
228 if (info->control.hw_key && in tkip_encrypt_skb()
229 (info->control.hw_key->flags & IEEE80211_KEY_FLAG_PUT_IV_SPACE)) in tkip_encrypt_skb()
233 pn = atomic64_inc_return(&key->conf.tx_pn); in tkip_encrypt_skb()
234 pos = ieee80211_tkip_add_iv(pos, &key->conf, pn); in tkip_encrypt_skb()
236 /* hwaccel - with software IV */ in tkip_encrypt_skb()
237 if (info->control.hw_key) in tkip_encrypt_skb()
243 return ieee80211_tkip_encrypt_data(&tx->local->wep_tx_ctx, in tkip_encrypt_skb()
244 key, skb, pos, len); in tkip_encrypt_skb()
255 skb_queue_walk(&tx->skbs, skb) { in ieee80211_crypto_tkip_encrypt()
267 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) rx->skb->data; in ieee80211_crypto_tkip_decrypt()
269 struct ieee80211_key *key = rx->key; in ieee80211_crypto_tkip_decrypt()
270 struct sk_buff *skb = rx->skb; in ieee80211_crypto_tkip_decrypt()
273 hdrlen = ieee80211_hdrlen(hdr->frame_control); in ieee80211_crypto_tkip_decrypt()
275 if (!ieee80211_is_data(hdr->frame_control)) in ieee80211_crypto_tkip_decrypt()
278 if (!rx->sta || skb->len - hdrlen < 12) in ieee80211_crypto_tkip_decrypt()
282 if (skb_linearize(rx->skb)) in ieee80211_crypto_tkip_decrypt()
284 hdr = (void *)skb->data; in ieee80211_crypto_tkip_decrypt()
291 if (status->flag & RX_FLAG_DECRYPTED) in ieee80211_crypto_tkip_decrypt()
294 res = ieee80211_tkip_decrypt_data(&rx->local->wep_rx_ctx, in ieee80211_crypto_tkip_decrypt()
295 key, skb->data + hdrlen, in ieee80211_crypto_tkip_decrypt()
296 skb->len - hdrlen, rx->sta->sta.addr, in ieee80211_crypto_tkip_decrypt()
297 hdr->addr1, hwaccel, rx->security_idx, in ieee80211_crypto_tkip_decrypt()
298 &rx->tkip.iv32, in ieee80211_crypto_tkip_decrypt()
299 &rx->tkip.iv16); in ieee80211_crypto_tkip_decrypt()
304 if (!(status->flag & RX_FLAG_ICV_STRIPPED)) in ieee80211_crypto_tkip_decrypt()
305 skb_trim(skb, skb->len - IEEE80211_TKIP_ICV_LEN); in ieee80211_crypto_tkip_decrypt()
308 memmove(skb->data + IEEE80211_TKIP_IV_LEN, skb->data, hdrlen); in ieee80211_crypto_tkip_decrypt()
320 struct ieee80211_hdr *hdr = (void *)skb->data; in ccmp_gcmp_aad()
330 mgmt = ieee80211_is_mgmt(hdr->frame_control); in ccmp_gcmp_aad()
331 mask_fc = hdr->frame_control; in ccmp_gcmp_aad()
338 a4_included = ieee80211_has_a4(hdr->frame_control); in ccmp_gcmp_aad()
342 if (ieee80211_is_data_qos(hdr->frame_control)) { in ccmp_gcmp_aad()
350 /* AAD (extra authenticate-only data) / masked 802.11 header in ccmp_gcmp_aad()
354 memcpy(&aad[4], &hdr->addrs, 3 * ETH_ALEN); in ccmp_gcmp_aad()
357 aad[22] = *((u8 *) &hdr->seq_ctrl) & 0x0f; in ccmp_gcmp_aad()
361 memcpy(&aad[24], hdr->addr4, ETH_ALEN); in ccmp_gcmp_aad()
374 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; in ccmp_special_blocks()
389 b_0[1] = qos_tid | (ieee80211_is_mgmt(hdr->frame_control) << 4); in ccmp_special_blocks()
390 memcpy(&b_0[2], hdr->addr2, ETH_ALEN); in ccmp_special_blocks()
421 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data; in ccmp_encrypt_skb()
422 struct ieee80211_key *key = tx->key; in ccmp_encrypt_skb()
425 u8 *pos; in ccmp_encrypt_skb() local
431 if (info->control.hw_key && in ccmp_encrypt_skb()
432 !(info->control.hw_key->flags & IEEE80211_KEY_FLAG_GENERATE_IV) && in ccmp_encrypt_skb()
433 !(info->control.hw_key->flags & IEEE80211_KEY_FLAG_PUT_IV_SPACE) && in ccmp_encrypt_skb()
434 !((info->control.hw_key->flags & in ccmp_encrypt_skb()
436 ieee80211_is_mgmt(hdr->frame_control))) { in ccmp_encrypt_skb()
439 * header or MIC fields in ccmp_encrypt_skb()
444 hdrlen = ieee80211_hdrlen(hdr->frame_control); in ccmp_encrypt_skb()
445 len = skb->len - hdrlen; in ccmp_encrypt_skb()
447 if (info->control.hw_key) in ccmp_encrypt_skb()
454 return -1; in ccmp_encrypt_skb()
456 pos = skb_push(skb, IEEE80211_CCMP_HDR_LEN); in ccmp_encrypt_skb()
457 memmove(pos, pos + IEEE80211_CCMP_HDR_LEN, hdrlen); in ccmp_encrypt_skb()
460 if (info->control.hw_key && in ccmp_encrypt_skb()
461 (info->control.hw_key->flags & IEEE80211_KEY_FLAG_PUT_IV_SPACE)) in ccmp_encrypt_skb()
464 pos += hdrlen; in ccmp_encrypt_skb()
466 pn64 = atomic64_inc_return(&key->conf.tx_pn); in ccmp_encrypt_skb()
475 ccmp_pn2hdr(pos, pn, key->conf.keyidx); in ccmp_encrypt_skb()
477 /* hwaccel - with software CCMP header */ in ccmp_encrypt_skb()
478 if (info->control.hw_key) in ccmp_encrypt_skb()
481 pos += IEEE80211_CCMP_HDR_LEN; in ccmp_encrypt_skb()
483 return ieee80211_aes_ccm_encrypt(key->u.ccmp.tfm, b_0, aad, pos, len, in ccmp_encrypt_skb()
496 skb_queue_walk(&tx->skbs, skb) { in ieee80211_crypto_ccmp_encrypt()
509 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data; in ieee80211_crypto_ccmp_decrypt()
511 struct ieee80211_key *key = rx->key; in ieee80211_crypto_ccmp_decrypt()
512 struct sk_buff *skb = rx->skb; in ieee80211_crypto_ccmp_decrypt()
518 hdrlen = ieee80211_hdrlen(hdr->frame_control); in ieee80211_crypto_ccmp_decrypt()
520 if (!ieee80211_is_data(hdr->frame_control) && in ieee80211_crypto_ccmp_decrypt()
524 if (status->flag & RX_FLAG_DECRYPTED) { in ieee80211_crypto_ccmp_decrypt()
525 if (!pskb_may_pull(rx->skb, hdrlen + IEEE80211_CCMP_HDR_LEN)) in ieee80211_crypto_ccmp_decrypt()
527 if (status->flag & RX_FLAG_MIC_STRIPPED) in ieee80211_crypto_ccmp_decrypt()
530 if (skb_linearize(rx->skb)) in ieee80211_crypto_ccmp_decrypt()
534 /* reload hdr - skb might have been reallocated */ in ieee80211_crypto_ccmp_decrypt()
535 hdr = (void *)rx->skb->data; in ieee80211_crypto_ccmp_decrypt()
537 data_len = skb->len - hdrlen - IEEE80211_CCMP_HDR_LEN - mic_len; in ieee80211_crypto_ccmp_decrypt()
538 if (!rx->sta || data_len < 0) in ieee80211_crypto_ccmp_decrypt()
541 if (!(status->flag & RX_FLAG_PN_VALIDATED)) { in ieee80211_crypto_ccmp_decrypt()
544 ccmp_hdr2pn(pn, skb->data + hdrlen); in ieee80211_crypto_ccmp_decrypt()
546 queue = rx->security_idx; in ieee80211_crypto_ccmp_decrypt()
548 res = memcmp(pn, key->u.ccmp.rx_pn[queue], in ieee80211_crypto_ccmp_decrypt()
551 (!res && !(status->flag & RX_FLAG_ALLOW_SAME_PN))) { in ieee80211_crypto_ccmp_decrypt()
552 key->u.ccmp.replays++; in ieee80211_crypto_ccmp_decrypt()
556 if (!(status->flag & RX_FLAG_DECRYPTED)) { in ieee80211_crypto_ccmp_decrypt()
559 /* hardware didn't decrypt/verify MIC */ in ieee80211_crypto_ccmp_decrypt()
563 key->u.ccmp.tfm, b_0, aad, in ieee80211_crypto_ccmp_decrypt()
564 skb->data + hdrlen + IEEE80211_CCMP_HDR_LEN, in ieee80211_crypto_ccmp_decrypt()
566 skb->data + skb->len - mic_len)) in ieee80211_crypto_ccmp_decrypt()
570 memcpy(key->u.ccmp.rx_pn[queue], pn, IEEE80211_CCMP_PN_LEN); in ieee80211_crypto_ccmp_decrypt()
572 memcpy(rx->ccm_gcm.pn, pn, IEEE80211_CCMP_PN_LEN); in ieee80211_crypto_ccmp_decrypt()
575 /* Remove CCMP header and MIC */ in ieee80211_crypto_ccmp_decrypt()
576 if (pskb_trim(skb, skb->len - mic_len)) in ieee80211_crypto_ccmp_decrypt()
578 memmove(skb->data + IEEE80211_CCMP_HDR_LEN, skb->data, hdrlen); in ieee80211_crypto_ccmp_decrypt()
586 struct ieee80211_hdr *hdr = (void *)skb->data; in gcmp_special_blocks()
588 memcpy(j_0, hdr->addr2, ETH_ALEN); in gcmp_special_blocks()
592 j_0[AES_BLOCK_SIZE - 1] = 0x01; in gcmp_special_blocks()
621 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; in gcmp_encrypt_skb()
622 struct ieee80211_key *key = tx->key; in gcmp_encrypt_skb()
625 u8 *pos; in gcmp_encrypt_skb() local
631 if (info->control.hw_key && in gcmp_encrypt_skb()
632 !(info->control.hw_key->flags & IEEE80211_KEY_FLAG_GENERATE_IV) && in gcmp_encrypt_skb()
633 !(info->control.hw_key->flags & IEEE80211_KEY_FLAG_PUT_IV_SPACE) && in gcmp_encrypt_skb()
634 !((info->control.hw_key->flags & in gcmp_encrypt_skb()
636 ieee80211_is_mgmt(hdr->frame_control))) { in gcmp_encrypt_skb()
638 * header or MIC fields in gcmp_encrypt_skb()
643 hdrlen = ieee80211_hdrlen(hdr->frame_control); in gcmp_encrypt_skb()
644 len = skb->len - hdrlen; in gcmp_encrypt_skb()
646 if (info->control.hw_key) in gcmp_encrypt_skb()
653 return -1; in gcmp_encrypt_skb()
655 pos = skb_push(skb, IEEE80211_GCMP_HDR_LEN); in gcmp_encrypt_skb()
656 memmove(pos, pos + IEEE80211_GCMP_HDR_LEN, hdrlen); in gcmp_encrypt_skb()
661 if (info->control.hw_key && in gcmp_encrypt_skb()
662 (info->control.hw_key->flags & IEEE80211_KEY_FLAG_PUT_IV_SPACE)) in gcmp_encrypt_skb()
665 pos += hdrlen; in gcmp_encrypt_skb()
667 pn64 = atomic64_inc_return(&key->conf.tx_pn); in gcmp_encrypt_skb()
676 gcmp_pn2hdr(pos, pn, key->conf.keyidx); in gcmp_encrypt_skb()
678 /* hwaccel - with software GCMP header */ in gcmp_encrypt_skb()
679 if (info->control.hw_key) in gcmp_encrypt_skb()
682 pos += IEEE80211_GCMP_HDR_LEN; in gcmp_encrypt_skb()
684 return ieee80211_aes_gcm_encrypt(key->u.gcmp.tfm, j_0, aad, pos, len, in gcmp_encrypt_skb()
695 skb_queue_walk(&tx->skbs, skb) { in ieee80211_crypto_gcmp_encrypt()
706 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data; in ieee80211_crypto_gcmp_decrypt()
708 struct ieee80211_key *key = rx->key; in ieee80211_crypto_gcmp_decrypt()
709 struct sk_buff *skb = rx->skb; in ieee80211_crypto_gcmp_decrypt()
714 hdrlen = ieee80211_hdrlen(hdr->frame_control); in ieee80211_crypto_gcmp_decrypt()
716 if (!ieee80211_is_data(hdr->frame_control) && in ieee80211_crypto_gcmp_decrypt()
720 if (status->flag & RX_FLAG_DECRYPTED) { in ieee80211_crypto_gcmp_decrypt()
721 if (!pskb_may_pull(rx->skb, hdrlen + IEEE80211_GCMP_HDR_LEN)) in ieee80211_crypto_gcmp_decrypt()
723 if (status->flag & RX_FLAG_MIC_STRIPPED) in ieee80211_crypto_gcmp_decrypt()
726 if (skb_linearize(rx->skb)) in ieee80211_crypto_gcmp_decrypt()
730 /* reload hdr - skb might have been reallocated */ in ieee80211_crypto_gcmp_decrypt()
731 hdr = (void *)rx->skb->data; in ieee80211_crypto_gcmp_decrypt()
733 data_len = skb->len - hdrlen - IEEE80211_GCMP_HDR_LEN - mic_len; in ieee80211_crypto_gcmp_decrypt()
734 if (!rx->sta || data_len < 0) in ieee80211_crypto_gcmp_decrypt()
737 if (!(status->flag & RX_FLAG_PN_VALIDATED)) { in ieee80211_crypto_gcmp_decrypt()
740 gcmp_hdr2pn(pn, skb->data + hdrlen); in ieee80211_crypto_gcmp_decrypt()
742 queue = rx->security_idx; in ieee80211_crypto_gcmp_decrypt()
744 res = memcmp(pn, key->u.gcmp.rx_pn[queue], in ieee80211_crypto_gcmp_decrypt()
747 (!res && !(status->flag & RX_FLAG_ALLOW_SAME_PN))) { in ieee80211_crypto_gcmp_decrypt()
748 key->u.gcmp.replays++; in ieee80211_crypto_gcmp_decrypt()
752 if (!(status->flag & RX_FLAG_DECRYPTED)) { in ieee80211_crypto_gcmp_decrypt()
755 /* hardware didn't decrypt/verify MIC */ in ieee80211_crypto_gcmp_decrypt()
759 key->u.gcmp.tfm, j_0, aad, in ieee80211_crypto_gcmp_decrypt()
760 skb->data + hdrlen + IEEE80211_GCMP_HDR_LEN, in ieee80211_crypto_gcmp_decrypt()
762 skb->data + skb->len - in ieee80211_crypto_gcmp_decrypt()
767 memcpy(key->u.gcmp.rx_pn[queue], pn, IEEE80211_GCMP_PN_LEN); in ieee80211_crypto_gcmp_decrypt()
769 memcpy(rx->ccm_gcm.pn, pn, IEEE80211_CCMP_PN_LEN); in ieee80211_crypto_gcmp_decrypt()
772 /* Remove GCMP header and MIC */ in ieee80211_crypto_gcmp_decrypt()
773 if (pskb_trim(skb, skb->len - mic_len)) in ieee80211_crypto_gcmp_decrypt()
775 memmove(skb->data + IEEE80211_GCMP_HDR_LEN, skb->data, hdrlen); in ieee80211_crypto_gcmp_decrypt()
784 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data; in bip_aad()
790 mask_fc = hdr->frame_control; in bip_aad()
795 memcpy(aad + 2, &hdr->addrs, 3 * ETH_ALEN); in bip_aad()
825 struct ieee80211_key *key = tx->key; in ieee80211_crypto_aes_cmac_encrypt()
830 if (WARN_ON(skb_queue_len(&tx->skbs) != 1)) in ieee80211_crypto_aes_cmac_encrypt()
833 skb = skb_peek(&tx->skbs); in ieee80211_crypto_aes_cmac_encrypt()
837 if (info->control.hw_key && in ieee80211_crypto_aes_cmac_encrypt()
838 !(key->conf.flags & IEEE80211_KEY_FLAG_GENERATE_MMIE)) in ieee80211_crypto_aes_cmac_encrypt()
845 mmie->element_id = WLAN_EID_MMIE; in ieee80211_crypto_aes_cmac_encrypt()
846 mmie->length = sizeof(*mmie) - 2; in ieee80211_crypto_aes_cmac_encrypt()
847 mmie->key_id = cpu_to_le16(key->conf.keyidx); in ieee80211_crypto_aes_cmac_encrypt()
850 pn64 = atomic64_inc_return(&key->conf.tx_pn); in ieee80211_crypto_aes_cmac_encrypt()
852 bip_ipn_set64(mmie->sequence_number, pn64); in ieee80211_crypto_aes_cmac_encrypt()
854 if (info->control.hw_key) in ieee80211_crypto_aes_cmac_encrypt()
860 * MIC = AES-128-CMAC(IGTK, AAD || Management Frame Body || MMIE, 64) in ieee80211_crypto_aes_cmac_encrypt()
862 ieee80211_aes_cmac(key->u.aes_cmac.tfm, aad, in ieee80211_crypto_aes_cmac_encrypt()
863 skb->data + 24, skb->len - 24, mmie->mic); in ieee80211_crypto_aes_cmac_encrypt()
873 struct ieee80211_key *key = tx->key; in ieee80211_crypto_aes_cmac_256_encrypt()
878 if (WARN_ON(skb_queue_len(&tx->skbs) != 1)) in ieee80211_crypto_aes_cmac_256_encrypt()
881 skb = skb_peek(&tx->skbs); in ieee80211_crypto_aes_cmac_256_encrypt()
885 if (info->control.hw_key) in ieee80211_crypto_aes_cmac_256_encrypt()
892 mmie->element_id = WLAN_EID_MMIE; in ieee80211_crypto_aes_cmac_256_encrypt()
893 mmie->length = sizeof(*mmie) - 2; in ieee80211_crypto_aes_cmac_256_encrypt()
894 mmie->key_id = cpu_to_le16(key->conf.keyidx); in ieee80211_crypto_aes_cmac_256_encrypt()
897 pn64 = atomic64_inc_return(&key->conf.tx_pn); in ieee80211_crypto_aes_cmac_256_encrypt()
899 bip_ipn_set64(mmie->sequence_number, pn64); in ieee80211_crypto_aes_cmac_256_encrypt()
903 /* MIC = AES-256-CMAC(IGTK, AAD || Management Frame Body || MMIE, 128) in ieee80211_crypto_aes_cmac_256_encrypt()
905 ieee80211_aes_cmac_256(key->u.aes_cmac.tfm, aad, in ieee80211_crypto_aes_cmac_256_encrypt()
906 skb->data + 24, skb->len - 24, mmie->mic); in ieee80211_crypto_aes_cmac_256_encrypt()
914 struct sk_buff *skb = rx->skb; in ieee80211_crypto_aes_cmac_decrypt()
916 struct ieee80211_key *key = rx->key; in ieee80211_crypto_aes_cmac_decrypt()
918 u8 aad[20], mic[8], ipn[6]; in ieee80211_crypto_aes_cmac_decrypt() local
919 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data; in ieee80211_crypto_aes_cmac_decrypt()
921 if (!ieee80211_is_mgmt(hdr->frame_control)) in ieee80211_crypto_aes_cmac_decrypt()
926 if (skb->len < 24 + sizeof(*mmie)) in ieee80211_crypto_aes_cmac_decrypt()
930 (skb->data + skb->len - sizeof(*mmie)); in ieee80211_crypto_aes_cmac_decrypt()
931 if (mmie->element_id != WLAN_EID_MMIE || in ieee80211_crypto_aes_cmac_decrypt()
932 mmie->length != sizeof(*mmie) - 2) in ieee80211_crypto_aes_cmac_decrypt()
935 bip_ipn_swap(ipn, mmie->sequence_number); in ieee80211_crypto_aes_cmac_decrypt()
937 if (memcmp(ipn, key->u.aes_cmac.rx_pn, 6) <= 0) { in ieee80211_crypto_aes_cmac_decrypt()
938 key->u.aes_cmac.replays++; in ieee80211_crypto_aes_cmac_decrypt()
942 if (!(status->flag & RX_FLAG_DECRYPTED)) { in ieee80211_crypto_aes_cmac_decrypt()
943 /* hardware didn't decrypt/verify MIC */ in ieee80211_crypto_aes_cmac_decrypt()
945 ieee80211_aes_cmac(key->u.aes_cmac.tfm, aad, in ieee80211_crypto_aes_cmac_decrypt()
946 skb->data + 24, skb->len - 24, mic); in ieee80211_crypto_aes_cmac_decrypt()
947 if (crypto_memneq(mic, mmie->mic, sizeof(mmie->mic))) { in ieee80211_crypto_aes_cmac_decrypt()
948 key->u.aes_cmac.icverrors++; in ieee80211_crypto_aes_cmac_decrypt()
953 memcpy(key->u.aes_cmac.rx_pn, ipn, 6); in ieee80211_crypto_aes_cmac_decrypt()
956 skb_trim(skb, skb->len - sizeof(*mmie)); in ieee80211_crypto_aes_cmac_decrypt()
964 struct sk_buff *skb = rx->skb; in ieee80211_crypto_aes_cmac_256_decrypt()
966 struct ieee80211_key *key = rx->key; in ieee80211_crypto_aes_cmac_256_decrypt()
968 u8 aad[20], mic[16], ipn[6]; in ieee80211_crypto_aes_cmac_256_decrypt() local
969 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; in ieee80211_crypto_aes_cmac_256_decrypt()
971 if (!ieee80211_is_mgmt(hdr->frame_control)) in ieee80211_crypto_aes_cmac_256_decrypt()
976 if (skb->len < 24 + sizeof(*mmie)) in ieee80211_crypto_aes_cmac_256_decrypt()
980 (skb->data + skb->len - sizeof(*mmie)); in ieee80211_crypto_aes_cmac_256_decrypt()
981 if (mmie->element_id != WLAN_EID_MMIE || in ieee80211_crypto_aes_cmac_256_decrypt()
982 mmie->length != sizeof(*mmie) - 2) in ieee80211_crypto_aes_cmac_256_decrypt()
985 bip_ipn_swap(ipn, mmie->sequence_number); in ieee80211_crypto_aes_cmac_256_decrypt()
987 if (memcmp(ipn, key->u.aes_cmac.rx_pn, 6) <= 0) { in ieee80211_crypto_aes_cmac_256_decrypt()
988 key->u.aes_cmac.replays++; in ieee80211_crypto_aes_cmac_256_decrypt()
992 if (!(status->flag & RX_FLAG_DECRYPTED)) { in ieee80211_crypto_aes_cmac_256_decrypt()
993 /* hardware didn't decrypt/verify MIC */ in ieee80211_crypto_aes_cmac_256_decrypt()
995 ieee80211_aes_cmac_256(key->u.aes_cmac.tfm, aad, in ieee80211_crypto_aes_cmac_256_decrypt()
996 skb->data + 24, skb->len - 24, mic); in ieee80211_crypto_aes_cmac_256_decrypt()
997 if (crypto_memneq(mic, mmie->mic, sizeof(mmie->mic))) { in ieee80211_crypto_aes_cmac_256_decrypt()
998 key->u.aes_cmac.icverrors++; in ieee80211_crypto_aes_cmac_256_decrypt()
1003 memcpy(key->u.aes_cmac.rx_pn, ipn, 6); in ieee80211_crypto_aes_cmac_256_decrypt()
1006 skb_trim(skb, skb->len - sizeof(*mmie)); in ieee80211_crypto_aes_cmac_256_decrypt()
1016 struct ieee80211_key *key = tx->key; in ieee80211_crypto_aes_gmac_encrypt()
1023 if (WARN_ON(skb_queue_len(&tx->skbs) != 1)) in ieee80211_crypto_aes_gmac_encrypt()
1026 skb = skb_peek(&tx->skbs); in ieee80211_crypto_aes_gmac_encrypt()
1030 if (info->control.hw_key) in ieee80211_crypto_aes_gmac_encrypt()
1037 mmie->element_id = WLAN_EID_MMIE; in ieee80211_crypto_aes_gmac_encrypt()
1038 mmie->length = sizeof(*mmie) - 2; in ieee80211_crypto_aes_gmac_encrypt()
1039 mmie->key_id = cpu_to_le16(key->conf.keyidx); in ieee80211_crypto_aes_gmac_encrypt()
1042 pn64 = atomic64_inc_return(&key->conf.tx_pn); in ieee80211_crypto_aes_gmac_encrypt()
1044 bip_ipn_set64(mmie->sequence_number, pn64); in ieee80211_crypto_aes_gmac_encrypt()
1048 hdr = (struct ieee80211_hdr *)skb->data; in ieee80211_crypto_aes_gmac_encrypt()
1049 memcpy(nonce, hdr->addr2, ETH_ALEN); in ieee80211_crypto_aes_gmac_encrypt()
1050 bip_ipn_swap(nonce + ETH_ALEN, mmie->sequence_number); in ieee80211_crypto_aes_gmac_encrypt()
1052 /* MIC = AES-GMAC(IGTK, AAD || Management Frame Body || MMIE, 128) */ in ieee80211_crypto_aes_gmac_encrypt()
1053 if (ieee80211_aes_gmac(key->u.aes_gmac.tfm, aad, nonce, in ieee80211_crypto_aes_gmac_encrypt()
1054 skb->data + 24, skb->len - 24, mmie->mic) < 0) in ieee80211_crypto_aes_gmac_encrypt()
1063 struct sk_buff *skb = rx->skb; in ieee80211_crypto_aes_gmac_decrypt()
1065 struct ieee80211_key *key = rx->key; in ieee80211_crypto_aes_gmac_decrypt()
1067 u8 aad[GMAC_AAD_LEN], *mic, ipn[6], nonce[GMAC_NONCE_LEN]; in ieee80211_crypto_aes_gmac_decrypt() local
1068 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; in ieee80211_crypto_aes_gmac_decrypt()
1070 if (!ieee80211_is_mgmt(hdr->frame_control)) in ieee80211_crypto_aes_gmac_decrypt()
1075 if (skb->len < 24 + sizeof(*mmie)) in ieee80211_crypto_aes_gmac_decrypt()
1079 (skb->data + skb->len - sizeof(*mmie)); in ieee80211_crypto_aes_gmac_decrypt()
1080 if (mmie->element_id != WLAN_EID_MMIE || in ieee80211_crypto_aes_gmac_decrypt()
1081 mmie->length != sizeof(*mmie) - 2) in ieee80211_crypto_aes_gmac_decrypt()
1084 bip_ipn_swap(ipn, mmie->sequence_number); in ieee80211_crypto_aes_gmac_decrypt()
1086 if (memcmp(ipn, key->u.aes_gmac.rx_pn, 6) <= 0) { in ieee80211_crypto_aes_gmac_decrypt()
1087 key->u.aes_gmac.replays++; in ieee80211_crypto_aes_gmac_decrypt()
1091 if (!(status->flag & RX_FLAG_DECRYPTED)) { in ieee80211_crypto_aes_gmac_decrypt()
1092 /* hardware didn't decrypt/verify MIC */ in ieee80211_crypto_aes_gmac_decrypt()
1095 memcpy(nonce, hdr->addr2, ETH_ALEN); in ieee80211_crypto_aes_gmac_decrypt()
1098 mic = kmalloc(GMAC_MIC_LEN, GFP_ATOMIC); in ieee80211_crypto_aes_gmac_decrypt()
1099 if (!mic) in ieee80211_crypto_aes_gmac_decrypt()
1101 if (ieee80211_aes_gmac(key->u.aes_gmac.tfm, aad, nonce, in ieee80211_crypto_aes_gmac_decrypt()
1102 skb->data + 24, skb->len - 24, in ieee80211_crypto_aes_gmac_decrypt()
1103 mic) < 0 || in ieee80211_crypto_aes_gmac_decrypt()
1104 crypto_memneq(mic, mmie->mic, sizeof(mmie->mic))) { in ieee80211_crypto_aes_gmac_decrypt()
1105 key->u.aes_gmac.icverrors++; in ieee80211_crypto_aes_gmac_decrypt()
1106 kfree(mic); in ieee80211_crypto_aes_gmac_decrypt()
1109 kfree(mic); in ieee80211_crypto_aes_gmac_decrypt()
1112 memcpy(key->u.aes_gmac.rx_pn, ipn, 6); in ieee80211_crypto_aes_gmac_decrypt()
1115 skb_trim(skb, skb->len - sizeof(*mmie)); in ieee80211_crypto_aes_gmac_decrypt()