Merge branch 'upstream-linus' of master.kernel.org:/pub/scm/linux/kernel/git/jgarzik...
[powerpc.git] / net / ieee80211 / ieee80211_crypt_tkip.c
index 259572d..5a48d8e 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * Host AP crypt: host-based TKIP encryption implementation for Host AP driver
  *
- * Copyright (c) 2003-2004, Jouni Malinen <jkmaline@cc.hut.fi>
+ * Copyright (c) 2003-2004, Jouni Malinen <j@w1.fi>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License version 2 as
@@ -16,6 +16,7 @@
 #include <linux/random.h>
 #include <linux/skbuff.h>
 #include <linux/netdevice.h>
+#include <linux/mm.h>
 #include <linux/if_ether.h>
 #include <linux/if_arp.h>
 #include <asm/string.h>
@@ -93,7 +94,7 @@ static void *ieee80211_tkip_init(int key_idx)
        if (IS_ERR(priv->tx_tfm_arc4)) {
                printk(KERN_DEBUG "ieee80211_crypt_tkip: could not allocate "
                       "crypto API arc4\n");
-               priv->tfm_arc4 = NULL;
+               priv->tx_tfm_arc4 = NULL;
                goto fail;
        }
 
@@ -102,6 +103,7 @@ static void *ieee80211_tkip_init(int key_idx)
        if (IS_ERR(priv->tx_tfm_michael)) {
                printk(KERN_DEBUG "ieee80211_crypt_tkip: could not allocate "
                       "crypto API michael_mic\n");
+               priv->tx_tfm_michael = NULL;
                goto fail;
        }
 
@@ -110,6 +112,7 @@ static void *ieee80211_tkip_init(int key_idx)
        if (IS_ERR(priv->rx_tfm_arc4)) {
                printk(KERN_DEBUG "ieee80211_crypt_tkip: could not allocate "
                       "crypto API arc4\n");
+               priv->rx_tfm_arc4 = NULL;
                goto fail;
        }
 
@@ -118,7 +121,7 @@ static void *ieee80211_tkip_init(int key_idx)
        if (IS_ERR(priv->rx_tfm_michael)) {
                printk(KERN_DEBUG "ieee80211_crypt_tkip: could not allocate "
                       "crypto API michael_mic\n");
-               priv->tfm_michael = NULL;
+               priv->rx_tfm_michael = NULL;
                goto fail;
        }
 
@@ -392,6 +395,19 @@ static int ieee80211_tkip_encrypt(struct sk_buff *skb, int hdr_len, void *priv)
        return crypto_blkcipher_encrypt(&desc, &sg, &sg, len + 4);
 }
 
+/*
+ * deal with seq counter wrapping correctly.
+ * refer to timer_after() for jiffies wrapping handling
+ */
+static inline int tkip_replay_check(u32 iv32_n, u16 iv16_n,
+                                   u32 iv32_o, u16 iv16_o)
+{
+       if ((s32)iv32_n - (s32)iv32_o < 0 ||
+           (iv32_n == iv32_o && iv16_n <= iv16_o))
+               return 1;
+       return 0;
+}
+
 static int ieee80211_tkip_decrypt(struct sk_buff *skb, int hdr_len, void *priv)
 {
        struct ieee80211_tkip_data *tkey = priv;
@@ -449,7 +465,7 @@ static int ieee80211_tkip_decrypt(struct sk_buff *skb, int hdr_len, void *priv)
 
        if (tkip_replay_check(iv32, iv16, tkey->rx_iv32, tkey->rx_iv16)) {
                if (net_ratelimit()) {
-                       printk(KERN_DEBUG "TKIP: replay detected: STA=" MAC_FMT
+                       IEEE80211_DEBUG_DROP("TKIP: replay detected: STA=" MAC_FMT
                               " previous TSC %08x%04x received TSC "
                               "%08x%04x\n", MAC_ARG(hdr->addr2),
                               tkey->rx_iv32, tkey->rx_iv16, iv32, iv16);
@@ -491,7 +507,7 @@ static int ieee80211_tkip_decrypt(struct sk_buff *skb, int hdr_len, void *priv)
                        tkey->rx_phase1_done = 0;
                }
                if (net_ratelimit()) {
-                       printk(KERN_DEBUG "TKIP: ICV error detected: STA="
+                       IEEE80211_DEBUG_DROP("TKIP: ICV error detected: STA="
                               MAC_FMT "\n", MAC_ARG(hdr->addr2));
                }
                tkey->dot11RSNAStatsTKIPICVErrors++;