aboutsummaryrefslogtreecommitdiffstats
path: root/net/ieee80211/ieee80211_crypt_tkip.c
diff options
context:
space:
mode:
Diffstat (limited to 'net/ieee80211/ieee80211_crypt_tkip.c')
-rw-r--r--net/ieee80211/ieee80211_crypt_tkip.c56
1 files changed, 28 insertions, 28 deletions
diff --git a/net/ieee80211/ieee80211_crypt_tkip.c b/net/ieee80211/ieee80211_crypt_tkip.c
index e0988320efbf..93def94c1b32 100644
--- a/net/ieee80211/ieee80211_crypt_tkip.c
+++ b/net/ieee80211/ieee80211_crypt_tkip.c
@@ -80,10 +80,9 @@ static void *ieee80211_tkip_init(int key_idx)
80{ 80{
81 struct ieee80211_tkip_data *priv; 81 struct ieee80211_tkip_data *priv;
82 82
83 priv = kmalloc(sizeof(*priv), GFP_ATOMIC); 83 priv = kzalloc(sizeof(*priv), GFP_ATOMIC);
84 if (priv == NULL) 84 if (priv == NULL)
85 goto fail; 85 goto fail;
86 memset(priv, 0, sizeof(*priv));
87 86
88 priv->key_idx = key_idx; 87 priv->key_idx = key_idx;
89 88
@@ -271,34 +270,33 @@ static void tkip_mixing_phase2(u8 * WEPSeed, const u8 * TK, const u16 * TTAK,
271#endif 270#endif
272} 271}
273 272
274static u8 *ieee80211_tkip_hdr(struct sk_buff *skb, int hdr_len, void *priv) 273static int ieee80211_tkip_hdr(struct sk_buff *skb, int hdr_len,
274 u8 * rc4key, int keylen, void *priv)
275{ 275{
276 struct ieee80211_tkip_data *tkey = priv; 276 struct ieee80211_tkip_data *tkey = priv;
277 int len; 277 int len;
278 u8 *rc4key, *pos, *icv; 278 u8 *pos;
279 struct ieee80211_hdr_4addr *hdr; 279 struct ieee80211_hdr_4addr *hdr;
280 u32 crc;
281 280
282 hdr = (struct ieee80211_hdr_4addr *)skb->data; 281 hdr = (struct ieee80211_hdr_4addr *)skb->data;
283 282
284 if (skb_headroom(skb) < 8 || skb->len < hdr_len) 283 if (skb_headroom(skb) < 8 || skb->len < hdr_len)
285 return NULL; 284 return -1;
285
286 if (rc4key == NULL || keylen < 16)
287 return -1;
286 288
287 if (!tkey->tx_phase1_done) { 289 if (!tkey->tx_phase1_done) {
288 tkip_mixing_phase1(tkey->tx_ttak, tkey->key, hdr->addr2, 290 tkip_mixing_phase1(tkey->tx_ttak, tkey->key, hdr->addr2,
289 tkey->tx_iv32); 291 tkey->tx_iv32);
290 tkey->tx_phase1_done = 1; 292 tkey->tx_phase1_done = 1;
291 } 293 }
292 rc4key = kmalloc(16, GFP_ATOMIC);
293 if (!rc4key)
294 return NULL;
295 tkip_mixing_phase2(rc4key, tkey->key, tkey->tx_ttak, tkey->tx_iv16); 294 tkip_mixing_phase2(rc4key, tkey->key, tkey->tx_ttak, tkey->tx_iv16);
296 295
297 len = skb->len - hdr_len; 296 len = skb->len - hdr_len;
298 pos = skb_push(skb, 8); 297 pos = skb_push(skb, 8);
299 memmove(pos, pos + 8, hdr_len); 298 memmove(pos, pos + 8, hdr_len);
300 pos += hdr_len; 299 pos += hdr_len;
301 icv = skb_put(skb, 4);
302 300
303 *pos++ = *rc4key; 301 *pos++ = *rc4key;
304 *pos++ = *(rc4key + 1); 302 *pos++ = *(rc4key + 1);
@@ -309,28 +307,28 @@ static u8 *ieee80211_tkip_hdr(struct sk_buff *skb, int hdr_len, void *priv)
309 *pos++ = (tkey->tx_iv32 >> 16) & 0xff; 307 *pos++ = (tkey->tx_iv32 >> 16) & 0xff;
310 *pos++ = (tkey->tx_iv32 >> 24) & 0xff; 308 *pos++ = (tkey->tx_iv32 >> 24) & 0xff;
311 309
312 crc = ~crc32_le(~0, pos, len); 310 tkey->tx_iv16++;
313 icv[0] = crc; 311 if (tkey->tx_iv16 == 0) {
314 icv[1] = crc >> 8; 312 tkey->tx_phase1_done = 0;
315 icv[2] = crc >> 16; 313 tkey->tx_iv32++;
316 icv[3] = crc >> 24; 314 }
317 315
318 return rc4key; 316 return 8;
319} 317}
320 318
321static int ieee80211_tkip_encrypt(struct sk_buff *skb, int hdr_len, void *priv) 319static int ieee80211_tkip_encrypt(struct sk_buff *skb, int hdr_len, void *priv)
322{ 320{
323 struct ieee80211_tkip_data *tkey = priv; 321 struct ieee80211_tkip_data *tkey = priv;
324 int len; 322 int len;
325 const u8 *rc4key; 323 u8 rc4key[16], *pos, *icv;
326 u8 *pos; 324 u32 crc;
327 struct scatterlist sg; 325 struct scatterlist sg;
328 326
329 if (tkey->flags & IEEE80211_CRYPTO_TKIP_COUNTERMEASURES) { 327 if (tkey->flags & IEEE80211_CRYPTO_TKIP_COUNTERMEASURES) {
330 if (net_ratelimit()) { 328 if (net_ratelimit()) {
331 struct ieee80211_hdr_4addr *hdr = 329 struct ieee80211_hdr_4addr *hdr =
332 (struct ieee80211_hdr_4addr *)skb->data; 330 (struct ieee80211_hdr_4addr *)skb->data;
333 printk(KERN_DEBUG "TKIP countermeasures: dropped " 331 printk(KERN_DEBUG ": TKIP countermeasures: dropped "
334 "TX packet to " MAC_FMT "\n", 332 "TX packet to " MAC_FMT "\n",
335 MAC_ARG(hdr->addr1)); 333 MAC_ARG(hdr->addr1));
336 } 334 }
@@ -343,22 +341,23 @@ static int ieee80211_tkip_encrypt(struct sk_buff *skb, int hdr_len, void *priv)
343 len = skb->len - hdr_len; 341 len = skb->len - hdr_len;
344 pos = skb->data + hdr_len; 342 pos = skb->data + hdr_len;
345 343
346 rc4key = ieee80211_tkip_hdr(skb, hdr_len, priv); 344 if ((ieee80211_tkip_hdr(skb, hdr_len, rc4key, 16, priv)) < 0)
347 if (!rc4key)
348 return -1; 345 return -1;
349 346
347 icv = skb_put(skb, 4);
348
349 crc = ~crc32_le(~0, pos, len);
350 icv[0] = crc;
351 icv[1] = crc >> 8;
352 icv[2] = crc >> 16;
353 icv[3] = crc >> 24;
354
350 crypto_cipher_setkey(tkey->tfm_arc4, rc4key, 16); 355 crypto_cipher_setkey(tkey->tfm_arc4, rc4key, 16);
351 sg.page = virt_to_page(pos); 356 sg.page = virt_to_page(pos);
352 sg.offset = offset_in_page(pos); 357 sg.offset = offset_in_page(pos);
353 sg.length = len + 4; 358 sg.length = len + 4;
354 crypto_cipher_encrypt(tkey->tfm_arc4, &sg, &sg, len + 4); 359 crypto_cipher_encrypt(tkey->tfm_arc4, &sg, &sg, len + 4);
355 360
356 tkey->tx_iv16++;
357 if (tkey->tx_iv16 == 0) {
358 tkey->tx_phase1_done = 0;
359 tkey->tx_iv32++;
360 }
361
362 return 0; 361 return 0;
363} 362}
364 363
@@ -379,7 +378,7 @@ static int ieee80211_tkip_decrypt(struct sk_buff *skb, int hdr_len, void *priv)
379 378
380 if (tkey->flags & IEEE80211_CRYPTO_TKIP_COUNTERMEASURES) { 379 if (tkey->flags & IEEE80211_CRYPTO_TKIP_COUNTERMEASURES) {
381 if (net_ratelimit()) { 380 if (net_ratelimit()) {
382 printk(KERN_DEBUG "TKIP countermeasures: dropped " 381 printk(KERN_DEBUG ": TKIP countermeasures: dropped "
383 "received packet from " MAC_FMT "\n", 382 "received packet from " MAC_FMT "\n",
384 MAC_ARG(hdr->addr2)); 383 MAC_ARG(hdr->addr2));
385 } 384 }
@@ -695,6 +694,7 @@ static struct ieee80211_crypto_ops ieee80211_crypt_tkip = {
695 .name = "TKIP", 694 .name = "TKIP",
696 .init = ieee80211_tkip_init, 695 .init = ieee80211_tkip_init,
697 .deinit = ieee80211_tkip_deinit, 696 .deinit = ieee80211_tkip_deinit,
697 .build_iv = ieee80211_tkip_hdr,
698 .encrypt_mpdu = ieee80211_tkip_encrypt, 698 .encrypt_mpdu = ieee80211_tkip_encrypt,
699 .decrypt_mpdu = ieee80211_tkip_decrypt, 699 .decrypt_mpdu = ieee80211_tkip_decrypt,
700 .encrypt_msdu = ieee80211_michael_mic_add, 700 .encrypt_msdu = ieee80211_michael_mic_add,