.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
---|
1 | 2 | /* |
---|
2 | 3 | * lib80211 crypt: host-based TKIP encryption implementation for lib80211 |
---|
3 | 4 | * |
---|
4 | 5 | * Copyright (c) 2003-2004, Jouni Malinen <j@w1.fi> |
---|
5 | 6 | * 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. |
---|
11 | 7 | */ |
---|
12 | 8 | |
---|
13 | 9 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
---|
14 | 10 | |
---|
15 | 11 | #include <linux/err.h> |
---|
| 12 | +#include <linux/fips.h> |
---|
16 | 13 | #include <linux/module.h> |
---|
17 | 14 | #include <linux/init.h> |
---|
18 | 15 | #include <linux/slab.h> |
---|
.. | .. |
---|
29 | 26 | #include <linux/ieee80211.h> |
---|
30 | 27 | #include <net/iw_handler.h> |
---|
31 | 28 | |
---|
| 29 | +#include <crypto/arc4.h> |
---|
32 | 30 | #include <crypto/hash.h> |
---|
33 | | -#include <crypto/skcipher.h> |
---|
| 31 | +#include <linux/crypto.h> |
---|
34 | 32 | #include <linux/crc32.h> |
---|
35 | 33 | |
---|
36 | 34 | #include <net/lib80211.h> |
---|
.. | .. |
---|
64 | 62 | |
---|
65 | 63 | int key_idx; |
---|
66 | 64 | |
---|
67 | | - struct crypto_skcipher *rx_tfm_arc4; |
---|
| 65 | + struct arc4_ctx rx_ctx_arc4; |
---|
| 66 | + struct arc4_ctx tx_ctx_arc4; |
---|
68 | 67 | struct crypto_shash *rx_tfm_michael; |
---|
69 | | - struct crypto_skcipher *tx_tfm_arc4; |
---|
70 | 68 | struct crypto_shash *tx_tfm_michael; |
---|
71 | 69 | |
---|
72 | 70 | /* scratch buffers for virt_to_page() (crypto API) */ |
---|
.. | .. |
---|
93 | 91 | { |
---|
94 | 92 | struct lib80211_tkip_data *priv; |
---|
95 | 93 | |
---|
| 94 | + if (fips_enabled) |
---|
| 95 | + return NULL; |
---|
| 96 | + |
---|
96 | 97 | priv = kzalloc(sizeof(*priv), GFP_ATOMIC); |
---|
97 | 98 | if (priv == NULL) |
---|
98 | 99 | goto fail; |
---|
99 | 100 | |
---|
100 | 101 | priv->key_idx = key_idx; |
---|
101 | 102 | |
---|
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 | | - |
---|
109 | 103 | priv->tx_tfm_michael = crypto_alloc_shash("michael_mic", 0, 0); |
---|
110 | 104 | if (IS_ERR(priv->tx_tfm_michael)) { |
---|
111 | 105 | 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; |
---|
119 | 106 | goto fail; |
---|
120 | 107 | } |
---|
121 | 108 | |
---|
.. | .. |
---|
130 | 117 | fail: |
---|
131 | 118 | if (priv) { |
---|
132 | 119 | crypto_free_shash(priv->tx_tfm_michael); |
---|
133 | | - crypto_free_skcipher(priv->tx_tfm_arc4); |
---|
134 | 120 | crypto_free_shash(priv->rx_tfm_michael); |
---|
135 | | - crypto_free_skcipher(priv->rx_tfm_arc4); |
---|
136 | 121 | kfree(priv); |
---|
137 | 122 | } |
---|
138 | 123 | |
---|
.. | .. |
---|
144 | 129 | struct lib80211_tkip_data *_priv = priv; |
---|
145 | 130 | if (_priv) { |
---|
146 | 131 | crypto_free_shash(_priv->tx_tfm_michael); |
---|
147 | | - crypto_free_skcipher(_priv->tx_tfm_arc4); |
---|
148 | 132 | crypto_free_shash(_priv->rx_tfm_michael); |
---|
149 | | - crypto_free_skcipher(_priv->rx_tfm_arc4); |
---|
150 | 133 | } |
---|
151 | | - kfree(priv); |
---|
| 134 | + kfree_sensitive(priv); |
---|
152 | 135 | } |
---|
153 | 136 | |
---|
154 | 137 | static inline u16 RotR1(u16 val) |
---|
.. | .. |
---|
344 | 327 | static int lib80211_tkip_encrypt(struct sk_buff *skb, int hdr_len, void *priv) |
---|
345 | 328 | { |
---|
346 | 329 | struct lib80211_tkip_data *tkey = priv; |
---|
347 | | - SKCIPHER_REQUEST_ON_STACK(req, tkey->tx_tfm_arc4); |
---|
348 | 330 | int len; |
---|
349 | 331 | u8 rc4key[16], *pos, *icv; |
---|
350 | 332 | u32 crc; |
---|
351 | | - struct scatterlist sg; |
---|
352 | | - int err; |
---|
353 | 333 | |
---|
354 | 334 | if (tkey->flags & IEEE80211_CRYPTO_TKIP_COUNTERMEASURES) { |
---|
355 | 335 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; |
---|
.. | .. |
---|
374 | 354 | icv[2] = crc >> 16; |
---|
375 | 355 | icv[3] = crc >> 24; |
---|
376 | 356 | |
---|
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; |
---|
385 | 361 | } |
---|
386 | 362 | |
---|
387 | 363 | /* |
---|
.. | .. |
---|
400 | 376 | static int lib80211_tkip_decrypt(struct sk_buff *skb, int hdr_len, void *priv) |
---|
401 | 377 | { |
---|
402 | 378 | struct lib80211_tkip_data *tkey = priv; |
---|
403 | | - SKCIPHER_REQUEST_ON_STACK(req, tkey->rx_tfm_arc4); |
---|
404 | 379 | u8 rc4key[16]; |
---|
405 | 380 | u8 keyidx, *pos; |
---|
406 | 381 | u32 iv32; |
---|
.. | .. |
---|
408 | 383 | struct ieee80211_hdr *hdr; |
---|
409 | 384 | u8 icv[4]; |
---|
410 | 385 | u32 crc; |
---|
411 | | - struct scatterlist sg; |
---|
412 | 386 | int plen; |
---|
413 | | - int err; |
---|
414 | 387 | |
---|
415 | 388 | hdr = (struct ieee80211_hdr *)skb->data; |
---|
416 | 389 | |
---|
.. | .. |
---|
463 | 436 | |
---|
464 | 437 | plen = skb->len - hdr_len - 12; |
---|
465 | 438 | |
---|
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); |
---|
478 | 441 | |
---|
479 | 442 | crc = ~crc32_le(~0, pos, plen); |
---|
480 | 443 | icv[0] = crc; |
---|
.. | .. |
---|
520 | 483 | } |
---|
521 | 484 | |
---|
522 | 485 | desc->tfm = tfm_michael; |
---|
523 | | - desc->flags = 0; |
---|
524 | 486 | |
---|
525 | 487 | if (crypto_shash_setkey(tfm_michael, key, 8)) |
---|
526 | 488 | return -1; |
---|
.. | .. |
---|
660 | 622 | struct lib80211_tkip_data *tkey = priv; |
---|
661 | 623 | int keyidx; |
---|
662 | 624 | 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; |
---|
664 | 626 | 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; |
---|
666 | 628 | |
---|
667 | 629 | keyidx = tkey->key_idx; |
---|
668 | 630 | memset(tkey, 0, sizeof(*tkey)); |
---|
669 | 631 | tkey->key_idx = keyidx; |
---|
670 | 632 | tkey->tx_tfm_michael = tfm; |
---|
671 | | - tkey->tx_tfm_arc4 = tfm2; |
---|
| 633 | + tkey->tx_ctx_arc4 = *tfm2; |
---|
672 | 634 | tkey->rx_tfm_michael = tfm3; |
---|
673 | | - tkey->rx_tfm_arc4 = tfm4; |
---|
| 635 | + tkey->rx_ctx_arc4 = *tfm4; |
---|
674 | 636 | if (len == TKIP_KEY_LEN) { |
---|
675 | 637 | memcpy(tkey->key, key, TKIP_KEY_LEN); |
---|
676 | 638 | tkey->key_set = 1; |
---|