Skip to content

Commit af1f3d3

Browse files
Ard Biesheuvelherbertx
authored andcommitted
net/lib80211: move WEP handling to ARC4 library code
The crypto API abstraction is not very useful for invoking ciphers directly, especially in the case of arc4, which only has a generic implementation in C. So let's invoke the library code directly. Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
1 parent 5fdb373 commit af1f3d3

File tree

2 files changed

+14
-38
lines changed

2 files changed

+14
-38
lines changed

net/wireless/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@ config LIB80211
212212

213213
config LIB80211_CRYPT_WEP
214214
tristate
215+
select CRYPTO_LIB_ARC4
215216

216217
config LIB80211_CRYPT_CCMP
217218
tristate

net/wireless/lib80211_crypt_wep.c

Lines changed: 13 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
*/
1212

1313
#include <linux/err.h>
14+
#include <linux/fips.h>
1415
#include <linux/module.h>
1516
#include <linux/init.h>
1617
#include <linux/slab.h>
@@ -22,7 +23,7 @@
2223

2324
#include <net/lib80211.h>
2425

25-
#include <linux/crypto.h>
26+
#include <crypto/arc4.h>
2627
#include <linux/crc32.h>
2728

2829
MODULE_AUTHOR("Jouni Malinen");
@@ -35,52 +36,31 @@ struct lib80211_wep_data {
3536
u8 key[WEP_KEY_LEN + 1];
3637
u8 key_len;
3738
u8 key_idx;
38-
struct crypto_cipher *tx_tfm;
39-
struct crypto_cipher *rx_tfm;
39+
struct arc4_ctx tx_ctx;
40+
struct arc4_ctx rx_ctx;
4041
};
4142

4243
static void *lib80211_wep_init(int keyidx)
4344
{
4445
struct lib80211_wep_data *priv;
4546

47+
if (fips_enabled)
48+
return NULL;
49+
4650
priv = kzalloc(sizeof(*priv), GFP_ATOMIC);
4751
if (priv == NULL)
48-
goto fail;
52+
return NULL;
4953
priv->key_idx = keyidx;
5054

51-
priv->tx_tfm = crypto_alloc_cipher("arc4", 0, 0);
52-
if (IS_ERR(priv->tx_tfm)) {
53-
priv->tx_tfm = NULL;
54-
goto fail;
55-
}
56-
57-
priv->rx_tfm = crypto_alloc_cipher("arc4", 0, 0);
58-
if (IS_ERR(priv->rx_tfm)) {
59-
priv->rx_tfm = NULL;
60-
goto fail;
61-
}
6255
/* start WEP IV from a random value */
6356
get_random_bytes(&priv->iv, 4);
6457

6558
return priv;
66-
67-
fail:
68-
if (priv) {
69-
crypto_free_cipher(priv->tx_tfm);
70-
crypto_free_cipher(priv->rx_tfm);
71-
kfree(priv);
72-
}
73-
return NULL;
7459
}
7560

7661
static void lib80211_wep_deinit(void *priv)
7762
{
78-
struct lib80211_wep_data *_priv = priv;
79-
if (_priv) {
80-
crypto_free_cipher(_priv->tx_tfm);
81-
crypto_free_cipher(_priv->rx_tfm);
82-
}
83-
kfree(priv);
63+
kzfree(priv);
8464
}
8565

8666
/* Add WEP IV/key info to a frame that has at least 4 bytes of headroom */
@@ -132,7 +112,6 @@ static int lib80211_wep_encrypt(struct sk_buff *skb, int hdr_len, void *priv)
132112
u32 crc, klen, len;
133113
u8 *pos, *icv;
134114
u8 key[WEP_KEY_LEN + 3];
135-
int i;
136115

137116
/* other checks are in lib80211_wep_build_iv */
138117
if (skb_tailroom(skb) < 4)
@@ -160,10 +139,8 @@ static int lib80211_wep_encrypt(struct sk_buff *skb, int hdr_len, void *priv)
160139
icv[2] = crc >> 16;
161140
icv[3] = crc >> 24;
162141

163-
crypto_cipher_setkey(wep->tx_tfm, key, klen);
164-
165-
for (i = 0; i < len + 4; i++)
166-
crypto_cipher_encrypt_one(wep->tx_tfm, pos + i, pos + i);
142+
arc4_setkey(&wep->tx_ctx, key, klen);
143+
arc4_crypt(&wep->tx_ctx, pos, pos, len + 4);
167144

168145
return 0;
169146
}
@@ -181,7 +158,6 @@ static int lib80211_wep_decrypt(struct sk_buff *skb, int hdr_len, void *priv)
181158
u32 crc, klen, plen;
182159
u8 key[WEP_KEY_LEN + 3];
183160
u8 keyidx, *pos, icv[4];
184-
int i;
185161

186162
if (skb->len < hdr_len + 8)
187163
return -1;
@@ -202,9 +178,8 @@ static int lib80211_wep_decrypt(struct sk_buff *skb, int hdr_len, void *priv)
202178
/* Apply RC4 to data and compute CRC32 over decrypted data */
203179
plen = skb->len - hdr_len - 8;
204180

205-
crypto_cipher_setkey(wep->rx_tfm, key, klen);
206-
for (i = 0; i < plen + 4; i++)
207-
crypto_cipher_decrypt_one(wep->rx_tfm, pos + i, pos + i);
181+
arc4_setkey(&wep->rx_ctx, key, klen);
182+
arc4_crypt(&wep->rx_ctx, pos, pos, plen + 4);
208183

209184
crc = ~crc32_le(~0, pos, plen);
210185
icv[0] = crc;

0 commit comments

Comments
 (0)