aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHarvey Harrison <harvey.harrison@gmail.com>2008-06-11 17:22:00 -0400
committerJohn W. Linville <linville@tuxdriver.com>2008-06-14 12:18:13 -0400
commit7c70537f97fe35f46762247a4bda72c16d585736 (patch)
tree54c8ba7f5e1822f48a00ae3133492e0b4d624a4a
parentc801242c38de247d82f12f6bf28bd19a280a12ae (diff)
mac80211: tkip.c fold ieee80211_gen_rc4key into its one caller
Also change the arguments of the phase1, 2 key mixing to take a pointer to the encrytion key and the tkip_ctx in the same order. Do the dereference of the encryption key in the callers. Signed-off-by: Harvey Harrison <harvey.harrison@gmail.com> Signed-off-by: John W. Linville <linville@tuxdriver.com>
-rw-r--r--net/mac80211/tkip.c38
1 files changed, 17 insertions, 21 deletions
diff --git a/net/mac80211/tkip.c b/net/mac80211/tkip.c
index a2c8ca1100b2..8a7dac742b71 100644
--- a/net/mac80211/tkip.c
+++ b/net/mac80211/tkip.c
@@ -72,7 +72,6 @@ static u8 *write_tkip_iv(u8 *pos, u16 iv16)
72 return pos; 72 return pos;
73} 73}
74 74
75
76/* 75/*
77 * P1K := Phase1(TA, TK, TSC) 76 * P1K := Phase1(TA, TK, TSC)
78 * TA = transmitter address (48 bits) 77 * TA = transmitter address (48 bits)
@@ -80,11 +79,10 @@ static u8 *write_tkip_iv(u8 *pos, u16 iv16)
80 * TSC = TKIP sequence counter (48 bits, only 32 msb bits used) 79 * TSC = TKIP sequence counter (48 bits, only 32 msb bits used)
81 * P1K: 80 bits 80 * P1K: 80 bits
82 */ 81 */
83static void tkip_mixing_phase1(struct ieee80211_key *key, const u8 *ta, 82static void tkip_mixing_phase1(const u8 *tk, struct tkip_ctx *ctx,
84 struct tkip_ctx *ctx, u32 tsc_IV32) 83 const u8 *ta, u32 tsc_IV32)
85{ 84{
86 int i, j; 85 int i, j;
87 const u8 *tk = &key->conf.key[ALG_TKIP_TEMP_ENCR_KEY];
88 u16 *p1k = ctx->p1k; 86 u16 *p1k = ctx->p1k;
89 87
90 p1k[0] = tsc_IV32 & 0xFFFF; 88 p1k[0] = tsc_IV32 & 0xFFFF;
@@ -104,12 +102,11 @@ static void tkip_mixing_phase1(struct ieee80211_key *key, const u8 *ta,
104 ctx->initialized = 1; 102 ctx->initialized = 1;
105} 103}
106 104
107static void tkip_mixing_phase2(struct ieee80211_key *key, struct tkip_ctx *ctx, 105static void tkip_mixing_phase2(const u8 *tk, struct tkip_ctx *ctx,
108 u16 tsc_IV16, u8 *rc4key) 106 u16 tsc_IV16, u8 *rc4key)
109{ 107{
110 u16 ppk[6]; 108 u16 ppk[6];
111 const u16 *p1k = ctx->p1k; 109 const u16 *p1k = ctx->p1k;
112 const u8 *tk = &key->conf.key[ALG_TKIP_TEMP_ENCR_KEY];
113 int i; 110 int i;
114 111
115 ppk[0] = p1k[0]; 112 ppk[0] = p1k[0];
@@ -150,16 +147,6 @@ u8 *ieee80211_tkip_add_iv(u8 *pos, struct ieee80211_key *key, u16 iv16)
150 return pos + 4; 147 return pos + 4;
151} 148}
152 149
153static void ieee80211_tkip_gen_rc4key(struct ieee80211_key *key, u8 *ta,
154 u8 *rc4key)
155{
156 /* Calculate per-packet key */
157 if (key->u.tkip.tx.iv16 == 0 || !key->u.tkip.tx.initialized)
158 tkip_mixing_phase1(key, ta, &key->u.tkip.tx, key->u.tkip.tx.iv32);
159
160 tkip_mixing_phase2(key, &key->u.tkip.tx, key->u.tkip.tx.iv16, rc4key);
161}
162
163void ieee80211_get_tkip_key(struct ieee80211_key_conf *keyconf, 150void ieee80211_get_tkip_key(struct ieee80211_key_conf *keyconf,
164 struct sk_buff *skb, enum ieee80211_tkip_key_type type, 151 struct sk_buff *skb, enum ieee80211_tkip_key_type type,
165 u8 *outkey) 152 u8 *outkey)
@@ -170,6 +157,7 @@ void ieee80211_get_tkip_key(struct ieee80211_key_conf *keyconf,
170 u8 *data = (u8 *) hdr; 157 u8 *data = (u8 *) hdr;
171 u16 fc = le16_to_cpu(hdr->frame_control); 158 u16 fc = le16_to_cpu(hdr->frame_control);
172 int hdr_len = ieee80211_get_hdrlen(fc); 159 int hdr_len = ieee80211_get_hdrlen(fc);
160 u8 *tk = &key->conf.key[ALG_TKIP_TEMP_ENCR_KEY];
173 u8 *ta = hdr->addr2; 161 u8 *ta = hdr->addr2;
174 u16 iv16; 162 u16 iv16;
175 u32 iv32; 163 u32 iv32;
@@ -193,14 +181,14 @@ void ieee80211_get_tkip_key(struct ieee80211_key_conf *keyconf,
193 * might occur after the wrap around of iv16 in the key in case of 181 * might occur after the wrap around of iv16 in the key in case of
194 * fragmented packets. */ 182 * fragmented packets. */
195 if (iv16 == 0 || !key->u.tkip.tx.initialized) 183 if (iv16 == 0 || !key->u.tkip.tx.initialized)
196 tkip_mixing_phase1(key, ta, &key->u.tkip.tx, iv32); 184 tkip_mixing_phase1(tk, &key->u.tkip.tx, ta, iv32);
197 185
198 if (type == IEEE80211_TKIP_P1_KEY) { 186 if (type == IEEE80211_TKIP_P1_KEY) {
199 memcpy(outkey, key->u.tkip.tx.p1k, sizeof(u16) * 5); 187 memcpy(outkey, key->u.tkip.tx.p1k, sizeof(u16) * 5);
200 return; 188 return;
201 } 189 }
202 190
203 tkip_mixing_phase2(key, &key->u.tkip.tx, iv16, outkey); 191 tkip_mixing_phase2(tk, &key->u.tkip.tx, iv16, outkey);
204} 192}
205EXPORT_SYMBOL(ieee80211_get_tkip_key); 193EXPORT_SYMBOL(ieee80211_get_tkip_key);
206 194
@@ -214,8 +202,15 @@ void ieee80211_tkip_encrypt_data(struct crypto_blkcipher *tfm,
214 u8 *pos, size_t payload_len, u8 *ta) 202 u8 *pos, size_t payload_len, u8 *ta)
215{ 203{
216 u8 rc4key[16]; 204 u8 rc4key[16];
205 struct tkip_ctx *ctx = &key->u.tkip.tx;
206 const u8 *tk = &key->conf.key[ALG_TKIP_TEMP_ENCR_KEY];
207
208 /* Calculate per-packet key */
209 if (ctx->iv16 == 0 || !ctx->initialized)
210 tkip_mixing_phase1(tk, ctx, ta, ctx->iv32);
211
212 tkip_mixing_phase2(tk, ctx, ctx->iv16, rc4key);
217 213
218 ieee80211_tkip_gen_rc4key(key, ta, rc4key);
219 pos = ieee80211_tkip_add_iv(pos, key, key->u.tkip.tx.iv16); 214 pos = ieee80211_tkip_add_iv(pos, key, key->u.tkip.tx.iv16);
220 ieee80211_wep_encrypt_data(tfm, rc4key, 16, pos, payload_len); 215 ieee80211_wep_encrypt_data(tfm, rc4key, 16, pos, payload_len);
221} 216}
@@ -234,6 +229,7 @@ int ieee80211_tkip_decrypt_data(struct crypto_blkcipher *tfm,
234 u32 iv16; 229 u32 iv16;
235 u8 rc4key[16], keyid, *pos = payload; 230 u8 rc4key[16], keyid, *pos = payload;
236 int res; 231 int res;
232 const u8 *tk = &key->conf.key[ALG_TKIP_TEMP_ENCR_KEY];
237 233
238 if (payload_len < 12) 234 if (payload_len < 12)
239 return -1; 235 return -1;
@@ -284,7 +280,7 @@ int ieee80211_tkip_decrypt_data(struct crypto_blkcipher *tfm,
284 if (!key->u.tkip.rx[queue].initialized || 280 if (!key->u.tkip.rx[queue].initialized ||
285 key->u.tkip.rx[queue].iv32 != iv32) { 281 key->u.tkip.rx[queue].iv32 != iv32) {
286 /* IV16 wrapped around - perform TKIP phase 1 */ 282 /* IV16 wrapped around - perform TKIP phase 1 */
287 tkip_mixing_phase1(key, ta, &key->u.tkip.rx[queue], iv32); 283 tkip_mixing_phase1(tk, &key->u.tkip.rx[queue], ta, iv32);
288#ifdef CONFIG_TKIP_DEBUG 284#ifdef CONFIG_TKIP_DEBUG
289 { 285 {
290 int i; 286 int i;
@@ -317,7 +313,7 @@ int ieee80211_tkip_decrypt_data(struct crypto_blkcipher *tfm,
317 } 313 }
318 } 314 }
319 315
320 tkip_mixing_phase2(key, &key->u.tkip.rx[queue], iv16, rc4key); 316 tkip_mixing_phase2(tk, &key->u.tkip.rx[queue], iv16, rc4key);
321#ifdef CONFIG_TKIP_DEBUG 317#ifdef CONFIG_TKIP_DEBUG
322 { 318 {
323 int i; 319 int i;