hc
2024-10-22 8ac6c7a54ed1b98d142dce24b11c6de6a1e239a5
kernel/net/wireless/lib80211_crypt_tkip.c
....@@ -1,18 +1,15 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * lib80211 crypt: host-based TKIP encryption implementation for lib80211
34 *
45 * Copyright (c) 2003-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 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
1410
1511 #include <linux/err.h>
12
+#include <linux/fips.h>
1613 #include <linux/module.h>
1714 #include <linux/init.h>
1815 #include <linux/slab.h>
....@@ -29,8 +26,9 @@
2926 #include <linux/ieee80211.h>
3027 #include <net/iw_handler.h>
3128
29
+#include <crypto/arc4.h>
3230 #include <crypto/hash.h>
33
-#include <crypto/skcipher.h>
31
+#include <linux/crypto.h>
3432 #include <linux/crc32.h>
3533
3634 #include <net/lib80211.h>
....@@ -64,9 +62,9 @@
6462
6563 int key_idx;
6664
67
- struct crypto_skcipher *rx_tfm_arc4;
65
+ struct arc4_ctx rx_ctx_arc4;
66
+ struct arc4_ctx tx_ctx_arc4;
6867 struct crypto_shash *rx_tfm_michael;
69
- struct crypto_skcipher *tx_tfm_arc4;
7068 struct crypto_shash *tx_tfm_michael;
7169
7270 /* scratch buffers for virt_to_page() (crypto API) */
....@@ -93,29 +91,18 @@
9391 {
9492 struct lib80211_tkip_data *priv;
9593
94
+ if (fips_enabled)
95
+ return NULL;
96
+
9697 priv = kzalloc(sizeof(*priv), GFP_ATOMIC);
9798 if (priv == NULL)
9899 goto fail;
99100
100101 priv->key_idx = key_idx;
101102
102
- priv->tx_tfm_arc4 = crypto_alloc_skcipher("ecb(arc4)", 0,
103
- CRYPTO_ALG_ASYNC);
104
- if (IS_ERR(priv->tx_tfm_arc4)) {
105
- priv->tx_tfm_arc4 = NULL;
106
- goto fail;
107
- }
108
-
109103 priv->tx_tfm_michael = crypto_alloc_shash("michael_mic", 0, 0);
110104 if (IS_ERR(priv->tx_tfm_michael)) {
111105 priv->tx_tfm_michael = NULL;
112
- goto fail;
113
- }
114
-
115
- priv->rx_tfm_arc4 = crypto_alloc_skcipher("ecb(arc4)", 0,
116
- CRYPTO_ALG_ASYNC);
117
- if (IS_ERR(priv->rx_tfm_arc4)) {
118
- priv->rx_tfm_arc4 = NULL;
119106 goto fail;
120107 }
121108
....@@ -130,9 +117,7 @@
130117 fail:
131118 if (priv) {
132119 crypto_free_shash(priv->tx_tfm_michael);
133
- crypto_free_skcipher(priv->tx_tfm_arc4);
134120 crypto_free_shash(priv->rx_tfm_michael);
135
- crypto_free_skcipher(priv->rx_tfm_arc4);
136121 kfree(priv);
137122 }
138123
....@@ -144,11 +129,9 @@
144129 struct lib80211_tkip_data *_priv = priv;
145130 if (_priv) {
146131 crypto_free_shash(_priv->tx_tfm_michael);
147
- crypto_free_skcipher(_priv->tx_tfm_arc4);
148132 crypto_free_shash(_priv->rx_tfm_michael);
149
- crypto_free_skcipher(_priv->rx_tfm_arc4);
150133 }
151
- kfree(priv);
134
+ kfree_sensitive(priv);
152135 }
153136
154137 static inline u16 RotR1(u16 val)
....@@ -344,12 +327,9 @@
344327 static int lib80211_tkip_encrypt(struct sk_buff *skb, int hdr_len, void *priv)
345328 {
346329 struct lib80211_tkip_data *tkey = priv;
347
- SKCIPHER_REQUEST_ON_STACK(req, tkey->tx_tfm_arc4);
348330 int len;
349331 u8 rc4key[16], *pos, *icv;
350332 u32 crc;
351
- struct scatterlist sg;
352
- int err;
353333
354334 if (tkey->flags & IEEE80211_CRYPTO_TKIP_COUNTERMEASURES) {
355335 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
....@@ -374,14 +354,10 @@
374354 icv[2] = crc >> 16;
375355 icv[3] = crc >> 24;
376356
377
- crypto_skcipher_setkey(tkey->tx_tfm_arc4, rc4key, 16);
378
- sg_init_one(&sg, pos, len + 4);
379
- skcipher_request_set_tfm(req, tkey->tx_tfm_arc4);
380
- skcipher_request_set_callback(req, 0, NULL, NULL);
381
- skcipher_request_set_crypt(req, &sg, &sg, len + 4, NULL);
382
- err = crypto_skcipher_encrypt(req);
383
- skcipher_request_zero(req);
384
- return err;
357
+ arc4_setkey(&tkey->tx_ctx_arc4, rc4key, 16);
358
+ arc4_crypt(&tkey->tx_ctx_arc4, pos, pos, len + 4);
359
+
360
+ return 0;
385361 }
386362
387363 /*
....@@ -400,7 +376,6 @@
400376 static int lib80211_tkip_decrypt(struct sk_buff *skb, int hdr_len, void *priv)
401377 {
402378 struct lib80211_tkip_data *tkey = priv;
403
- SKCIPHER_REQUEST_ON_STACK(req, tkey->rx_tfm_arc4);
404379 u8 rc4key[16];
405380 u8 keyidx, *pos;
406381 u32 iv32;
....@@ -408,9 +383,7 @@
408383 struct ieee80211_hdr *hdr;
409384 u8 icv[4];
410385 u32 crc;
411
- struct scatterlist sg;
412386 int plen;
413
- int err;
414387
415388 hdr = (struct ieee80211_hdr *)skb->data;
416389
....@@ -463,18 +436,8 @@
463436
464437 plen = skb->len - hdr_len - 12;
465438
466
- crypto_skcipher_setkey(tkey->rx_tfm_arc4, rc4key, 16);
467
- sg_init_one(&sg, pos, plen + 4);
468
- skcipher_request_set_tfm(req, tkey->rx_tfm_arc4);
469
- skcipher_request_set_callback(req, 0, NULL, NULL);
470
- skcipher_request_set_crypt(req, &sg, &sg, plen + 4, NULL);
471
- err = crypto_skcipher_decrypt(req);
472
- skcipher_request_zero(req);
473
- if (err) {
474
- net_dbg_ratelimited("TKIP: failed to decrypt received packet from %pM\n",
475
- hdr->addr2);
476
- return -7;
477
- }
439
+ arc4_setkey(&tkey->rx_ctx_arc4, rc4key, 16);
440
+ arc4_crypt(&tkey->rx_ctx_arc4, pos, pos, plen + 4);
478441
479442 crc = ~crc32_le(~0, pos, plen);
480443 icv[0] = crc;
....@@ -520,7 +483,6 @@
520483 }
521484
522485 desc->tfm = tfm_michael;
523
- desc->flags = 0;
524486
525487 if (crypto_shash_setkey(tfm_michael, key, 8))
526488 return -1;
....@@ -660,17 +622,17 @@
660622 struct lib80211_tkip_data *tkey = priv;
661623 int keyidx;
662624 struct crypto_shash *tfm = tkey->tx_tfm_michael;
663
- struct crypto_skcipher *tfm2 = tkey->tx_tfm_arc4;
625
+ struct arc4_ctx *tfm2 = &tkey->tx_ctx_arc4;
664626 struct crypto_shash *tfm3 = tkey->rx_tfm_michael;
665
- struct crypto_skcipher *tfm4 = tkey->rx_tfm_arc4;
627
+ struct arc4_ctx *tfm4 = &tkey->rx_ctx_arc4;
666628
667629 keyidx = tkey->key_idx;
668630 memset(tkey, 0, sizeof(*tkey));
669631 tkey->key_idx = keyidx;
670632 tkey->tx_tfm_michael = tfm;
671
- tkey->tx_tfm_arc4 = tfm2;
633
+ tkey->tx_ctx_arc4 = *tfm2;
672634 tkey->rx_tfm_michael = tfm3;
673
- tkey->rx_tfm_arc4 = tfm4;
635
+ tkey->rx_ctx_arc4 = *tfm4;
674636 if (len == TKIP_KEY_LEN) {
675637 memcpy(tkey->key, key, TKIP_KEY_LEN);
676638 tkey->key_set = 1;