Skip to content

Commit ffd7891

Browse files
Luis R. Rodriguezlinvjw
Luis R. Rodriguez
authored andcommitted
mac80211: Let drivers have access to TKIP key offets for TX and RX MIC
Some drivers may want to to use the TKIP key offsets for TX and RX MIC so lets move this out. Lets also clear up a bit how this is used internally in mac80211. Signed-off-by: Luis R. Rodriguez <[email protected]> Signed-off-by: John W. Linville <[email protected]>
1 parent 61243d8 commit ffd7891

File tree

5 files changed

+41
-38
lines changed

5 files changed

+41
-38
lines changed

include/linux/nl80211.h

+4-1
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,10 @@ enum nl80211_attrs {
241241
NL80211_ATTR_MAX = __NL80211_ATTR_AFTER_LAST - 1
242242
};
243243

244-
#define NL80211_MAX_SUPP_RATES 32
244+
#define NL80211_MAX_SUPP_RATES 32
245+
#define NL80211_TKIP_DATA_OFFSET_ENCR_KEY 0
246+
#define NL80211_TKIP_DATA_OFFSET_TX_MIC_KEY 16
247+
#define NL80211_TKIP_DATA_OFFSET_RX_MIC_KEY 24
245248

246249
/**
247250
* enum nl80211_iftype - (virtual) interface types

include/net/mac80211.h

+6-1
Original file line numberDiff line numberDiff line change
@@ -595,7 +595,12 @@ enum ieee80211_key_flags {
595595
* @flags: key flags, see &enum ieee80211_key_flags.
596596
* @keyidx: the key index (0-3)
597597
* @keylen: key material length
598-
* @key: key material
598+
* @key: key material. For ALG_TKIP the key is encoded as a 256-bit (32 byte)
599+
* data block:
600+
* - Temporal Encryption Key (128 bits)
601+
* - Temporal Authenticator Tx MIC Key (64 bits)
602+
* - Temporal Authenticator Rx MIC Key (64 bits)
603+
*
599604
*/
600605
struct ieee80211_key_conf {
601606
enum ieee80211_key_alg alg;

net/mac80211/key.h

+12-25
Original file line numberDiff line numberDiff line change
@@ -16,31 +16,18 @@
1616
#include <linux/rcupdate.h>
1717
#include <net/mac80211.h>
1818

19-
/* ALG_TKIP
20-
* struct ieee80211_key::key is encoded as a 256-bit (32 byte) data block:
21-
* Temporal Encryption Key (128 bits)
22-
* Temporal Authenticator Tx MIC Key (64 bits)
23-
* Temporal Authenticator Rx MIC Key (64 bits)
24-
*/
25-
26-
#define WEP_IV_LEN 4
27-
#define WEP_ICV_LEN 4
28-
29-
#define ALG_TKIP_KEY_LEN 32
30-
/* Starting offsets for each key */
31-
#define ALG_TKIP_TEMP_ENCR_KEY 0
32-
#define ALG_TKIP_TEMP_AUTH_TX_MIC_KEY 16
33-
#define ALG_TKIP_TEMP_AUTH_RX_MIC_KEY 24
34-
#define TKIP_IV_LEN 8
35-
#define TKIP_ICV_LEN 4
36-
37-
#define ALG_CCMP_KEY_LEN 16
38-
#define CCMP_HDR_LEN 8
39-
#define CCMP_MIC_LEN 8
40-
#define CCMP_TK_LEN 16
41-
#define CCMP_PN_LEN 6
42-
43-
#define NUM_RX_DATA_QUEUES 17
19+
#define WEP_IV_LEN 4
20+
#define WEP_ICV_LEN 4
21+
#define ALG_TKIP_KEY_LEN 32
22+
#define ALG_CCMP_KEY_LEN 16
23+
#define CCMP_HDR_LEN 8
24+
#define CCMP_MIC_LEN 8
25+
#define CCMP_TK_LEN 16
26+
#define CCMP_PN_LEN 6
27+
#define TKIP_IV_LEN 8
28+
#define TKIP_ICV_LEN 4
29+
30+
#define NUM_RX_DATA_QUEUES 17
4431

4532
struct ieee80211_local;
4633
struct ieee80211_sub_if_data;

net/mac80211/tkip.c

+5-5
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ void ieee80211_get_tkip_key(struct ieee80211_key_conf *keyconf,
164164
iv16 = data[2] | (data[0] << 8);
165165
iv32 = get_unaligned_le32(&data[4]);
166166

167-
tk = &key->conf.key[ALG_TKIP_TEMP_ENCR_KEY];
167+
tk = &key->conf.key[NL80211_TKIP_DATA_OFFSET_ENCR_KEY];
168168
ctx = &key->u.tkip.tx;
169169

170170
#ifdef CONFIG_MAC80211_TKIP_DEBUG
@@ -205,7 +205,7 @@ void ieee80211_tkip_encrypt_data(struct crypto_blkcipher *tfm,
205205
{
206206
u8 rc4key[16];
207207
struct tkip_ctx *ctx = &key->u.tkip.tx;
208-
const u8 *tk = &key->conf.key[ALG_TKIP_TEMP_ENCR_KEY];
208+
const u8 *tk = &key->conf.key[NL80211_TKIP_DATA_OFFSET_ENCR_KEY];
209209

210210
/* Calculate per-packet key */
211211
if (ctx->iv16 == 0 || !ctx->initialized)
@@ -231,7 +231,7 @@ int ieee80211_tkip_decrypt_data(struct crypto_blkcipher *tfm,
231231
u32 iv16;
232232
u8 rc4key[16], keyid, *pos = payload;
233233
int res;
234-
const u8 *tk = &key->conf.key[ALG_TKIP_TEMP_ENCR_KEY];
234+
const u8 *tk = &key->conf.key[NL80211_TKIP_DATA_OFFSET_ENCR_KEY];
235235

236236
if (payload_len < 12)
237237
return -1;
@@ -286,13 +286,13 @@ int ieee80211_tkip_decrypt_data(struct crypto_blkcipher *tfm,
286286
#ifdef CONFIG_MAC80211_TKIP_DEBUG
287287
{
288288
int i;
289+
u8 key_offset = NL80211_TKIP_DATA_OFFSET_ENCR_KEY;
289290
DECLARE_MAC_BUF(mac);
290291
printk(KERN_DEBUG "TKIP decrypt: Phase1 TA=%s"
291292
" TK=", print_mac(mac, ta));
292293
for (i = 0; i < 16; i++)
293294
printk("%02x ",
294-
key->conf.key[
295-
ALG_TKIP_TEMP_ENCR_KEY + i]);
295+
key->conf.key[key_offset + i]);
296296
printk("\n");
297297
printk(KERN_DEBUG "TKIP decrypt: P1K=");
298298
for (i = 0; i < 5; i++)

net/mac80211/wpa.c

+14-6
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ static int ieee80211_get_hdr_info(const struct sk_buff *skb, u8 **sa, u8 **da,
4949
ieee80211_tx_result
5050
ieee80211_tx_h_michael_mic_add(struct ieee80211_tx_data *tx)
5151
{
52-
u8 *data, *sa, *da, *key, *mic, qos_tid;
52+
u8 *data, *sa, *da, *key, *mic, qos_tid, key_offset;
5353
size_t data_len;
5454
u16 fc;
5555
struct sk_buff *skb = tx->skb;
@@ -88,8 +88,12 @@ ieee80211_tx_h_michael_mic_add(struct ieee80211_tx_data *tx)
8888
#else
8989
authenticator = 1;
9090
#endif
91-
key = &tx->key->conf.key[authenticator ? ALG_TKIP_TEMP_AUTH_TX_MIC_KEY :
92-
ALG_TKIP_TEMP_AUTH_RX_MIC_KEY];
91+
/* At this point we know we're using ALG_TKIP. To get the MIC key
92+
* we now will rely on the offset from the ieee80211_key_conf::key */
93+
key_offset = authenticator ?
94+
NL80211_TKIP_DATA_OFFSET_TX_MIC_KEY :
95+
NL80211_TKIP_DATA_OFFSET_RX_MIC_KEY;
96+
key = &tx->key->conf.key[key_offset];
9397
mic = skb_put(skb, MICHAEL_MIC_LEN);
9498
michael_mic(key, da, sa, qos_tid & 0x0f, data, data_len, mic);
9599

@@ -100,7 +104,7 @@ ieee80211_tx_h_michael_mic_add(struct ieee80211_tx_data *tx)
100104
ieee80211_rx_result
101105
ieee80211_rx_h_michael_mic_verify(struct ieee80211_rx_data *rx)
102106
{
103-
u8 *data, *sa, *da, *key = NULL, qos_tid;
107+
u8 *data, *sa, *da, *key = NULL, qos_tid, key_offset;
104108
size_t data_len;
105109
u16 fc;
106110
u8 mic[MICHAEL_MIC_LEN];
@@ -131,8 +135,12 @@ ieee80211_rx_h_michael_mic_verify(struct ieee80211_rx_data *rx)
131135
#else
132136
authenticator = 1;
133137
#endif
134-
key = &rx->key->conf.key[authenticator ? ALG_TKIP_TEMP_AUTH_RX_MIC_KEY :
135-
ALG_TKIP_TEMP_AUTH_TX_MIC_KEY];
138+
/* At this point we know we're using ALG_TKIP. To get the MIC key
139+
* we now will rely on the offset from the ieee80211_key_conf::key */
140+
key_offset = authenticator ?
141+
NL80211_TKIP_DATA_OFFSET_RX_MIC_KEY :
142+
NL80211_TKIP_DATA_OFFSET_TX_MIC_KEY;
143+
key = &rx->key->conf.key[key_offset];
136144
michael_mic(key, da, sa, qos_tid & 0x0f, data, data_len, mic);
137145
if (memcmp(mic, data + data_len, MICHAEL_MIC_LEN) != 0 || wpa_test) {
138146
if (!(rx->flags & IEEE80211_RX_RA_MATCH))

0 commit comments

Comments
 (0)