aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHarvey Harrison <harvey.harrison@gmail.com>2008-05-14 19:26:19 -0400
committerJohn W. Linville <linville@tuxdriver.com>2008-05-21 21:47:49 -0400
commitb0f76b335f8b1c324b4b2be06369d391b26a7cc9 (patch)
tree22ecaa2eb8ac0d6df3e35b4cecbca1de74ac63bc
parenta7b6f0c5558ad03281b8064d6a4ab2e124dea991 (diff)
mac80211: add a struct to hold tkip context
Signed-off-by: Harvey Harrison <harvey.harrison@gmail.com> Cc: "John W. Linville" <linville@tuxdriver.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: John W. Linville <linville@tuxdriver.com>
-rw-r--r--net/mac80211/cfg.c4
-rw-r--r--net/mac80211/debugfs_key.c8
-rw-r--r--net/mac80211/key.h17
-rw-r--r--net/mac80211/tkip.c54
-rw-r--r--net/mac80211/wpa.c16
5 files changed, 50 insertions, 49 deletions
diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c
index 3cef80dcd0e5..dbf0563c397d 100644
--- a/net/mac80211/cfg.c
+++ b/net/mac80211/cfg.c
@@ -256,8 +256,8 @@ static int ieee80211_get_key(struct wiphy *wiphy, struct net_device *dev,
256 case ALG_TKIP: 256 case ALG_TKIP:
257 params.cipher = WLAN_CIPHER_SUITE_TKIP; 257 params.cipher = WLAN_CIPHER_SUITE_TKIP;
258 258
259 iv32 = key->u.tkip.iv32; 259 iv32 = key->u.tkip.tx.iv32;
260 iv16 = key->u.tkip.iv16; 260 iv16 = key->u.tkip.tx.iv16;
261 261
262 if (key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE && 262 if (key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE &&
263 sdata->local->ops->get_tkip_seq) 263 sdata->local->ops->get_tkip_seq)
diff --git a/net/mac80211/debugfs_key.c b/net/mac80211/debugfs_key.c
index 19efc3a6a932..7439b63df5d0 100644
--- a/net/mac80211/debugfs_key.c
+++ b/net/mac80211/debugfs_key.c
@@ -97,8 +97,8 @@ static ssize_t key_tx_spec_read(struct file *file, char __user *userbuf,
97 break; 97 break;
98 case ALG_TKIP: 98 case ALG_TKIP:
99 len = scnprintf(buf, sizeof(buf), "%08x %04x\n", 99 len = scnprintf(buf, sizeof(buf), "%08x %04x\n",
100 key->u.tkip.iv32, 100 key->u.tkip.tx.iv32,
101 key->u.tkip.iv16); 101 key->u.tkip.tx.iv16);
102 break; 102 break;
103 case ALG_CCMP: 103 case ALG_CCMP:
104 tpn = key->u.ccmp.tx_pn; 104 tpn = key->u.ccmp.tx_pn;
@@ -128,8 +128,8 @@ static ssize_t key_rx_spec_read(struct file *file, char __user *userbuf,
128 for (i = 0; i < NUM_RX_DATA_QUEUES; i++) 128 for (i = 0; i < NUM_RX_DATA_QUEUES; i++)
129 p += scnprintf(p, sizeof(buf)+buf-p, 129 p += scnprintf(p, sizeof(buf)+buf-p,
130 "%08x %04x\n", 130 "%08x %04x\n",
131 key->u.tkip.iv32_rx[i], 131 key->u.tkip.rx[i].iv32,
132 key->u.tkip.iv16_rx[i]); 132 key->u.tkip.rx[i].iv16);
133 len = p - buf; 133 len = p - buf;
134 break; 134 break;
135 case ALG_CCMP: 135 case ALG_CCMP:
diff --git a/net/mac80211/key.h b/net/mac80211/key.h
index f52c3df1fe9a..a0f774aafa45 100644
--- a/net/mac80211/key.h
+++ b/net/mac80211/key.h
@@ -69,6 +69,13 @@ enum ieee80211_internal_key_flags {
69 KEY_FLAG_TODO_ADD_DEBUGFS = BIT(5), 69 KEY_FLAG_TODO_ADD_DEBUGFS = BIT(5),
70}; 70};
71 71
72struct tkip_ctx {
73 u32 iv32;
74 u16 iv16;
75 u16 p1k[5];
76 int initialized;
77};
78
72struct ieee80211_key { 79struct ieee80211_key {
73 struct ieee80211_local *local; 80 struct ieee80211_local *local;
74 struct ieee80211_sub_if_data *sdata; 81 struct ieee80211_sub_if_data *sdata;
@@ -85,16 +92,10 @@ struct ieee80211_key {
85 union { 92 union {
86 struct { 93 struct {
87 /* last used TSC */ 94 /* last used TSC */
88 u32 iv32; 95 struct tkip_ctx tx;
89 u16 iv16;
90 u16 p1k[5];
91 int tx_initialized;
92 96
93 /* last received RSC */ 97 /* last received RSC */
94 u32 iv32_rx[NUM_RX_DATA_QUEUES]; 98 struct tkip_ctx rx[NUM_RX_DATA_QUEUES];
95 u16 iv16_rx[NUM_RX_DATA_QUEUES];
96 u16 p1k_rx[NUM_RX_DATA_QUEUES][5];
97 int rx_initialized[NUM_RX_DATA_QUEUES];
98 } tkip; 99 } tkip;
99 struct { 100 struct {
100 u8 tx_pn[6]; 101 u8 tx_pn[6];
diff --git a/net/mac80211/tkip.c b/net/mac80211/tkip.c
index 8cdf053cb835..d74c91e23a7f 100644
--- a/net/mac80211/tkip.c
+++ b/net/mac80211/tkip.c
@@ -138,7 +138,7 @@ u8 *ieee80211_tkip_add_iv(u8 *pos, struct ieee80211_key *key,
138 *pos++ = iv1; 138 *pos++ = iv1;
139 *pos++ = iv2; 139 *pos++ = iv2;
140 *pos++ = (key->conf.keyidx << 6) | (1 << 5) /* Ext IV */; 140 *pos++ = (key->conf.keyidx << 6) | (1 << 5) /* Ext IV */;
141 put_unaligned_le32(key->u.tkip.iv32, pos); 141 put_unaligned_le32(key->u.tkip.tx.iv32, pos);
142 return pos + 4; 142 return pos + 4;
143} 143}
144 144
@@ -146,16 +146,16 @@ static void ieee80211_tkip_gen_rc4key(struct ieee80211_key *key, u8 *ta,
146 u8 *rc4key) 146 u8 *rc4key)
147{ 147{
148 /* Calculate per-packet key */ 148 /* Calculate per-packet key */
149 if (key->u.tkip.iv16 == 0 || !key->u.tkip.tx_initialized) { 149 if (key->u.tkip.tx.iv16 == 0 || !key->u.tkip.tx.initialized) {
150 /* IV16 wrapped around - perform TKIP phase 1 */ 150 /* IV16 wrapped around - perform TKIP phase 1 */
151 tkip_mixing_phase1(ta, &key->conf.key[ALG_TKIP_TEMP_ENCR_KEY], 151 tkip_mixing_phase1(ta, &key->conf.key[ALG_TKIP_TEMP_ENCR_KEY],
152 key->u.tkip.iv32, key->u.tkip.p1k); 152 key->u.tkip.tx.iv32, key->u.tkip.tx.p1k);
153 key->u.tkip.tx_initialized = 1; 153 key->u.tkip.tx.initialized = 1;
154 } 154 }
155 155
156 tkip_mixing_phase2(key->u.tkip.p1k, 156 tkip_mixing_phase2(key->u.tkip.tx.p1k,
157 &key->conf.key[ALG_TKIP_TEMP_ENCR_KEY], 157 &key->conf.key[ALG_TKIP_TEMP_ENCR_KEY],
158 key->u.tkip.iv16, rc4key); 158 key->u.tkip.tx.iv16, rc4key);
159} 159}
160 160
161void ieee80211_get_tkip_key(struct ieee80211_key_conf *keyconf, 161void ieee80211_get_tkip_key(struct ieee80211_key_conf *keyconf,
@@ -179,9 +179,9 @@ void ieee80211_get_tkip_key(struct ieee80211_key_conf *keyconf,
179 printk(KERN_DEBUG "TKIP encrypt: iv16 = 0x%04x, iv32 = 0x%08x\n", 179 printk(KERN_DEBUG "TKIP encrypt: iv16 = 0x%04x, iv32 = 0x%08x\n",
180 iv16, iv32); 180 iv16, iv32);
181 181
182 if (iv32 != key->u.tkip.iv32) { 182 if (iv32 != key->u.tkip.tx.iv32) {
183 printk(KERN_DEBUG "skb: iv32 = 0x%08x key: iv32 = 0x%08x\n", 183 printk(KERN_DEBUG "skb: iv32 = 0x%08x key: iv32 = 0x%08x\n",
184 iv32, key->u.tkip.iv32); 184 iv32, key->u.tkip.tx.iv32);
185 printk(KERN_DEBUG "Wrap around of iv16 in the middle of a " 185 printk(KERN_DEBUG "Wrap around of iv16 in the middle of a "
186 "fragmented packet\n"); 186 "fragmented packet\n");
187 } 187 }
@@ -190,19 +190,19 @@ void ieee80211_get_tkip_key(struct ieee80211_key_conf *keyconf,
190 /* Update the p1k only when the iv16 in the packet wraps around, this 190 /* Update the p1k only when the iv16 in the packet wraps around, this
191 * might occur after the wrap around of iv16 in the key in case of 191 * might occur after the wrap around of iv16 in the key in case of
192 * fragmented packets. */ 192 * fragmented packets. */
193 if (iv16 == 0 || !key->u.tkip.tx_initialized) { 193 if (iv16 == 0 || !key->u.tkip.tx.initialized) {
194 /* IV16 wrapped around - perform TKIP phase 1 */ 194 /* IV16 wrapped around - perform TKIP phase 1 */
195 tkip_mixing_phase1(ta, &key->conf.key[ALG_TKIP_TEMP_ENCR_KEY], 195 tkip_mixing_phase1(ta, &key->conf.key[ALG_TKIP_TEMP_ENCR_KEY],
196 iv32, key->u.tkip.p1k); 196 iv32, key->u.tkip.tx.p1k);
197 key->u.tkip.tx_initialized = 1; 197 key->u.tkip.tx.initialized = 1;
198 } 198 }
199 199
200 if (type == IEEE80211_TKIP_P1_KEY) { 200 if (type == IEEE80211_TKIP_P1_KEY) {
201 memcpy(outkey, key->u.tkip.p1k, sizeof(u16) * 5); 201 memcpy(outkey, key->u.tkip.tx.p1k, sizeof(u16) * 5);
202 return; 202 return;
203 } 203 }
204 204
205 tkip_mixing_phase2(key->u.tkip.p1k, 205 tkip_mixing_phase2(key->u.tkip.tx.p1k,
206 &key->conf.key[ALG_TKIP_TEMP_ENCR_KEY], iv16, outkey); 206 &key->conf.key[ALG_TKIP_TEMP_ENCR_KEY], iv16, outkey);
207} 207}
208EXPORT_SYMBOL(ieee80211_get_tkip_key); 208EXPORT_SYMBOL(ieee80211_get_tkip_key);
@@ -263,33 +263,33 @@ int ieee80211_tkip_decrypt_data(struct crypto_blkcipher *tfm,
263 if ((keyid >> 6) != key->conf.keyidx) 263 if ((keyid >> 6) != key->conf.keyidx)
264 return TKIP_DECRYPT_INVALID_KEYIDX; 264 return TKIP_DECRYPT_INVALID_KEYIDX;
265 265
266 if (key->u.tkip.rx_initialized[queue] && 266 if (key->u.tkip.rx[queue].initialized &&
267 (iv32 < key->u.tkip.iv32_rx[queue] || 267 (iv32 < key->u.tkip.rx[queue].iv32 ||
268 (iv32 == key->u.tkip.iv32_rx[queue] && 268 (iv32 == key->u.tkip.rx[queue].iv32 &&
269 iv16 <= key->u.tkip.iv16_rx[queue]))) { 269 iv16 <= key->u.tkip.rx[queue].iv16))) {
270#ifdef CONFIG_TKIP_DEBUG 270#ifdef CONFIG_TKIP_DEBUG
271 DECLARE_MAC_BUF(mac); 271 DECLARE_MAC_BUF(mac);
272 printk(KERN_DEBUG "TKIP replay detected for RX frame from " 272 printk(KERN_DEBUG "TKIP replay detected for RX frame from "
273 "%s (RX IV (%04x,%02x) <= prev. IV (%04x,%02x)\n", 273 "%s (RX IV (%04x,%02x) <= prev. IV (%04x,%02x)\n",
274 print_mac(mac, ta), 274 print_mac(mac, ta),
275 iv32, iv16, key->u.tkip.iv32_rx[queue], 275 iv32, iv16, key->u.tkip.rx[queue].iv32,
276 key->u.tkip.iv16_rx[queue]); 276 key->u.tkip.rx[queue].iv16);
277#endif /* CONFIG_TKIP_DEBUG */ 277#endif /* CONFIG_TKIP_DEBUG */
278 return TKIP_DECRYPT_REPLAY; 278 return TKIP_DECRYPT_REPLAY;
279 } 279 }
280 280
281 if (only_iv) { 281 if (only_iv) {
282 res = TKIP_DECRYPT_OK; 282 res = TKIP_DECRYPT_OK;
283 key->u.tkip.rx_initialized[queue] = 1; 283 key->u.tkip.rx[queue].initialized = 1;
284 goto done; 284 goto done;
285 } 285 }
286 286
287 if (!key->u.tkip.rx_initialized[queue] || 287 if (!key->u.tkip.rx[queue].initialized ||
288 key->u.tkip.iv32_rx[queue] != iv32) { 288 key->u.tkip.rx[queue].iv32 != iv32) {
289 key->u.tkip.rx_initialized[queue] = 1; 289 key->u.tkip.rx[queue].initialized = 1;
290 /* IV16 wrapped around - perform TKIP phase 1 */ 290 /* IV16 wrapped around - perform TKIP phase 1 */
291 tkip_mixing_phase1(ta, &key->conf.key[ALG_TKIP_TEMP_ENCR_KEY], 291 tkip_mixing_phase1(ta, &key->conf.key[ALG_TKIP_TEMP_ENCR_KEY],
292 iv32, key->u.tkip.p1k_rx[queue]); 292 iv32, key->u.tkip.rx[queue].p1k);
293#ifdef CONFIG_TKIP_DEBUG 293#ifdef CONFIG_TKIP_DEBUG
294 { 294 {
295 int i; 295 int i;
@@ -303,7 +303,7 @@ int ieee80211_tkip_decrypt_data(struct crypto_blkcipher *tfm,
303 printk("\n"); 303 printk("\n");
304 printk(KERN_DEBUG "TKIP decrypt: P1K="); 304 printk(KERN_DEBUG "TKIP decrypt: P1K=");
305 for (i = 0; i < 5; i++) 305 for (i = 0; i < 5; i++)
306 printk("%04x ", key->u.tkip.p1k_rx[queue][i]); 306 printk("%04x ", key->u.tkip.rx[queue].p1k[i]);
307 printk("\n"); 307 printk("\n");
308 } 308 }
309#endif /* CONFIG_TKIP_DEBUG */ 309#endif /* CONFIG_TKIP_DEBUG */
@@ -318,11 +318,11 @@ int ieee80211_tkip_decrypt_data(struct crypto_blkcipher *tfm,
318 318
319 key->local->ops->update_tkip_key( 319 key->local->ops->update_tkip_key(
320 local_to_hw(key->local), &key->conf, 320 local_to_hw(key->local), &key->conf,
321 sta_addr, iv32, key->u.tkip.p1k_rx[queue]); 321 sta_addr, iv32, key->u.tkip.rx[queue].p1k);
322 } 322 }
323 } 323 }
324 324
325 tkip_mixing_phase2(key->u.tkip.p1k_rx[queue], 325 tkip_mixing_phase2(key->u.tkip.rx[queue].p1k,
326 &key->conf.key[ALG_TKIP_TEMP_ENCR_KEY], 326 &key->conf.key[ALG_TKIP_TEMP_ENCR_KEY],
327 iv16, rc4key); 327 iv16, rc4key);
328#ifdef CONFIG_TKIP_DEBUG 328#ifdef CONFIG_TKIP_DEBUG
diff --git a/net/mac80211/wpa.c b/net/mac80211/wpa.c
index 42f3654e1c5e..d7304490d2ec 100644
--- a/net/mac80211/wpa.c
+++ b/net/mac80211/wpa.c
@@ -176,8 +176,8 @@ ieee80211_rx_h_michael_mic_verify(struct ieee80211_rx_data *rx)
176 skb_trim(skb, skb->len - MICHAEL_MIC_LEN); 176 skb_trim(skb, skb->len - MICHAEL_MIC_LEN);
177 177
178 /* update IV in key information to be able to detect replays */ 178 /* update IV in key information to be able to detect replays */
179 rx->key->u.tkip.iv32_rx[rx->queue] = rx->tkip_iv32; 179 rx->key->u.tkip.rx[rx->queue].iv32 = rx->tkip_iv32;
180 rx->key->u.tkip.iv16_rx[rx->queue] = rx->tkip_iv16; 180 rx->key->u.tkip.rx[rx->queue].iv16 = rx->tkip_iv16;
181 181
182 return RX_CONTINUE; 182 return RX_CONTINUE;
183} 183}
@@ -214,19 +214,19 @@ static int tkip_encrypt_skb(struct ieee80211_tx_data *tx,
214 pos += hdrlen; 214 pos += hdrlen;
215 215
216 /* Increase IV for the frame */ 216 /* Increase IV for the frame */
217 key->u.tkip.iv16++; 217 key->u.tkip.tx.iv16++;
218 if (key->u.tkip.iv16 == 0) 218 if (key->u.tkip.tx.iv16 == 0)
219 key->u.tkip.iv32++; 219 key->u.tkip.tx.iv32++;
220 220
221 if (tx->key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE) { 221 if (tx->key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE) {
222 hdr = (struct ieee80211_hdr *)skb->data; 222 hdr = (struct ieee80211_hdr *)skb->data;
223 223
224 /* hwaccel - with preallocated room for IV */ 224 /* hwaccel - with preallocated room for IV */
225 ieee80211_tkip_add_iv(pos, key, 225 ieee80211_tkip_add_iv(pos, key,
226 (u8) (key->u.tkip.iv16 >> 8), 226 (u8) (key->u.tkip.tx.iv16 >> 8),
227 (u8) (((key->u.tkip.iv16 >> 8) | 0x20) & 227 (u8) (((key->u.tkip.tx.iv16 >> 8) | 0x20) &
228 0x7f), 228 0x7f),
229 (u8) key->u.tkip.iv16); 229 (u8) key->u.tkip.tx.iv16);
230 230
231 tx->control->hw_key = &tx->key->conf; 231 tx->control->hw_key = &tx->key->conf;
232 return 0; 232 return 0;