Skip to content

Commit c3a7922

Browse files
committed
staging: rtl8192u: Use skcipher and ahash
This patch replaces uses of blkcipher with skcipher, and the long obsolete hash interface with ahash. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au> Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent a60b7fa commit c3a7922

File tree

2 files changed

+81
-57
lines changed

2 files changed

+81
-57
lines changed

drivers/staging/rtl8192u/ieee80211/ieee80211_crypt_tkip.c

Lines changed: 51 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121

2222
#include "ieee80211.h"
2323

24-
#include <linux/crypto.h>
24+
#include <crypto/hash.h>
25+
#include <crypto/skcipher.h>
2526
#include <linux/scatterlist.h>
2627
#include <linux/crc32.h>
2728

@@ -52,10 +53,10 @@ struct ieee80211_tkip_data {
5253

5354
int key_idx;
5455

55-
struct crypto_blkcipher *rx_tfm_arc4;
56-
struct crypto_hash *rx_tfm_michael;
57-
struct crypto_blkcipher *tx_tfm_arc4;
58-
struct crypto_hash *tx_tfm_michael;
56+
struct crypto_skcipher *rx_tfm_arc4;
57+
struct crypto_ahash *rx_tfm_michael;
58+
struct crypto_skcipher *tx_tfm_arc4;
59+
struct crypto_ahash *tx_tfm_michael;
5960

6061
/* scratch buffers for virt_to_page() (crypto API) */
6162
u8 rx_hdr[16], tx_hdr[16];
@@ -70,7 +71,7 @@ static void *ieee80211_tkip_init(int key_idx)
7071
goto fail;
7172
priv->key_idx = key_idx;
7273

73-
priv->tx_tfm_arc4 = crypto_alloc_blkcipher("ecb(arc4)", 0,
74+
priv->tx_tfm_arc4 = crypto_alloc_skcipher("ecb(arc4)", 0,
7475
CRYPTO_ALG_ASYNC);
7576
if (IS_ERR(priv->tx_tfm_arc4)) {
7677
printk(KERN_DEBUG "ieee80211_crypt_tkip: could not allocate "
@@ -79,7 +80,7 @@ static void *ieee80211_tkip_init(int key_idx)
7980
goto fail;
8081
}
8182

82-
priv->tx_tfm_michael = crypto_alloc_hash("michael_mic", 0,
83+
priv->tx_tfm_michael = crypto_alloc_ahash("michael_mic", 0,
8384
CRYPTO_ALG_ASYNC);
8485
if (IS_ERR(priv->tx_tfm_michael)) {
8586
printk(KERN_DEBUG "ieee80211_crypt_tkip: could not allocate "
@@ -88,7 +89,7 @@ static void *ieee80211_tkip_init(int key_idx)
8889
goto fail;
8990
}
9091

91-
priv->rx_tfm_arc4 = crypto_alloc_blkcipher("ecb(arc4)", 0,
92+
priv->rx_tfm_arc4 = crypto_alloc_skcipher("ecb(arc4)", 0,
9293
CRYPTO_ALG_ASYNC);
9394
if (IS_ERR(priv->rx_tfm_arc4)) {
9495
printk(KERN_DEBUG "ieee80211_crypt_tkip: could not allocate "
@@ -97,7 +98,7 @@ static void *ieee80211_tkip_init(int key_idx)
9798
goto fail;
9899
}
99100

100-
priv->rx_tfm_michael = crypto_alloc_hash("michael_mic", 0,
101+
priv->rx_tfm_michael = crypto_alloc_ahash("michael_mic", 0,
101102
CRYPTO_ALG_ASYNC);
102103
if (IS_ERR(priv->rx_tfm_michael)) {
103104
printk(KERN_DEBUG "ieee80211_crypt_tkip: could not allocate "
@@ -110,14 +111,10 @@ static void *ieee80211_tkip_init(int key_idx)
110111

111112
fail:
112113
if (priv) {
113-
if (priv->tx_tfm_michael)
114-
crypto_free_hash(priv->tx_tfm_michael);
115-
if (priv->tx_tfm_arc4)
116-
crypto_free_blkcipher(priv->tx_tfm_arc4);
117-
if (priv->rx_tfm_michael)
118-
crypto_free_hash(priv->rx_tfm_michael);
119-
if (priv->rx_tfm_arc4)
120-
crypto_free_blkcipher(priv->rx_tfm_arc4);
114+
crypto_free_ahash(priv->tx_tfm_michael);
115+
crypto_free_skcipher(priv->tx_tfm_arc4);
116+
crypto_free_ahash(priv->rx_tfm_michael);
117+
crypto_free_skcipher(priv->rx_tfm_arc4);
121118
kfree(priv);
122119
}
123120

@@ -130,14 +127,10 @@ static void ieee80211_tkip_deinit(void *priv)
130127
struct ieee80211_tkip_data *_priv = priv;
131128

132129
if (_priv) {
133-
if (_priv->tx_tfm_michael)
134-
crypto_free_hash(_priv->tx_tfm_michael);
135-
if (_priv->tx_tfm_arc4)
136-
crypto_free_blkcipher(_priv->tx_tfm_arc4);
137-
if (_priv->rx_tfm_michael)
138-
crypto_free_hash(_priv->rx_tfm_michael);
139-
if (_priv->rx_tfm_arc4)
140-
crypto_free_blkcipher(_priv->rx_tfm_arc4);
130+
crypto_free_ahash(_priv->tx_tfm_michael);
131+
crypto_free_skcipher(_priv->tx_tfm_arc4);
132+
crypto_free_ahash(_priv->rx_tfm_michael);
133+
crypto_free_skcipher(_priv->rx_tfm_arc4);
141134
}
142135
kfree(priv);
143136
}
@@ -312,7 +305,6 @@ static int ieee80211_tkip_encrypt(struct sk_buff *skb, int hdr_len, void *priv)
312305
u8 *pos;
313306
struct rtl_80211_hdr_4addr *hdr;
314307
cb_desc *tcb_desc = (cb_desc *)(skb->cb + MAX_DEV_ADDR_SIZE);
315-
struct blkcipher_desc desc = {.tfm = tkey->tx_tfm_arc4};
316308
int ret = 0;
317309
u8 rc4key[16], *icv;
318310
u32 crc;
@@ -357,15 +349,21 @@ static int ieee80211_tkip_encrypt(struct sk_buff *skb, int hdr_len, void *priv)
357349
*pos++ = (tkey->tx_iv32 >> 24) & 0xff;
358350

359351
if (!tcb_desc->bHwSec) {
352+
SKCIPHER_REQUEST_ON_STACK(req, tkey->tx_tfm_arc4);
353+
360354
icv = skb_put(skb, 4);
361355
crc = ~crc32_le(~0, pos, len);
362356
icv[0] = crc;
363357
icv[1] = crc >> 8;
364358
icv[2] = crc >> 16;
365359
icv[3] = crc >> 24;
366-
crypto_blkcipher_setkey(tkey->tx_tfm_arc4, rc4key, 16);
360+
crypto_skcipher_setkey(tkey->tx_tfm_arc4, rc4key, 16);
367361
sg_init_one(&sg, pos, len+4);
368-
ret = crypto_blkcipher_encrypt(&desc, &sg, &sg, len + 4);
362+
skcipher_request_set_tfm(req, tkey->tx_tfm_arc4);
363+
skcipher_request_set_callback(req, 0, NULL, NULL);
364+
skcipher_request_set_crypt(req, &sg, &sg, len + 4, NULL);
365+
ret = crypto_skcipher_encrypt(req);
366+
skcipher_request_zero(req);
369367
}
370368

371369
tkey->tx_iv16++;
@@ -390,12 +388,12 @@ static int ieee80211_tkip_decrypt(struct sk_buff *skb, int hdr_len, void *priv)
390388
u16 iv16;
391389
struct rtl_80211_hdr_4addr *hdr;
392390
cb_desc *tcb_desc = (cb_desc *)(skb->cb + MAX_DEV_ADDR_SIZE);
393-
struct blkcipher_desc desc = {.tfm = tkey->rx_tfm_arc4};
394391
u8 rc4key[16];
395392
u8 icv[4];
396393
u32 crc;
397394
struct scatterlist sg;
398395
int plen;
396+
int err;
399397

400398
if (skb->len < hdr_len + 8 + 4)
401399
return -1;
@@ -429,6 +427,8 @@ static int ieee80211_tkip_decrypt(struct sk_buff *skb, int hdr_len, void *priv)
429427
pos += 8;
430428

431429
if (!tcb_desc->bHwSec) {
430+
SKCIPHER_REQUEST_ON_STACK(req, tkey->rx_tfm_arc4);
431+
432432
if (iv32 < tkey->rx_iv32 ||
433433
(iv32 == tkey->rx_iv32 && iv16 <= tkey->rx_iv16)) {
434434
if (net_ratelimit()) {
@@ -449,10 +449,16 @@ static int ieee80211_tkip_decrypt(struct sk_buff *skb, int hdr_len, void *priv)
449449

450450
plen = skb->len - hdr_len - 12;
451451

452-
crypto_blkcipher_setkey(tkey->rx_tfm_arc4, rc4key, 16);
452+
crypto_skcipher_setkey(tkey->rx_tfm_arc4, rc4key, 16);
453453
sg_init_one(&sg, pos, plen+4);
454454

455-
if (crypto_blkcipher_decrypt(&desc, &sg, &sg, plen + 4)) {
455+
skcipher_request_set_tfm(req, tkey->rx_tfm_arc4);
456+
skcipher_request_set_callback(req, 0, NULL, NULL);
457+
skcipher_request_set_crypt(req, &sg, &sg, plen + 4, NULL);
458+
459+
err = crypto_skcipher_decrypt(req);
460+
skcipher_request_zero(req);
461+
if (err) {
456462
if (net_ratelimit()) {
457463
printk(KERN_DEBUG ": TKIP: failed to decrypt "
458464
"received packet from %pM\n",
@@ -501,11 +507,12 @@ static int ieee80211_tkip_decrypt(struct sk_buff *skb, int hdr_len, void *priv)
501507
return keyidx;
502508
}
503509

504-
static int michael_mic(struct crypto_hash *tfm_michael, u8 *key, u8 *hdr,
510+
static int michael_mic(struct crypto_ahash *tfm_michael, u8 *key, u8 *hdr,
505511
u8 *data, size_t data_len, u8 *mic)
506512
{
507-
struct hash_desc desc;
513+
AHASH_REQUEST_ON_STACK(req, tfm_michael);
508514
struct scatterlist sg[2];
515+
int err;
509516

510517
if (tfm_michael == NULL) {
511518
printk(KERN_WARNING "michael_mic: tfm_michael == NULL\n");
@@ -516,12 +523,15 @@ static int michael_mic(struct crypto_hash *tfm_michael, u8 *key, u8 *hdr,
516523
sg_set_buf(&sg[0], hdr, 16);
517524
sg_set_buf(&sg[1], data, data_len);
518525

519-
if (crypto_hash_setkey(tfm_michael, key, 8))
526+
if (crypto_ahash_setkey(tfm_michael, key, 8))
520527
return -1;
521528

522-
desc.tfm = tfm_michael;
523-
desc.flags = 0;
524-
return crypto_hash_digest(&desc, sg, data_len + 16, mic);
529+
ahash_request_set_tfm(req, tfm_michael);
530+
ahash_request_set_callback(req, 0, NULL, NULL);
531+
ahash_request_set_crypt(req, sg, mic, data_len + 16);
532+
err = crypto_ahash_digest(req);
533+
ahash_request_zero(req);
534+
return err;
525535
}
526536

527537
static void michael_mic_hdr(struct sk_buff *skb, u8 *hdr)
@@ -660,10 +670,10 @@ static int ieee80211_tkip_set_key(void *key, int len, u8 *seq, void *priv)
660670
{
661671
struct ieee80211_tkip_data *tkey = priv;
662672
int keyidx;
663-
struct crypto_hash *tfm = tkey->tx_tfm_michael;
664-
struct crypto_blkcipher *tfm2 = tkey->tx_tfm_arc4;
665-
struct crypto_hash *tfm3 = tkey->rx_tfm_michael;
666-
struct crypto_blkcipher *tfm4 = tkey->rx_tfm_arc4;
673+
struct crypto_ahash *tfm = tkey->tx_tfm_michael;
674+
struct crypto_skcipher *tfm2 = tkey->tx_tfm_arc4;
675+
struct crypto_ahash *tfm3 = tkey->rx_tfm_michael;
676+
struct crypto_skcipher *tfm4 = tkey->rx_tfm_arc4;
667677

668678
keyidx = tkey->key_idx;
669679
memset(tkey, 0, sizeof(*tkey));

drivers/staging/rtl8192u/ieee80211/ieee80211_crypt_wep.c

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
#include "ieee80211.h"
2020

21-
#include <linux/crypto.h>
21+
#include <crypto/skcipher.h>
2222
#include <linux/scatterlist.h>
2323
#include <linux/crc32.h>
2424

@@ -32,8 +32,8 @@ struct prism2_wep_data {
3232
u8 key[WEP_KEY_LEN + 1];
3333
u8 key_len;
3434
u8 key_idx;
35-
struct crypto_blkcipher *tx_tfm;
36-
struct crypto_blkcipher *rx_tfm;
35+
struct crypto_skcipher *tx_tfm;
36+
struct crypto_skcipher *rx_tfm;
3737
};
3838

3939

@@ -46,10 +46,10 @@ static void *prism2_wep_init(int keyidx)
4646
return NULL;
4747
priv->key_idx = keyidx;
4848

49-
priv->tx_tfm = crypto_alloc_blkcipher("ecb(arc4)", 0, CRYPTO_ALG_ASYNC);
49+
priv->tx_tfm = crypto_alloc_skcipher("ecb(arc4)", 0, CRYPTO_ALG_ASYNC);
5050
if (IS_ERR(priv->tx_tfm))
5151
goto free_priv;
52-
priv->rx_tfm = crypto_alloc_blkcipher("ecb(arc4)", 0, CRYPTO_ALG_ASYNC);
52+
priv->rx_tfm = crypto_alloc_skcipher("ecb(arc4)", 0, CRYPTO_ALG_ASYNC);
5353
if (IS_ERR(priv->rx_tfm))
5454
goto free_tx;
5555

@@ -58,7 +58,7 @@ static void *prism2_wep_init(int keyidx)
5858

5959
return priv;
6060
free_tx:
61-
crypto_free_blkcipher(priv->tx_tfm);
61+
crypto_free_skcipher(priv->tx_tfm);
6262
free_priv:
6363
kfree(priv);
6464
return NULL;
@@ -70,10 +70,8 @@ static void prism2_wep_deinit(void *priv)
7070
struct prism2_wep_data *_priv = priv;
7171

7272
if (_priv) {
73-
if (_priv->tx_tfm)
74-
crypto_free_blkcipher(_priv->tx_tfm);
75-
if (_priv->rx_tfm)
76-
crypto_free_blkcipher(_priv->rx_tfm);
73+
crypto_free_skcipher(_priv->tx_tfm);
74+
crypto_free_skcipher(_priv->rx_tfm);
7775
}
7876
kfree(priv);
7977
}
@@ -91,10 +89,10 @@ static int prism2_wep_encrypt(struct sk_buff *skb, int hdr_len, void *priv)
9189
u8 key[WEP_KEY_LEN + 3];
9290
u8 *pos;
9391
cb_desc *tcb_desc = (cb_desc *)(skb->cb + MAX_DEV_ADDR_SIZE);
94-
struct blkcipher_desc desc = {.tfm = wep->tx_tfm};
9592
u32 crc;
9693
u8 *icv;
9794
struct scatterlist sg;
95+
int err;
9896

9997
if (skb_headroom(skb) < 4 || skb_tailroom(skb) < 4 ||
10098
skb->len < hdr_len)
@@ -129,6 +127,8 @@ static int prism2_wep_encrypt(struct sk_buff *skb, int hdr_len, void *priv)
129127
memcpy(key + 3, wep->key, wep->key_len);
130128

131129
if (!tcb_desc->bHwSec) {
130+
SKCIPHER_REQUEST_ON_STACK(req, wep->tx_tfm);
131+
132132
/* Append little-endian CRC32 and encrypt it to produce ICV */
133133
crc = ~crc32_le(~0, pos, len);
134134
icv = skb_put(skb, 4);
@@ -137,10 +137,16 @@ static int prism2_wep_encrypt(struct sk_buff *skb, int hdr_len, void *priv)
137137
icv[2] = crc >> 16;
138138
icv[3] = crc >> 24;
139139

140-
crypto_blkcipher_setkey(wep->tx_tfm, key, klen);
140+
crypto_skcipher_setkey(wep->tx_tfm, key, klen);
141141
sg_init_one(&sg, pos, len+4);
142142

143-
return crypto_blkcipher_encrypt(&desc, &sg, &sg, len + 4);
143+
skcipher_request_set_tfm(req, wep->tx_tfm);
144+
skcipher_request_set_callback(req, 0, NULL, NULL);
145+
skcipher_request_set_crypt(req, &sg, &sg, len + 4, NULL);
146+
147+
err = crypto_skcipher_encrypt(req);
148+
skcipher_request_zero(req);
149+
return err;
144150
}
145151

146152
return 0;
@@ -161,10 +167,10 @@ static int prism2_wep_decrypt(struct sk_buff *skb, int hdr_len, void *priv)
161167
u8 key[WEP_KEY_LEN + 3];
162168
u8 keyidx, *pos;
163169
cb_desc *tcb_desc = (cb_desc *)(skb->cb + MAX_DEV_ADDR_SIZE);
164-
struct blkcipher_desc desc = {.tfm = wep->rx_tfm};
165170
u32 crc;
166171
u8 icv[4];
167172
struct scatterlist sg;
173+
int err;
168174

169175
if (skb->len < hdr_len + 8)
170176
return -1;
@@ -186,10 +192,18 @@ static int prism2_wep_decrypt(struct sk_buff *skb, int hdr_len, void *priv)
186192
plen = skb->len - hdr_len - 8;
187193

188194
if (!tcb_desc->bHwSec) {
189-
crypto_blkcipher_setkey(wep->rx_tfm, key, klen);
195+
SKCIPHER_REQUEST_ON_STACK(req, wep->rx_tfm);
196+
197+
crypto_skcipher_setkey(wep->rx_tfm, key, klen);
190198
sg_init_one(&sg, pos, plen+4);
191199

192-
if (crypto_blkcipher_decrypt(&desc, &sg, &sg, plen + 4))
200+
skcipher_request_set_tfm(req, wep->rx_tfm);
201+
skcipher_request_set_callback(req, 0, NULL, NULL);
202+
skcipher_request_set_crypt(req, &sg, &sg, plen + 4, NULL);
203+
204+
err = crypto_skcipher_decrypt(req);
205+
skcipher_request_zero(req);
206+
if (err)
193207
return -7;
194208

195209
crc = ~crc32_le(~0, pos, plen);

0 commit comments

Comments
 (0)