diff options
author | Harvey Harrison <harvey.harrison@gmail.com> | 2008-06-11 17:22:00 -0400 |
---|---|---|
committer | John W. Linville <linville@tuxdriver.com> | 2008-06-14 12:18:13 -0400 |
commit | c801242c38de247d82f12f6bf28bd19a280a12ae (patch) | |
tree | 7ad4a20083f24b433e36ab28bda09ea87f499bdc /net | |
parent | 87228f57434108d8463ff10fd408d8d1273a23d2 (diff) |
mac80211: tkip.c consolidate tkip IV writing in helper
Signed-off-by: Harvey Harrison <harvey.harrison@gmail.com>
Signed-off-by: John W. Linville <linville@tuxdriver.com>
Diffstat (limited to 'net')
-rw-r--r-- | net/mac80211/tkip.c | 25 | ||||
-rw-r--r-- | net/mac80211/tkip.h | 4 | ||||
-rw-r--r-- | net/mac80211/wpa.c | 8 |
3 files changed, 17 insertions, 20 deletions
diff --git a/net/mac80211/tkip.c b/net/mac80211/tkip.c index a00cf1ea7719..a2c8ca1100b2 100644 --- a/net/mac80211/tkip.c +++ b/net/mac80211/tkip.c | |||
@@ -64,6 +64,15 @@ static u16 tkipS(u16 val) | |||
64 | return tkip_sbox[val & 0xff] ^ swab16(tkip_sbox[val >> 8]); | 64 | return tkip_sbox[val & 0xff] ^ swab16(tkip_sbox[val >> 8]); |
65 | } | 65 | } |
66 | 66 | ||
67 | static u8 *write_tkip_iv(u8 *pos, u16 iv16) | ||
68 | { | ||
69 | *pos++ = iv16 >> 8; | ||
70 | *pos++ = ((iv16 >> 8) | 0x20) & 0x7f; | ||
71 | *pos++ = iv16 & 0xFF; | ||
72 | return pos; | ||
73 | } | ||
74 | |||
75 | |||
67 | /* | 76 | /* |
68 | * P1K := Phase1(TA, TK, TSC) | 77 | * P1K := Phase1(TA, TK, TSC) |
69 | * TA = transmitter address (48 bits) | 78 | * TA = transmitter address (48 bits) |
@@ -123,12 +132,9 @@ static void tkip_mixing_phase2(struct ieee80211_key *key, struct tkip_ctx *ctx, | |||
123 | ppk[4] += ror16(ppk[3], 1); | 132 | ppk[4] += ror16(ppk[3], 1); |
124 | ppk[5] += ror16(ppk[4], 1); | 133 | ppk[5] += ror16(ppk[4], 1); |
125 | 134 | ||
126 | rc4key[0] = tsc_IV16 >> 8; | 135 | rc4key = write_tkip_iv(rc4key, tsc_IV16); |
127 | rc4key[1] = ((tsc_IV16 >> 8) | 0x20) & 0x7f; | 136 | *rc4key++ = ((ppk[5] ^ get_unaligned_le16(tk)) >> 1) & 0xFF; |
128 | rc4key[2] = tsc_IV16 & 0xFF; | ||
129 | rc4key[3] = ((ppk[5] ^ get_unaligned_le16(tk)) >> 1) & 0xFF; | ||
130 | 137 | ||
131 | rc4key += 4; | ||
132 | for (i = 0; i < 6; i++) | 138 | for (i = 0; i < 6; i++) |
133 | put_unaligned_le16(ppk[i], rc4key + 2 * i); | 139 | put_unaligned_le16(ppk[i], rc4key + 2 * i); |
134 | } | 140 | } |
@@ -136,12 +142,9 @@ static void tkip_mixing_phase2(struct ieee80211_key *key, struct tkip_ctx *ctx, | |||
136 | /* Add TKIP IV and Ext. IV at @pos. @iv0, @iv1, and @iv2 are the first octets | 142 | /* Add TKIP IV and Ext. IV at @pos. @iv0, @iv1, and @iv2 are the first octets |
137 | * of the IV. Returns pointer to the octet following IVs (i.e., beginning of | 143 | * of the IV. Returns pointer to the octet following IVs (i.e., beginning of |
138 | * the packet payload). */ | 144 | * the packet payload). */ |
139 | u8 *ieee80211_tkip_add_iv(u8 *pos, struct ieee80211_key *key, | 145 | u8 *ieee80211_tkip_add_iv(u8 *pos, struct ieee80211_key *key, u16 iv16) |
140 | u8 iv0, u8 iv1, u8 iv2) | ||
141 | { | 146 | { |
142 | *pos++ = iv0; | 147 | pos = write_tkip_iv(pos, iv16); |
143 | *pos++ = iv1; | ||
144 | *pos++ = iv2; | ||
145 | *pos++ = (key->conf.keyidx << 6) | (1 << 5) /* Ext IV */; | 148 | *pos++ = (key->conf.keyidx << 6) | (1 << 5) /* Ext IV */; |
146 | put_unaligned_le32(key->u.tkip.tx.iv32, pos); | 149 | put_unaligned_le32(key->u.tkip.tx.iv32, pos); |
147 | return pos + 4; | 150 | return pos + 4; |
@@ -213,7 +216,7 @@ void ieee80211_tkip_encrypt_data(struct crypto_blkcipher *tfm, | |||
213 | u8 rc4key[16]; | 216 | u8 rc4key[16]; |
214 | 217 | ||
215 | ieee80211_tkip_gen_rc4key(key, ta, rc4key); | 218 | ieee80211_tkip_gen_rc4key(key, ta, rc4key); |
216 | pos = ieee80211_tkip_add_iv(pos, key, rc4key[0], rc4key[1], rc4key[2]); | 219 | pos = ieee80211_tkip_add_iv(pos, key, key->u.tkip.tx.iv16); |
217 | ieee80211_wep_encrypt_data(tfm, rc4key, 16, pos, payload_len); | 220 | ieee80211_wep_encrypt_data(tfm, rc4key, 16, pos, payload_len); |
218 | } | 221 | } |
219 | 222 | ||
diff --git a/net/mac80211/tkip.h b/net/mac80211/tkip.h index b890427fc959..d4714383f5fc 100644 --- a/net/mac80211/tkip.h +++ b/net/mac80211/tkip.h | |||
@@ -13,8 +13,8 @@ | |||
13 | #include <linux/crypto.h> | 13 | #include <linux/crypto.h> |
14 | #include "key.h" | 14 | #include "key.h" |
15 | 15 | ||
16 | u8 *ieee80211_tkip_add_iv(u8 *pos, struct ieee80211_key *key, | 16 | u8 *ieee80211_tkip_add_iv(u8 *pos, struct ieee80211_key *key, u16 iv16); |
17 | u8 iv0, u8 iv1, u8 iv2); | 17 | |
18 | void ieee80211_tkip_encrypt_data(struct crypto_blkcipher *tfm, | 18 | void ieee80211_tkip_encrypt_data(struct crypto_blkcipher *tfm, |
19 | struct ieee80211_key *key, | 19 | struct ieee80211_key *key, |
20 | u8 *pos, size_t payload_len, u8 *ta); | 20 | u8 *pos, size_t payload_len, u8 *ta); |
diff --git a/net/mac80211/wpa.c b/net/mac80211/wpa.c index 9834cecaca35..345e10e9b313 100644 --- a/net/mac80211/wpa.c +++ b/net/mac80211/wpa.c | |||
@@ -198,14 +198,8 @@ static int tkip_encrypt_skb(struct ieee80211_tx_data *tx, struct sk_buff *skb) | |||
198 | key->u.tkip.tx.iv32++; | 198 | key->u.tkip.tx.iv32++; |
199 | 199 | ||
200 | if (tx->key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE) { | 200 | if (tx->key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE) { |
201 | hdr = (struct ieee80211_hdr *)skb->data; | ||
202 | |||
203 | /* hwaccel - with preallocated room for IV */ | 201 | /* hwaccel - with preallocated room for IV */ |
204 | ieee80211_tkip_add_iv(pos, key, | 202 | ieee80211_tkip_add_iv(pos, key, key->u.tkip.tx.iv16); |
205 | (u8) (key->u.tkip.tx.iv16 >> 8), | ||
206 | (u8) (((key->u.tkip.tx.iv16 >> 8) | 0x20) & | ||
207 | 0x7f), | ||
208 | (u8) key->u.tkip.tx.iv16); | ||
209 | 203 | ||
210 | info->control.hw_key = &tx->key->conf; | 204 | info->control.hw_key = &tx->key->conf; |
211 | return 0; | 205 | return 0; |