hc
2024-10-22 8ac6c7a54ed1b98d142dce24b11c6de6a1e239a5
kernel/net/wireless/lib80211_crypt_wep.c
....@@ -1,16 +1,13 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * lib80211 crypt: host-based WEP encryption implementation for lib80211
34 *
45 * Copyright (c) 2002-2004, Jouni Malinen <j@w1.fi>
56 * Copyright (c) 2008, John W. Linville <linville@tuxdriver.com>
6
- *
7
- * This program is free software; you can redistribute it and/or modify
8
- * it under the terms of the GNU General Public License version 2 as
9
- * published by the Free Software Foundation. See README and COPYING for
10
- * more details.
117 */
128
139 #include <linux/err.h>
10
+#include <linux/fips.h>
1411 #include <linux/module.h>
1512 #include <linux/init.h>
1613 #include <linux/slab.h>
....@@ -22,7 +19,7 @@
2219
2320 #include <net/lib80211.h>
2421
25
-#include <crypto/skcipher.h>
22
+#include <crypto/arc4.h>
2623 #include <linux/crc32.h>
2724
2825 MODULE_AUTHOR("Jouni Malinen");
....@@ -35,52 +32,31 @@
3532 u8 key[WEP_KEY_LEN + 1];
3633 u8 key_len;
3734 u8 key_idx;
38
- struct crypto_skcipher *tx_tfm;
39
- struct crypto_skcipher *rx_tfm;
35
+ struct arc4_ctx tx_ctx;
36
+ struct arc4_ctx rx_ctx;
4037 };
4138
4239 static void *lib80211_wep_init(int keyidx)
4340 {
4441 struct lib80211_wep_data *priv;
4542
43
+ if (fips_enabled)
44
+ return NULL;
45
+
4646 priv = kzalloc(sizeof(*priv), GFP_ATOMIC);
4747 if (priv == NULL)
48
- goto fail;
48
+ return NULL;
4949 priv->key_idx = keyidx;
5050
51
- priv->tx_tfm = crypto_alloc_skcipher("ecb(arc4)", 0, CRYPTO_ALG_ASYNC);
52
- if (IS_ERR(priv->tx_tfm)) {
53
- priv->tx_tfm = NULL;
54
- goto fail;
55
- }
56
-
57
- priv->rx_tfm = crypto_alloc_skcipher("ecb(arc4)", 0, CRYPTO_ALG_ASYNC);
58
- if (IS_ERR(priv->rx_tfm)) {
59
- priv->rx_tfm = NULL;
60
- goto fail;
61
- }
6251 /* start WEP IV from a random value */
6352 get_random_bytes(&priv->iv, 4);
6453
6554 return priv;
66
-
67
- fail:
68
- if (priv) {
69
- crypto_free_skcipher(priv->tx_tfm);
70
- crypto_free_skcipher(priv->rx_tfm);
71
- kfree(priv);
72
- }
73
- return NULL;
7455 }
7556
7657 static void lib80211_wep_deinit(void *priv)
7758 {
78
- struct lib80211_wep_data *_priv = priv;
79
- if (_priv) {
80
- crypto_free_skcipher(_priv->tx_tfm);
81
- crypto_free_skcipher(_priv->rx_tfm);
82
- }
83
- kfree(priv);
59
+ kfree_sensitive(priv);
8460 }
8561
8662 /* Add WEP IV/key info to a frame that has at least 4 bytes of headroom */
....@@ -129,12 +105,9 @@
129105 static int lib80211_wep_encrypt(struct sk_buff *skb, int hdr_len, void *priv)
130106 {
131107 struct lib80211_wep_data *wep = priv;
132
- SKCIPHER_REQUEST_ON_STACK(req, wep->tx_tfm);
133108 u32 crc, klen, len;
134109 u8 *pos, *icv;
135
- struct scatterlist sg;
136110 u8 key[WEP_KEY_LEN + 3];
137
- int err;
138111
139112 /* other checks are in lib80211_wep_build_iv */
140113 if (skb_tailroom(skb) < 4)
....@@ -162,14 +135,10 @@
162135 icv[2] = crc >> 16;
163136 icv[3] = crc >> 24;
164137
165
- crypto_skcipher_setkey(wep->tx_tfm, key, klen);
166
- sg_init_one(&sg, pos, len + 4);
167
- skcipher_request_set_tfm(req, wep->tx_tfm);
168
- skcipher_request_set_callback(req, 0, NULL, NULL);
169
- skcipher_request_set_crypt(req, &sg, &sg, len + 4, NULL);
170
- err = crypto_skcipher_encrypt(req);
171
- skcipher_request_zero(req);
172
- return err;
138
+ arc4_setkey(&wep->tx_ctx, key, klen);
139
+ arc4_crypt(&wep->tx_ctx, pos, pos, len + 4);
140
+
141
+ return 0;
173142 }
174143
175144 /* Perform WEP decryption on given buffer. Buffer includes whole WEP part of
....@@ -182,12 +151,9 @@
182151 static int lib80211_wep_decrypt(struct sk_buff *skb, int hdr_len, void *priv)
183152 {
184153 struct lib80211_wep_data *wep = priv;
185
- SKCIPHER_REQUEST_ON_STACK(req, wep->rx_tfm);
186154 u32 crc, klen, plen;
187155 u8 key[WEP_KEY_LEN + 3];
188156 u8 keyidx, *pos, icv[4];
189
- struct scatterlist sg;
190
- int err;
191157
192158 if (skb->len < hdr_len + 8)
193159 return -1;
....@@ -208,15 +174,8 @@
208174 /* Apply RC4 to data and compute CRC32 over decrypted data */
209175 plen = skb->len - hdr_len - 8;
210176
211
- crypto_skcipher_setkey(wep->rx_tfm, key, klen);
212
- sg_init_one(&sg, pos, plen + 4);
213
- skcipher_request_set_tfm(req, wep->rx_tfm);
214
- skcipher_request_set_callback(req, 0, NULL, NULL);
215
- skcipher_request_set_crypt(req, &sg, &sg, plen + 4, NULL);
216
- err = crypto_skcipher_decrypt(req);
217
- skcipher_request_zero(req);
218
- if (err)
219
- return -7;
177
+ arc4_setkey(&wep->rx_ctx, key, klen);
178
+ arc4_crypt(&wep->rx_ctx, pos, pos, plen + 4);
220179
221180 crc = ~crc32_le(~0, pos, plen);
222181 icv[0] = crc;