提交 b0f76b33 编写于 作者: H Harvey Harrison 提交者: John W. Linville

mac80211: add a struct to hold tkip context

Signed-off-by: NHarvey Harrison <harvey.harrison@gmail.com>
Cc: "John W. Linville" <linville@tuxdriver.com>
Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: NJohn W. Linville <linville@tuxdriver.com>
上级 a7b6f0c5
...@@ -256,8 +256,8 @@ static int ieee80211_get_key(struct wiphy *wiphy, struct net_device *dev, ...@@ -256,8 +256,8 @@ static int ieee80211_get_key(struct wiphy *wiphy, struct net_device *dev,
case ALG_TKIP: case ALG_TKIP:
params.cipher = WLAN_CIPHER_SUITE_TKIP; params.cipher = WLAN_CIPHER_SUITE_TKIP;
iv32 = key->u.tkip.iv32; iv32 = key->u.tkip.tx.iv32;
iv16 = key->u.tkip.iv16; iv16 = key->u.tkip.tx.iv16;
if (key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE && if (key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE &&
sdata->local->ops->get_tkip_seq) sdata->local->ops->get_tkip_seq)
......
...@@ -97,8 +97,8 @@ static ssize_t key_tx_spec_read(struct file *file, char __user *userbuf, ...@@ -97,8 +97,8 @@ static ssize_t key_tx_spec_read(struct file *file, char __user *userbuf,
break; break;
case ALG_TKIP: case ALG_TKIP:
len = scnprintf(buf, sizeof(buf), "%08x %04x\n", len = scnprintf(buf, sizeof(buf), "%08x %04x\n",
key->u.tkip.iv32, key->u.tkip.tx.iv32,
key->u.tkip.iv16); key->u.tkip.tx.iv16);
break; break;
case ALG_CCMP: case ALG_CCMP:
tpn = key->u.ccmp.tx_pn; tpn = key->u.ccmp.tx_pn;
...@@ -128,8 +128,8 @@ static ssize_t key_rx_spec_read(struct file *file, char __user *userbuf, ...@@ -128,8 +128,8 @@ static ssize_t key_rx_spec_read(struct file *file, char __user *userbuf,
for (i = 0; i < NUM_RX_DATA_QUEUES; i++) for (i = 0; i < NUM_RX_DATA_QUEUES; i++)
p += scnprintf(p, sizeof(buf)+buf-p, p += scnprintf(p, sizeof(buf)+buf-p,
"%08x %04x\n", "%08x %04x\n",
key->u.tkip.iv32_rx[i], key->u.tkip.rx[i].iv32,
key->u.tkip.iv16_rx[i]); key->u.tkip.rx[i].iv16);
len = p - buf; len = p - buf;
break; break;
case ALG_CCMP: case ALG_CCMP:
......
...@@ -69,6 +69,13 @@ enum ieee80211_internal_key_flags { ...@@ -69,6 +69,13 @@ enum ieee80211_internal_key_flags {
KEY_FLAG_TODO_ADD_DEBUGFS = BIT(5), KEY_FLAG_TODO_ADD_DEBUGFS = BIT(5),
}; };
struct tkip_ctx {
u32 iv32;
u16 iv16;
u16 p1k[5];
int initialized;
};
struct ieee80211_key { struct ieee80211_key {
struct ieee80211_local *local; struct ieee80211_local *local;
struct ieee80211_sub_if_data *sdata; struct ieee80211_sub_if_data *sdata;
...@@ -85,16 +92,10 @@ struct ieee80211_key { ...@@ -85,16 +92,10 @@ struct ieee80211_key {
union { union {
struct { struct {
/* last used TSC */ /* last used TSC */
u32 iv32; struct tkip_ctx tx;
u16 iv16;
u16 p1k[5];
int tx_initialized;
/* last received RSC */ /* last received RSC */
u32 iv32_rx[NUM_RX_DATA_QUEUES]; struct tkip_ctx rx[NUM_RX_DATA_QUEUES];
u16 iv16_rx[NUM_RX_DATA_QUEUES];
u16 p1k_rx[NUM_RX_DATA_QUEUES][5];
int rx_initialized[NUM_RX_DATA_QUEUES];
} tkip; } tkip;
struct { struct {
u8 tx_pn[6]; u8 tx_pn[6];
......
...@@ -138,7 +138,7 @@ u8 *ieee80211_tkip_add_iv(u8 *pos, struct ieee80211_key *key, ...@@ -138,7 +138,7 @@ u8 *ieee80211_tkip_add_iv(u8 *pos, struct ieee80211_key *key,
*pos++ = iv1; *pos++ = iv1;
*pos++ = iv2; *pos++ = iv2;
*pos++ = (key->conf.keyidx << 6) | (1 << 5) /* Ext IV */; *pos++ = (key->conf.keyidx << 6) | (1 << 5) /* Ext IV */;
put_unaligned_le32(key->u.tkip.iv32, pos); put_unaligned_le32(key->u.tkip.tx.iv32, pos);
return pos + 4; return pos + 4;
} }
...@@ -146,16 +146,16 @@ static void ieee80211_tkip_gen_rc4key(struct ieee80211_key *key, u8 *ta, ...@@ -146,16 +146,16 @@ static void ieee80211_tkip_gen_rc4key(struct ieee80211_key *key, u8 *ta,
u8 *rc4key) u8 *rc4key)
{ {
/* Calculate per-packet key */ /* Calculate per-packet key */
if (key->u.tkip.iv16 == 0 || !key->u.tkip.tx_initialized) { if (key->u.tkip.tx.iv16 == 0 || !key->u.tkip.tx.initialized) {
/* IV16 wrapped around - perform TKIP phase 1 */ /* IV16 wrapped around - perform TKIP phase 1 */
tkip_mixing_phase1(ta, &key->conf.key[ALG_TKIP_TEMP_ENCR_KEY], tkip_mixing_phase1(ta, &key->conf.key[ALG_TKIP_TEMP_ENCR_KEY],
key->u.tkip.iv32, key->u.tkip.p1k); key->u.tkip.tx.iv32, key->u.tkip.tx.p1k);
key->u.tkip.tx_initialized = 1; key->u.tkip.tx.initialized = 1;
} }
tkip_mixing_phase2(key->u.tkip.p1k, tkip_mixing_phase2(key->u.tkip.tx.p1k,
&key->conf.key[ALG_TKIP_TEMP_ENCR_KEY], &key->conf.key[ALG_TKIP_TEMP_ENCR_KEY],
key->u.tkip.iv16, rc4key); key->u.tkip.tx.iv16, rc4key);
} }
void ieee80211_get_tkip_key(struct ieee80211_key_conf *keyconf, void ieee80211_get_tkip_key(struct ieee80211_key_conf *keyconf,
...@@ -179,9 +179,9 @@ void ieee80211_get_tkip_key(struct ieee80211_key_conf *keyconf, ...@@ -179,9 +179,9 @@ void ieee80211_get_tkip_key(struct ieee80211_key_conf *keyconf,
printk(KERN_DEBUG "TKIP encrypt: iv16 = 0x%04x, iv32 = 0x%08x\n", printk(KERN_DEBUG "TKIP encrypt: iv16 = 0x%04x, iv32 = 0x%08x\n",
iv16, iv32); iv16, iv32);
if (iv32 != key->u.tkip.iv32) { if (iv32 != key->u.tkip.tx.iv32) {
printk(KERN_DEBUG "skb: iv32 = 0x%08x key: iv32 = 0x%08x\n", printk(KERN_DEBUG "skb: iv32 = 0x%08x key: iv32 = 0x%08x\n",
iv32, key->u.tkip.iv32); iv32, key->u.tkip.tx.iv32);
printk(KERN_DEBUG "Wrap around of iv16 in the middle of a " printk(KERN_DEBUG "Wrap around of iv16 in the middle of a "
"fragmented packet\n"); "fragmented packet\n");
} }
...@@ -190,19 +190,19 @@ void ieee80211_get_tkip_key(struct ieee80211_key_conf *keyconf, ...@@ -190,19 +190,19 @@ void ieee80211_get_tkip_key(struct ieee80211_key_conf *keyconf,
/* Update the p1k only when the iv16 in the packet wraps around, this /* Update the p1k only when the iv16 in the packet wraps around, this
* might occur after the wrap around of iv16 in the key in case of * might occur after the wrap around of iv16 in the key in case of
* fragmented packets. */ * fragmented packets. */
if (iv16 == 0 || !key->u.tkip.tx_initialized) { if (iv16 == 0 || !key->u.tkip.tx.initialized) {
/* IV16 wrapped around - perform TKIP phase 1 */ /* IV16 wrapped around - perform TKIP phase 1 */
tkip_mixing_phase1(ta, &key->conf.key[ALG_TKIP_TEMP_ENCR_KEY], tkip_mixing_phase1(ta, &key->conf.key[ALG_TKIP_TEMP_ENCR_KEY],
iv32, key->u.tkip.p1k); iv32, key->u.tkip.tx.p1k);
key->u.tkip.tx_initialized = 1; key->u.tkip.tx.initialized = 1;
} }
if (type == IEEE80211_TKIP_P1_KEY) { if (type == IEEE80211_TKIP_P1_KEY) {
memcpy(outkey, key->u.tkip.p1k, sizeof(u16) * 5); memcpy(outkey, key->u.tkip.tx.p1k, sizeof(u16) * 5);
return; return;
} }
tkip_mixing_phase2(key->u.tkip.p1k, tkip_mixing_phase2(key->u.tkip.tx.p1k,
&key->conf.key[ALG_TKIP_TEMP_ENCR_KEY], iv16, outkey); &key->conf.key[ALG_TKIP_TEMP_ENCR_KEY], iv16, outkey);
} }
EXPORT_SYMBOL(ieee80211_get_tkip_key); EXPORT_SYMBOL(ieee80211_get_tkip_key);
...@@ -263,33 +263,33 @@ int ieee80211_tkip_decrypt_data(struct crypto_blkcipher *tfm, ...@@ -263,33 +263,33 @@ int ieee80211_tkip_decrypt_data(struct crypto_blkcipher *tfm,
if ((keyid >> 6) != key->conf.keyidx) if ((keyid >> 6) != key->conf.keyidx)
return TKIP_DECRYPT_INVALID_KEYIDX; return TKIP_DECRYPT_INVALID_KEYIDX;
if (key->u.tkip.rx_initialized[queue] && if (key->u.tkip.rx[queue].initialized &&
(iv32 < key->u.tkip.iv32_rx[queue] || (iv32 < key->u.tkip.rx[queue].iv32 ||
(iv32 == key->u.tkip.iv32_rx[queue] && (iv32 == key->u.tkip.rx[queue].iv32 &&
iv16 <= key->u.tkip.iv16_rx[queue]))) { iv16 <= key->u.tkip.rx[queue].iv16))) {
#ifdef CONFIG_TKIP_DEBUG #ifdef CONFIG_TKIP_DEBUG
DECLARE_MAC_BUF(mac); DECLARE_MAC_BUF(mac);
printk(KERN_DEBUG "TKIP replay detected for RX frame from " printk(KERN_DEBUG "TKIP replay detected for RX frame from "
"%s (RX IV (%04x,%02x) <= prev. IV (%04x,%02x)\n", "%s (RX IV (%04x,%02x) <= prev. IV (%04x,%02x)\n",
print_mac(mac, ta), print_mac(mac, ta),
iv32, iv16, key->u.tkip.iv32_rx[queue], iv32, iv16, key->u.tkip.rx[queue].iv32,
key->u.tkip.iv16_rx[queue]); key->u.tkip.rx[queue].iv16);
#endif /* CONFIG_TKIP_DEBUG */ #endif /* CONFIG_TKIP_DEBUG */
return TKIP_DECRYPT_REPLAY; return TKIP_DECRYPT_REPLAY;
} }
if (only_iv) { if (only_iv) {
res = TKIP_DECRYPT_OK; res = TKIP_DECRYPT_OK;
key->u.tkip.rx_initialized[queue] = 1; key->u.tkip.rx[queue].initialized = 1;
goto done; goto done;
} }
if (!key->u.tkip.rx_initialized[queue] || if (!key->u.tkip.rx[queue].initialized ||
key->u.tkip.iv32_rx[queue] != iv32) { key->u.tkip.rx[queue].iv32 != iv32) {
key->u.tkip.rx_initialized[queue] = 1; key->u.tkip.rx[queue].initialized = 1;
/* IV16 wrapped around - perform TKIP phase 1 */ /* IV16 wrapped around - perform TKIP phase 1 */
tkip_mixing_phase1(ta, &key->conf.key[ALG_TKIP_TEMP_ENCR_KEY], tkip_mixing_phase1(ta, &key->conf.key[ALG_TKIP_TEMP_ENCR_KEY],
iv32, key->u.tkip.p1k_rx[queue]); iv32, key->u.tkip.rx[queue].p1k);
#ifdef CONFIG_TKIP_DEBUG #ifdef CONFIG_TKIP_DEBUG
{ {
int i; int i;
...@@ -303,7 +303,7 @@ int ieee80211_tkip_decrypt_data(struct crypto_blkcipher *tfm, ...@@ -303,7 +303,7 @@ int ieee80211_tkip_decrypt_data(struct crypto_blkcipher *tfm,
printk("\n"); printk("\n");
printk(KERN_DEBUG "TKIP decrypt: P1K="); printk(KERN_DEBUG "TKIP decrypt: P1K=");
for (i = 0; i < 5; i++) for (i = 0; i < 5; i++)
printk("%04x ", key->u.tkip.p1k_rx[queue][i]); printk("%04x ", key->u.tkip.rx[queue].p1k[i]);
printk("\n"); printk("\n");
} }
#endif /* CONFIG_TKIP_DEBUG */ #endif /* CONFIG_TKIP_DEBUG */
...@@ -318,11 +318,11 @@ int ieee80211_tkip_decrypt_data(struct crypto_blkcipher *tfm, ...@@ -318,11 +318,11 @@ int ieee80211_tkip_decrypt_data(struct crypto_blkcipher *tfm,
key->local->ops->update_tkip_key( key->local->ops->update_tkip_key(
local_to_hw(key->local), &key->conf, local_to_hw(key->local), &key->conf,
sta_addr, iv32, key->u.tkip.p1k_rx[queue]); sta_addr, iv32, key->u.tkip.rx[queue].p1k);
} }
} }
tkip_mixing_phase2(key->u.tkip.p1k_rx[queue], tkip_mixing_phase2(key->u.tkip.rx[queue].p1k,
&key->conf.key[ALG_TKIP_TEMP_ENCR_KEY], &key->conf.key[ALG_TKIP_TEMP_ENCR_KEY],
iv16, rc4key); iv16, rc4key);
#ifdef CONFIG_TKIP_DEBUG #ifdef CONFIG_TKIP_DEBUG
......
...@@ -176,8 +176,8 @@ ieee80211_rx_h_michael_mic_verify(struct ieee80211_rx_data *rx) ...@@ -176,8 +176,8 @@ ieee80211_rx_h_michael_mic_verify(struct ieee80211_rx_data *rx)
skb_trim(skb, skb->len - MICHAEL_MIC_LEN); skb_trim(skb, skb->len - MICHAEL_MIC_LEN);
/* update IV in key information to be able to detect replays */ /* update IV in key information to be able to detect replays */
rx->key->u.tkip.iv32_rx[rx->queue] = rx->tkip_iv32; rx->key->u.tkip.rx[rx->queue].iv32 = rx->tkip_iv32;
rx->key->u.tkip.iv16_rx[rx->queue] = rx->tkip_iv16; rx->key->u.tkip.rx[rx->queue].iv16 = rx->tkip_iv16;
return RX_CONTINUE; return RX_CONTINUE;
} }
...@@ -214,19 +214,19 @@ static int tkip_encrypt_skb(struct ieee80211_tx_data *tx, ...@@ -214,19 +214,19 @@ static int tkip_encrypt_skb(struct ieee80211_tx_data *tx,
pos += hdrlen; pos += hdrlen;
/* Increase IV for the frame */ /* Increase IV for the frame */
key->u.tkip.iv16++; key->u.tkip.tx.iv16++;
if (key->u.tkip.iv16 == 0) if (key->u.tkip.tx.iv16 == 0)
key->u.tkip.iv32++; key->u.tkip.tx.iv32++;
if (tx->key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE) { if (tx->key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE) {
hdr = (struct ieee80211_hdr *)skb->data; hdr = (struct ieee80211_hdr *)skb->data;
/* hwaccel - with preallocated room for IV */ /* hwaccel - with preallocated room for IV */
ieee80211_tkip_add_iv(pos, key, ieee80211_tkip_add_iv(pos, key,
(u8) (key->u.tkip.iv16 >> 8), (u8) (key->u.tkip.tx.iv16 >> 8),
(u8) (((key->u.tkip.iv16 >> 8) | 0x20) & (u8) (((key->u.tkip.tx.iv16 >> 8) | 0x20) &
0x7f), 0x7f),
(u8) key->u.tkip.iv16); (u8) key->u.tkip.tx.iv16);
tx->control->hw_key = &tx->key->conf; tx->control->hw_key = &tx->key->conf;
return 0; return 0;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册