Skip to content

Commit a1d3839

Browse files
committed
staging: rtl8192e: Replace uses of obsolete blkcipher and hash
The interfaces blkcipher and hash are obsolete. This patch replaces them with skcipher and ahash respectively. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au> Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent fdb89b1 commit a1d3839

File tree

2 files changed

+82
-65
lines changed

2 files changed

+82
-65
lines changed

drivers/staging/rtl8192e/rtllib_crypt_tkip.c

Lines changed: 54 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
* more details.
1010
*/
1111

12+
#include <crypto/hash.h>
13+
#include <crypto/skcipher.h>
1214
#include <linux/module.h>
1315
#include <linux/init.h>
1416
#include <linux/slab.h>
@@ -18,7 +20,6 @@
1820
#include <linux/if_ether.h>
1921
#include <linux/if_arp.h>
2022
#include <linux/string.h>
21-
#include <linux/crypto.h>
2223
#include <linux/scatterlist.h>
2324
#include <linux/crc32.h>
2425
#include <linux/etherdevice.h>
@@ -48,10 +49,10 @@ struct rtllib_tkip_data {
4849
u32 dot11RSNAStatsTKIPLocalMICFailures;
4950

5051
int key_idx;
51-
struct crypto_blkcipher *rx_tfm_arc4;
52-
struct crypto_hash *rx_tfm_michael;
53-
struct crypto_blkcipher *tx_tfm_arc4;
54-
struct crypto_hash *tx_tfm_michael;
52+
struct crypto_skcipher *rx_tfm_arc4;
53+
struct crypto_ahash *rx_tfm_michael;
54+
struct crypto_skcipher *tx_tfm_arc4;
55+
struct crypto_ahash *tx_tfm_michael;
5556
/* scratch buffers for virt_to_page() (crypto API) */
5657
u8 rx_hdr[16];
5758
u8 tx_hdr[16];
@@ -65,32 +66,32 @@ static void *rtllib_tkip_init(int key_idx)
6566
if (priv == NULL)
6667
goto fail;
6768
priv->key_idx = key_idx;
68-
priv->tx_tfm_arc4 = crypto_alloc_blkcipher("ecb(arc4)", 0,
69-
CRYPTO_ALG_ASYNC);
69+
priv->tx_tfm_arc4 = crypto_alloc_skcipher("ecb(arc4)", 0,
70+
CRYPTO_ALG_ASYNC);
7071
if (IS_ERR(priv->tx_tfm_arc4)) {
7172
pr_debug("Could not allocate crypto API arc4\n");
7273
priv->tx_tfm_arc4 = NULL;
7374
goto fail;
7475
}
7576

76-
priv->tx_tfm_michael = crypto_alloc_hash("michael_mic", 0,
77-
CRYPTO_ALG_ASYNC);
77+
priv->tx_tfm_michael = crypto_alloc_ahash("michael_mic", 0,
78+
CRYPTO_ALG_ASYNC);
7879
if (IS_ERR(priv->tx_tfm_michael)) {
7980
pr_debug("Could not allocate crypto API michael_mic\n");
8081
priv->tx_tfm_michael = NULL;
8182
goto fail;
8283
}
8384

84-
priv->rx_tfm_arc4 = crypto_alloc_blkcipher("ecb(arc4)", 0,
85-
CRYPTO_ALG_ASYNC);
85+
priv->rx_tfm_arc4 = crypto_alloc_skcipher("ecb(arc4)", 0,
86+
CRYPTO_ALG_ASYNC);
8687
if (IS_ERR(priv->rx_tfm_arc4)) {
8788
pr_debug("Could not allocate crypto API arc4\n");
8889
priv->rx_tfm_arc4 = NULL;
8990
goto fail;
9091
}
9192

92-
priv->rx_tfm_michael = crypto_alloc_hash("michael_mic", 0,
93-
CRYPTO_ALG_ASYNC);
93+
priv->rx_tfm_michael = crypto_alloc_ahash("michael_mic", 0,
94+
CRYPTO_ALG_ASYNC);
9495
if (IS_ERR(priv->rx_tfm_michael)) {
9596
pr_debug("Could not allocate crypto API michael_mic\n");
9697
priv->rx_tfm_michael = NULL;
@@ -100,14 +101,10 @@ static void *rtllib_tkip_init(int key_idx)
100101

101102
fail:
102103
if (priv) {
103-
if (priv->tx_tfm_michael)
104-
crypto_free_hash(priv->tx_tfm_michael);
105-
if (priv->tx_tfm_arc4)
106-
crypto_free_blkcipher(priv->tx_tfm_arc4);
107-
if (priv->rx_tfm_michael)
108-
crypto_free_hash(priv->rx_tfm_michael);
109-
if (priv->rx_tfm_arc4)
110-
crypto_free_blkcipher(priv->rx_tfm_arc4);
104+
crypto_free_ahash(priv->tx_tfm_michael);
105+
crypto_free_skcipher(priv->tx_tfm_arc4);
106+
crypto_free_ahash(priv->rx_tfm_michael);
107+
crypto_free_skcipher(priv->rx_tfm_arc4);
111108
kfree(priv);
112109
}
113110

@@ -120,14 +117,10 @@ static void rtllib_tkip_deinit(void *priv)
120117
struct rtllib_tkip_data *_priv = priv;
121118

122119
if (_priv) {
123-
if (_priv->tx_tfm_michael)
124-
crypto_free_hash(_priv->tx_tfm_michael);
125-
if (_priv->tx_tfm_arc4)
126-
crypto_free_blkcipher(_priv->tx_tfm_arc4);
127-
if (_priv->rx_tfm_michael)
128-
crypto_free_hash(_priv->rx_tfm_michael);
129-
if (_priv->rx_tfm_arc4)
130-
crypto_free_blkcipher(_priv->rx_tfm_arc4);
120+
crypto_free_ahash(_priv->tx_tfm_michael);
121+
crypto_free_skcipher(_priv->tx_tfm_arc4);
122+
crypto_free_ahash(_priv->rx_tfm_michael);
123+
crypto_free_skcipher(_priv->rx_tfm_arc4);
131124
}
132125
kfree(priv);
133126
}
@@ -301,7 +294,6 @@ static int rtllib_tkip_encrypt(struct sk_buff *skb, int hdr_len, void *priv)
301294
struct rtllib_hdr_4addr *hdr;
302295
struct cb_desc *tcb_desc = (struct cb_desc *)(skb->cb +
303296
MAX_DEV_ADDR_SIZE);
304-
struct blkcipher_desc desc = {.tfm = tkey->tx_tfm_arc4};
305297
int ret = 0;
306298
u8 rc4key[16], *icv;
307299
u32 crc;
@@ -347,6 +339,8 @@ static int rtllib_tkip_encrypt(struct sk_buff *skb, int hdr_len, void *priv)
347339
*pos++ = (tkey->tx_iv32 >> 24) & 0xff;
348340

349341
if (!tcb_desc->bHwSec) {
342+
SKCIPHER_REQUEST_ON_STACK(req, tkey->tx_tfm_arc4);
343+
350344
icv = skb_put(skb, 4);
351345
crc = ~crc32_le(~0, pos, len);
352346
icv[0] = crc;
@@ -357,8 +351,12 @@ static int rtllib_tkip_encrypt(struct sk_buff *skb, int hdr_len, void *priv)
357351
sg_init_one(&sg, pos, len+4);
358352

359353

360-
crypto_blkcipher_setkey(tkey->tx_tfm_arc4, rc4key, 16);
361-
ret = crypto_blkcipher_encrypt(&desc, &sg, &sg, len + 4);
354+
crypto_skcipher_setkey(tkey->tx_tfm_arc4, rc4key, 16);
355+
skcipher_request_set_tfm(req, tkey->tx_tfm_arc4);
356+
skcipher_request_set_callback(req, 0, NULL, NULL);
357+
skcipher_request_set_crypt(req, &sg, &sg, len + 4, NULL);
358+
ret = crypto_skcipher_encrypt(req);
359+
skcipher_request_zero(req);
362360
}
363361

364362
tkey->tx_iv16++;
@@ -384,12 +382,12 @@ static int rtllib_tkip_decrypt(struct sk_buff *skb, int hdr_len, void *priv)
384382
struct rtllib_hdr_4addr *hdr;
385383
struct cb_desc *tcb_desc = (struct cb_desc *)(skb->cb +
386384
MAX_DEV_ADDR_SIZE);
387-
struct blkcipher_desc desc = {.tfm = tkey->rx_tfm_arc4};
388385
u8 rc4key[16];
389386
u8 icv[4];
390387
u32 crc;
391388
struct scatterlist sg;
392389
int plen;
390+
int err;
393391

394392
if (skb->len < hdr_len + 8 + 4)
395393
return -1;
@@ -425,6 +423,8 @@ static int rtllib_tkip_decrypt(struct sk_buff *skb, int hdr_len, void *priv)
425423
pos += 8;
426424

427425
if (!tcb_desc->bHwSec || (skb->cb[0] == 1)) {
426+
SKCIPHER_REQUEST_ON_STACK(req, tkey->rx_tfm_arc4);
427+
428428
if ((iv32 < tkey->rx_iv32 ||
429429
(iv32 == tkey->rx_iv32 && iv16 <= tkey->rx_iv16)) &&
430430
tkey->initialized) {
@@ -450,8 +450,13 @@ static int rtllib_tkip_decrypt(struct sk_buff *skb, int hdr_len, void *priv)
450450

451451
sg_init_one(&sg, pos, plen+4);
452452

453-
crypto_blkcipher_setkey(tkey->rx_tfm_arc4, rc4key, 16);
454-
if (crypto_blkcipher_decrypt(&desc, &sg, &sg, plen + 4)) {
453+
crypto_skcipher_setkey(tkey->rx_tfm_arc4, rc4key, 16);
454+
skcipher_request_set_tfm(req, tkey->rx_tfm_arc4);
455+
skcipher_request_set_callback(req, 0, NULL, NULL);
456+
skcipher_request_set_crypt(req, &sg, &sg, plen + 4, NULL);
457+
err = crypto_skcipher_decrypt(req);
458+
skcipher_request_zero(req);
459+
if (err) {
455460
if (net_ratelimit()) {
456461
netdev_dbg(skb->dev,
457462
"Failed to decrypt received packet from %pM\n",
@@ -500,11 +505,12 @@ static int rtllib_tkip_decrypt(struct sk_buff *skb, int hdr_len, void *priv)
500505
}
501506

502507

503-
static int michael_mic(struct crypto_hash *tfm_michael, u8 *key, u8 *hdr,
508+
static int michael_mic(struct crypto_ahash *tfm_michael, u8 *key, u8 *hdr,
504509
u8 *data, size_t data_len, u8 *mic)
505510
{
506-
struct hash_desc desc;
511+
AHASH_REQUEST_ON_STACK(req, tfm_michael);
507512
struct scatterlist sg[2];
513+
int err;
508514

509515
if (tfm_michael == NULL) {
510516
pr_warn("michael_mic: tfm_michael == NULL\n");
@@ -514,12 +520,15 @@ static int michael_mic(struct crypto_hash *tfm_michael, u8 *key, u8 *hdr,
514520
sg_set_buf(&sg[0], hdr, 16);
515521
sg_set_buf(&sg[1], data, data_len);
516522

517-
if (crypto_hash_setkey(tfm_michael, key, 8))
523+
if (crypto_ahash_setkey(tfm_michael, key, 8))
518524
return -1;
519525

520-
desc.tfm = tfm_michael;
521-
desc.flags = 0;
522-
return crypto_hash_digest(&desc, sg, data_len + 16, mic);
526+
ahash_request_set_tfm(req, tfm_michael);
527+
ahash_request_set_callback(req, 0, NULL, NULL);
528+
ahash_request_set_crypt(req, sg, mic, data_len + 16);
529+
err = crypto_ahash_digest(req);
530+
ahash_request_zero(req);
531+
return err;
523532
}
524533

525534
static void michael_mic_hdr(struct sk_buff *skb, u8 *hdr)
@@ -655,10 +664,10 @@ static int rtllib_tkip_set_key(void *key, int len, u8 *seq, void *priv)
655664
{
656665
struct rtllib_tkip_data *tkey = priv;
657666
int keyidx;
658-
struct crypto_hash *tfm = tkey->tx_tfm_michael;
659-
struct crypto_blkcipher *tfm2 = tkey->tx_tfm_arc4;
660-
struct crypto_hash *tfm3 = tkey->rx_tfm_michael;
661-
struct crypto_blkcipher *tfm4 = tkey->rx_tfm_arc4;
667+
struct crypto_ahash *tfm = tkey->tx_tfm_michael;
668+
struct crypto_skcipher *tfm2 = tkey->tx_tfm_arc4;
669+
struct crypto_ahash *tfm3 = tkey->rx_tfm_michael;
670+
struct crypto_skcipher *tfm4 = tkey->rx_tfm_arc4;
662671

663672
keyidx = tkey->key_idx;
664673
memset(tkey, 0, sizeof(*tkey));

drivers/staging/rtl8192e/rtllib_crypt_wep.c

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
* more details.
1010
*/
1111

12+
#include <crypto/skcipher.h>
1213
#include <linux/module.h>
1314
#include <linux/init.h>
1415
#include <linux/slab.h>
@@ -17,8 +18,6 @@
1718
#include <linux/string.h>
1819
#include "rtllib.h"
1920

20-
#include <linux/crypto.h>
21-
2221
#include <linux/scatterlist.h>
2322
#include <linux/crc32.h>
2423

@@ -28,8 +27,8 @@ struct prism2_wep_data {
2827
u8 key[WEP_KEY_LEN + 1];
2928
u8 key_len;
3029
u8 key_idx;
31-
struct crypto_blkcipher *tx_tfm;
32-
struct crypto_blkcipher *rx_tfm;
30+
struct crypto_skcipher *tx_tfm;
31+
struct crypto_skcipher *rx_tfm;
3332
};
3433

3534

@@ -42,13 +41,13 @@ static void *prism2_wep_init(int keyidx)
4241
goto fail;
4342
priv->key_idx = keyidx;
4443

45-
priv->tx_tfm = crypto_alloc_blkcipher("ecb(arc4)", 0, CRYPTO_ALG_ASYNC);
44+
priv->tx_tfm = crypto_alloc_skcipher("ecb(arc4)", 0, CRYPTO_ALG_ASYNC);
4645
if (IS_ERR(priv->tx_tfm)) {
4746
pr_debug("rtllib_crypt_wep: could not allocate crypto API arc4\n");
4847
priv->tx_tfm = NULL;
4948
goto fail;
5049
}
51-
priv->rx_tfm = crypto_alloc_blkcipher("ecb(arc4)", 0, CRYPTO_ALG_ASYNC);
50+
priv->rx_tfm = crypto_alloc_skcipher("ecb(arc4)", 0, CRYPTO_ALG_ASYNC);
5251
if (IS_ERR(priv->rx_tfm)) {
5352
pr_debug("rtllib_crypt_wep: could not allocate crypto API arc4\n");
5453
priv->rx_tfm = NULL;
@@ -62,10 +61,8 @@ static void *prism2_wep_init(int keyidx)
6261

6362
fail:
6463
if (priv) {
65-
if (priv->tx_tfm)
66-
crypto_free_blkcipher(priv->tx_tfm);
67-
if (priv->rx_tfm)
68-
crypto_free_blkcipher(priv->rx_tfm);
64+
crypto_free_skcipher(priv->tx_tfm);
65+
crypto_free_skcipher(priv->rx_tfm);
6966
kfree(priv);
7067
}
7168
return NULL;
@@ -77,10 +74,8 @@ static void prism2_wep_deinit(void *priv)
7774
struct prism2_wep_data *_priv = priv;
7875

7976
if (_priv) {
80-
if (_priv->tx_tfm)
81-
crypto_free_blkcipher(_priv->tx_tfm);
82-
if (_priv->rx_tfm)
83-
crypto_free_blkcipher(_priv->rx_tfm);
77+
crypto_free_skcipher(_priv->tx_tfm);
78+
crypto_free_skcipher(_priv->rx_tfm);
8479
}
8580
kfree(priv);
8681
}
@@ -99,10 +94,10 @@ static int prism2_wep_encrypt(struct sk_buff *skb, int hdr_len, void *priv)
9994
u8 *pos;
10095
struct cb_desc *tcb_desc = (struct cb_desc *)(skb->cb +
10196
MAX_DEV_ADDR_SIZE);
102-
struct blkcipher_desc desc = {.tfm = wep->tx_tfm};
10397
u32 crc;
10498
u8 *icv;
10599
struct scatterlist sg;
100+
int err;
106101

107102
if (skb_headroom(skb) < 4 || skb_tailroom(skb) < 4 ||
108103
skb->len < hdr_len){
@@ -140,6 +135,7 @@ static int prism2_wep_encrypt(struct sk_buff *skb, int hdr_len, void *priv)
140135
memcpy(key + 3, wep->key, wep->key_len);
141136

142137
if (!tcb_desc->bHwSec) {
138+
SKCIPHER_REQUEST_ON_STACK(req, wep->tx_tfm);
143139

144140
/* Append little-endian CRC32 and encrypt it to produce ICV */
145141
crc = ~crc32_le(~0, pos, len);
@@ -150,8 +146,13 @@ static int prism2_wep_encrypt(struct sk_buff *skb, int hdr_len, void *priv)
150146
icv[3] = crc >> 24;
151147

152148
sg_init_one(&sg, pos, len+4);
153-
crypto_blkcipher_setkey(wep->tx_tfm, key, klen);
154-
return crypto_blkcipher_encrypt(&desc, &sg, &sg, len + 4);
149+
crypto_skcipher_setkey(wep->tx_tfm, key, klen);
150+
skcipher_request_set_tfm(req, wep->tx_tfm);
151+
skcipher_request_set_callback(req, 0, NULL, NULL);
152+
skcipher_request_set_crypt(req, &sg, &sg, len + 4, NULL);
153+
err = crypto_skcipher_encrypt(req);
154+
skcipher_request_zero(req);
155+
return err;
155156
}
156157

157158
return 0;
@@ -173,10 +174,10 @@ static int prism2_wep_decrypt(struct sk_buff *skb, int hdr_len, void *priv)
173174
u8 keyidx, *pos;
174175
struct cb_desc *tcb_desc = (struct cb_desc *)(skb->cb +
175176
MAX_DEV_ADDR_SIZE);
176-
struct blkcipher_desc desc = {.tfm = wep->rx_tfm};
177177
u32 crc;
178178
u8 icv[4];
179179
struct scatterlist sg;
180+
int err;
180181

181182
if (skb->len < hdr_len + 8)
182183
return -1;
@@ -198,9 +199,16 @@ static int prism2_wep_decrypt(struct sk_buff *skb, int hdr_len, void *priv)
198199
plen = skb->len - hdr_len - 8;
199200

200201
if (!tcb_desc->bHwSec) {
202+
SKCIPHER_REQUEST_ON_STACK(req, wep->rx_tfm);
203+
201204
sg_init_one(&sg, pos, plen+4);
202-
crypto_blkcipher_setkey(wep->rx_tfm, key, klen);
203-
if (crypto_blkcipher_decrypt(&desc, &sg, &sg, plen + 4))
205+
crypto_skcipher_setkey(wep->rx_tfm, key, klen);
206+
skcipher_request_set_tfm(req, wep->rx_tfm);
207+
skcipher_request_set_callback(req, 0, NULL, NULL);
208+
skcipher_request_set_crypt(req, &sg, &sg, plen + 4, NULL);
209+
err = crypto_skcipher_decrypt(req);
210+
skcipher_request_zero(req);
211+
if (err)
204212
return -7;
205213
crc = ~crc32_le(~0, pos, plen);
206214
icv[0] = crc;

0 commit comments

Comments
 (0)