@@ -71,10 +71,12 @@ static u16 tkipS(u16 val)
7171 * TSC = TKIP sequence counter (48 bits, only 32 msb bits used)
7272 * P1K: 80 bits
7373 */
74- static void tkip_mixing_phase1 (const u8 * ta , const u8 * tk , u32 tsc_IV32 ,
75- u16 * p1k )
74+ static void tkip_mixing_phase1 (struct ieee80211_key * key , const u8 * ta ,
75+ struct tkip_ctx * ctx , u32 tsc_IV32 )
7676{
7777 int i , j ;
78+ const u8 * tk = & key -> conf .key [ALG_TKIP_TEMP_ENCR_KEY ];
79+ u16 * p1k = ctx -> p1k ;
7880
7981 p1k [0 ] = tsc_IV32 & 0xFFFF ;
8082 p1k [1 ] = tsc_IV32 >> 16 ;
@@ -90,6 +92,7 @@ static void tkip_mixing_phase1(const u8 *ta, const u8 *tk, u32 tsc_IV32,
9092 p1k [3 ] += tkipS (p1k [2 ] ^ get_unaligned_le16 (tk + 12 + j ));
9193 p1k [4 ] += tkipS (p1k [3 ] ^ get_unaligned_le16 (tk + 0 + j )) + i ;
9294 }
95+ ctx -> initialized = 1 ;
9396}
9497
9598static void tkip_mixing_phase2 (const u16 * p1k , const u8 * tk , u16 tsc_IV16 ,
@@ -146,12 +149,8 @@ static void ieee80211_tkip_gen_rc4key(struct ieee80211_key *key, u8 *ta,
146149 u8 * rc4key )
147150{
148151 /* Calculate per-packet key */
149- if (key -> u .tkip .tx .iv16 == 0 || !key -> u .tkip .tx .initialized ) {
150- /* IV16 wrapped around - perform TKIP phase 1 */
151- tkip_mixing_phase1 (ta , & key -> conf .key [ALG_TKIP_TEMP_ENCR_KEY ],
152- key -> u .tkip .tx .iv32 , key -> u .tkip .tx .p1k );
153- key -> u .tkip .tx .initialized = 1 ;
154- }
152+ if (key -> u .tkip .tx .iv16 == 0 || !key -> u .tkip .tx .initialized )
153+ tkip_mixing_phase1 (key , ta , & key -> u .tkip .tx , key -> u .tkip .tx .iv32 );
155154
156155 tkip_mixing_phase2 (key -> u .tkip .tx .p1k ,
157156 & key -> conf .key [ALG_TKIP_TEMP_ENCR_KEY ],
@@ -190,12 +189,8 @@ void ieee80211_get_tkip_key(struct ieee80211_key_conf *keyconf,
190189 /* Update the p1k only when the iv16 in the packet wraps around, this
191190 * might occur after the wrap around of iv16 in the key in case of
192191 * fragmented packets. */
193- if (iv16 == 0 || !key -> u .tkip .tx .initialized ) {
194- /* IV16 wrapped around - perform TKIP phase 1 */
195- tkip_mixing_phase1 (ta , & key -> conf .key [ALG_TKIP_TEMP_ENCR_KEY ],
196- iv32 , key -> u .tkip .tx .p1k );
197- key -> u .tkip .tx .initialized = 1 ;
198- }
192+ if (iv16 == 0 || !key -> u .tkip .tx .initialized )
193+ tkip_mixing_phase1 (key , ta , & key -> u .tkip .tx , iv32 );
199194
200195 if (type == IEEE80211_TKIP_P1_KEY ) {
201196 memcpy (outkey , key -> u .tkip .tx .p1k , sizeof (u16 ) * 5 );
@@ -286,10 +281,8 @@ int ieee80211_tkip_decrypt_data(struct crypto_blkcipher *tfm,
286281
287282 if (!key -> u .tkip .rx [queue ].initialized ||
288283 key -> u .tkip .rx [queue ].iv32 != iv32 ) {
289- key -> u .tkip .rx [queue ].initialized = 1 ;
290284 /* IV16 wrapped around - perform TKIP phase 1 */
291- tkip_mixing_phase1 (ta , & key -> conf .key [ALG_TKIP_TEMP_ENCR_KEY ],
292- iv32 , key -> u .tkip .rx [queue ].p1k );
285+ tkip_mixing_phase1 (key , ta , & key -> u .tkip .rx [queue ], iv32 );
293286#ifdef CONFIG_TKIP_DEBUG
294287 {
295288 int i ;
0 commit comments