@@ -30,30 +30,9 @@ int ieee80211_wep_init(struct ieee80211_local *local)
3030 /* start WEP IV from a random value */
3131 get_random_bytes (& local -> wep_iv , IEEE80211_WEP_IV_LEN );
3232
33- local -> wep_tx_tfm = crypto_alloc_cipher ("arc4" , 0 , 0 );
34- if (IS_ERR (local -> wep_tx_tfm )) {
35- local -> wep_rx_tfm = ERR_PTR (- EINVAL );
36- return PTR_ERR (local -> wep_tx_tfm );
37- }
38-
39- local -> wep_rx_tfm = crypto_alloc_cipher ("arc4" , 0 , 0 );
40- if (IS_ERR (local -> wep_rx_tfm )) {
41- crypto_free_cipher (local -> wep_tx_tfm );
42- local -> wep_tx_tfm = ERR_PTR (- EINVAL );
43- return PTR_ERR (local -> wep_rx_tfm );
44- }
45-
4633 return 0 ;
4734}
4835
49- void ieee80211_wep_free (struct ieee80211_local * local )
50- {
51- if (!IS_ERR (local -> wep_tx_tfm ))
52- crypto_free_cipher (local -> wep_tx_tfm );
53- if (!IS_ERR (local -> wep_rx_tfm ))
54- crypto_free_cipher (local -> wep_rx_tfm );
55- }
56-
5736static inline bool ieee80211_wep_weak_iv (u32 iv , int keylen )
5837{
5938 /*
@@ -131,21 +110,17 @@ static void ieee80211_wep_remove_iv(struct ieee80211_local *local,
131110/* Perform WEP encryption using given key. data buffer must have tailroom
132111 * for 4-byte ICV. data_len must not include this ICV. Note: this function
133112 * does _not_ add IV. data = RC4(data | CRC32(data)) */
134- int ieee80211_wep_encrypt_data (struct crypto_cipher * tfm , u8 * rc4key ,
113+ int ieee80211_wep_encrypt_data (struct arc4_ctx * ctx , u8 * rc4key ,
135114 size_t klen , u8 * data , size_t data_len )
136115{
137116 __le32 icv ;
138- int i ;
139-
140- if (IS_ERR (tfm ))
141- return -1 ;
142117
143118 icv = cpu_to_le32 (~crc32_le (~0 , data , data_len ));
144119 put_unaligned (icv , (__le32 * )(data + data_len ));
145120
146- crypto_cipher_setkey ( tfm , rc4key , klen );
147- for ( i = 0 ; i < data_len + IEEE80211_WEP_ICV_LEN ; i ++ )
148- crypto_cipher_encrypt_one ( tfm , data + i , data + i );
121+ arc4_setkey ( ctx , rc4key , klen );
122+ arc4_crypt ( ctx , data , data , data_len + IEEE80211_WEP_ICV_LEN );
123+ memzero_explicit ( ctx , sizeof ( * ctx ) );
149124
150125 return 0 ;
151126}
@@ -184,26 +159,22 @@ int ieee80211_wep_encrypt(struct ieee80211_local *local,
184159 /* Add room for ICV */
185160 skb_put (skb , IEEE80211_WEP_ICV_LEN );
186161
187- return ieee80211_wep_encrypt_data (local -> wep_tx_tfm , rc4key , keylen + 3 ,
162+ return ieee80211_wep_encrypt_data (& local -> wep_tx_ctx , rc4key , keylen + 3 ,
188163 iv + IEEE80211_WEP_IV_LEN , len );
189164}
190165
191166
192167/* Perform WEP decryption using given key. data buffer includes encrypted
193168 * payload, including 4-byte ICV, but _not_ IV. data_len must not include ICV.
194169 * Return 0 on success and -1 on ICV mismatch. */
195- int ieee80211_wep_decrypt_data (struct crypto_cipher * tfm , u8 * rc4key ,
170+ int ieee80211_wep_decrypt_data (struct arc4_ctx * ctx , u8 * rc4key ,
196171 size_t klen , u8 * data , size_t data_len )
197172{
198173 __le32 crc ;
199- int i ;
200-
201- if (IS_ERR (tfm ))
202- return -1 ;
203174
204- crypto_cipher_setkey ( tfm , rc4key , klen );
205- for ( i = 0 ; i < data_len + IEEE80211_WEP_ICV_LEN ; i ++ )
206- crypto_cipher_decrypt_one ( tfm , data + i , data + i );
175+ arc4_setkey ( ctx , rc4key , klen );
176+ arc4_crypt ( ctx , data , data , data_len + IEEE80211_WEP_ICV_LEN );
177+ memzero_explicit ( ctx , sizeof ( * ctx ) );
207178
208179 crc = cpu_to_le32 (~crc32_le (~0 , data , data_len ));
209180 if (memcmp (& crc , data + data_len , IEEE80211_WEP_ICV_LEN ) != 0 )
@@ -256,7 +227,7 @@ static int ieee80211_wep_decrypt(struct ieee80211_local *local,
256227 /* Copy rest of the WEP key (the secret part) */
257228 memcpy (rc4key + 3 , key -> conf .key , key -> conf .keylen );
258229
259- if (ieee80211_wep_decrypt_data (local -> wep_rx_tfm , rc4key , klen ,
230+ if (ieee80211_wep_decrypt_data (& local -> wep_rx_ctx , rc4key , klen ,
260231 skb -> data + hdrlen +
261232 IEEE80211_WEP_IV_LEN , len ))
262233 ret = -1 ;
0 commit comments