hc
2024-09-20 a36159eec6ca17402b0e146b86efaf76568dc353
kernel/net/mac80211/wep.c
....@@ -1,11 +1,8 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * Software WEP encryption implementation
34 * Copyright 2002, Jouni Malinen <jkmaline@cc.hut.fi>
45 * Copyright 2003, Instant802 Networks, Inc.
5
- *
6
- * This program is free software; you can redistribute it and/or modify
7
- * it under the terms of the GNU General Public License version 2 as
8
- * published by the Free Software Foundation.
96 */
107
118 #include <linux/netdevice.h>
....@@ -25,33 +22,10 @@
2522 #include "wep.h"
2623
2724
28
-int ieee80211_wep_init(struct ieee80211_local *local)
25
+void ieee80211_wep_init(struct ieee80211_local *local)
2926 {
3027 /* start WEP IV from a random value */
3128 get_random_bytes(&local->wep_iv, IEEE80211_WEP_IV_LEN);
32
-
33
- local->wep_tx_tfm = crypto_alloc_cipher("arc4", 0, CRYPTO_ALG_ASYNC);
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, CRYPTO_ALG_ASYNC);
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
-
46
- return 0;
47
-}
48
-
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);
5529 }
5630
5731 static inline bool ieee80211_wep_weak_iv(u32 iv, int keylen)
....@@ -131,21 +105,17 @@
131105 /* Perform WEP encryption using given key. data buffer must have tailroom
132106 * for 4-byte ICV. data_len must not include this ICV. Note: this function
133107 * does _not_ add IV. data = RC4(data | CRC32(data)) */
134
-int ieee80211_wep_encrypt_data(struct crypto_cipher *tfm, u8 *rc4key,
108
+int ieee80211_wep_encrypt_data(struct arc4_ctx *ctx, u8 *rc4key,
135109 size_t klen, u8 *data, size_t data_len)
136110 {
137111 __le32 icv;
138
- int i;
139
-
140
- if (IS_ERR(tfm))
141
- return -1;
142112
143113 icv = cpu_to_le32(~crc32_le(~0, data, data_len));
144114 put_unaligned(icv, (__le32 *)(data + data_len));
145115
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);
116
+ arc4_setkey(ctx, rc4key, klen);
117
+ arc4_crypt(ctx, data, data, data_len + IEEE80211_WEP_ICV_LEN);
118
+ memzero_explicit(ctx, sizeof(*ctx));
149119
150120 return 0;
151121 }
....@@ -184,7 +154,7 @@
184154 /* Add room for ICV */
185155 skb_put(skb, IEEE80211_WEP_ICV_LEN);
186156
187
- return ieee80211_wep_encrypt_data(local->wep_tx_tfm, rc4key, keylen + 3,
157
+ return ieee80211_wep_encrypt_data(&local->wep_tx_ctx, rc4key, keylen + 3,
188158 iv + IEEE80211_WEP_IV_LEN, len);
189159 }
190160
....@@ -192,18 +162,14 @@
192162 /* Perform WEP decryption using given key. data buffer includes encrypted
193163 * payload, including 4-byte ICV, but _not_ IV. data_len must not include ICV.
194164 * Return 0 on success and -1 on ICV mismatch. */
195
-int ieee80211_wep_decrypt_data(struct crypto_cipher *tfm, u8 *rc4key,
165
+int ieee80211_wep_decrypt_data(struct arc4_ctx *ctx, u8 *rc4key,
196166 size_t klen, u8 *data, size_t data_len)
197167 {
198168 __le32 crc;
199
- int i;
200169
201
- if (IS_ERR(tfm))
202
- return -1;
203
-
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);
170
+ arc4_setkey(ctx, rc4key, klen);
171
+ arc4_crypt(ctx, data, data, data_len + IEEE80211_WEP_ICV_LEN);
172
+ memzero_explicit(ctx, sizeof(*ctx));
207173
208174 crc = cpu_to_le32(~crc32_le(~0, data, data_len));
209175 if (memcmp(&crc, data + data_len, IEEE80211_WEP_ICV_LEN) != 0)
....@@ -256,7 +222,7 @@
256222 /* Copy rest of the WEP key (the secret part) */
257223 memcpy(rc4key + 3, key->conf.key, key->conf.keylen);
258224
259
- if (ieee80211_wep_decrypt_data(local->wep_rx_tfm, rc4key, klen,
225
+ if (ieee80211_wep_decrypt_data(&local->wep_rx_ctx, rc4key, klen,
260226 skb->data + hdrlen +
261227 IEEE80211_WEP_IV_LEN, len))
262228 ret = -1;