21
21
22
22
#include "ieee80211.h"
23
23
24
- #include <linux/crypto.h>
24
+ #include <crypto/hash.h>
25
+ #include <crypto/skcipher.h>
25
26
#include <linux/scatterlist.h>
26
27
#include <linux/crc32.h>
27
28
@@ -52,10 +53,10 @@ struct ieee80211_tkip_data {
52
53
53
54
int key_idx ;
54
55
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 ;
59
60
60
61
/* scratch buffers for virt_to_page() (crypto API) */
61
62
u8 rx_hdr [16 ], tx_hdr [16 ];
@@ -70,7 +71,7 @@ static void *ieee80211_tkip_init(int key_idx)
70
71
goto fail ;
71
72
priv -> key_idx = key_idx ;
72
73
73
- priv -> tx_tfm_arc4 = crypto_alloc_blkcipher ("ecb(arc4)" , 0 ,
74
+ priv -> tx_tfm_arc4 = crypto_alloc_skcipher ("ecb(arc4)" , 0 ,
74
75
CRYPTO_ALG_ASYNC );
75
76
if (IS_ERR (priv -> tx_tfm_arc4 )) {
76
77
printk (KERN_DEBUG "ieee80211_crypt_tkip: could not allocate "
@@ -79,7 +80,7 @@ static void *ieee80211_tkip_init(int key_idx)
79
80
goto fail ;
80
81
}
81
82
82
- priv -> tx_tfm_michael = crypto_alloc_hash ("michael_mic" , 0 ,
83
+ priv -> tx_tfm_michael = crypto_alloc_ahash ("michael_mic" , 0 ,
83
84
CRYPTO_ALG_ASYNC );
84
85
if (IS_ERR (priv -> tx_tfm_michael )) {
85
86
printk (KERN_DEBUG "ieee80211_crypt_tkip: could not allocate "
@@ -88,7 +89,7 @@ static void *ieee80211_tkip_init(int key_idx)
88
89
goto fail ;
89
90
}
90
91
91
- priv -> rx_tfm_arc4 = crypto_alloc_blkcipher ("ecb(arc4)" , 0 ,
92
+ priv -> rx_tfm_arc4 = crypto_alloc_skcipher ("ecb(arc4)" , 0 ,
92
93
CRYPTO_ALG_ASYNC );
93
94
if (IS_ERR (priv -> rx_tfm_arc4 )) {
94
95
printk (KERN_DEBUG "ieee80211_crypt_tkip: could not allocate "
@@ -97,7 +98,7 @@ static void *ieee80211_tkip_init(int key_idx)
97
98
goto fail ;
98
99
}
99
100
100
- priv -> rx_tfm_michael = crypto_alloc_hash ("michael_mic" , 0 ,
101
+ priv -> rx_tfm_michael = crypto_alloc_ahash ("michael_mic" , 0 ,
101
102
CRYPTO_ALG_ASYNC );
102
103
if (IS_ERR (priv -> rx_tfm_michael )) {
103
104
printk (KERN_DEBUG "ieee80211_crypt_tkip: could not allocate "
@@ -110,14 +111,10 @@ static void *ieee80211_tkip_init(int key_idx)
110
111
111
112
fail :
112
113
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 );
121
118
kfree (priv );
122
119
}
123
120
@@ -130,14 +127,10 @@ static void ieee80211_tkip_deinit(void *priv)
130
127
struct ieee80211_tkip_data * _priv = priv ;
131
128
132
129
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 );
141
134
}
142
135
kfree (priv );
143
136
}
@@ -312,7 +305,6 @@ static int ieee80211_tkip_encrypt(struct sk_buff *skb, int hdr_len, void *priv)
312
305
u8 * pos ;
313
306
struct rtl_80211_hdr_4addr * hdr ;
314
307
cb_desc * tcb_desc = (cb_desc * )(skb -> cb + MAX_DEV_ADDR_SIZE );
315
- struct blkcipher_desc desc = {.tfm = tkey -> tx_tfm_arc4 };
316
308
int ret = 0 ;
317
309
u8 rc4key [16 ], * icv ;
318
310
u32 crc ;
@@ -357,15 +349,21 @@ static int ieee80211_tkip_encrypt(struct sk_buff *skb, int hdr_len, void *priv)
357
349
* pos ++ = (tkey -> tx_iv32 >> 24 ) & 0xff ;
358
350
359
351
if (!tcb_desc -> bHwSec ) {
352
+ SKCIPHER_REQUEST_ON_STACK (req , tkey -> tx_tfm_arc4 );
353
+
360
354
icv = skb_put (skb , 4 );
361
355
crc = ~crc32_le (~0 , pos , len );
362
356
icv [0 ] = crc ;
363
357
icv [1 ] = crc >> 8 ;
364
358
icv [2 ] = crc >> 16 ;
365
359
icv [3 ] = crc >> 24 ;
366
- crypto_blkcipher_setkey (tkey -> tx_tfm_arc4 , rc4key , 16 );
360
+ crypto_skcipher_setkey (tkey -> tx_tfm_arc4 , rc4key , 16 );
367
361
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 );
369
367
}
370
368
371
369
tkey -> tx_iv16 ++ ;
@@ -390,12 +388,12 @@ static int ieee80211_tkip_decrypt(struct sk_buff *skb, int hdr_len, void *priv)
390
388
u16 iv16 ;
391
389
struct rtl_80211_hdr_4addr * hdr ;
392
390
cb_desc * tcb_desc = (cb_desc * )(skb -> cb + MAX_DEV_ADDR_SIZE );
393
- struct blkcipher_desc desc = {.tfm = tkey -> rx_tfm_arc4 };
394
391
u8 rc4key [16 ];
395
392
u8 icv [4 ];
396
393
u32 crc ;
397
394
struct scatterlist sg ;
398
395
int plen ;
396
+ int err ;
399
397
400
398
if (skb -> len < hdr_len + 8 + 4 )
401
399
return -1 ;
@@ -429,6 +427,8 @@ static int ieee80211_tkip_decrypt(struct sk_buff *skb, int hdr_len, void *priv)
429
427
pos += 8 ;
430
428
431
429
if (!tcb_desc -> bHwSec ) {
430
+ SKCIPHER_REQUEST_ON_STACK (req , tkey -> rx_tfm_arc4 );
431
+
432
432
if (iv32 < tkey -> rx_iv32 ||
433
433
(iv32 == tkey -> rx_iv32 && iv16 <= tkey -> rx_iv16 )) {
434
434
if (net_ratelimit ()) {
@@ -449,10 +449,16 @@ static int ieee80211_tkip_decrypt(struct sk_buff *skb, int hdr_len, void *priv)
449
449
450
450
plen = skb -> len - hdr_len - 12 ;
451
451
452
- crypto_blkcipher_setkey (tkey -> rx_tfm_arc4 , rc4key , 16 );
452
+ crypto_skcipher_setkey (tkey -> rx_tfm_arc4 , rc4key , 16 );
453
453
sg_init_one (& sg , pos , plen + 4 );
454
454
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 ) {
456
462
if (net_ratelimit ()) {
457
463
printk (KERN_DEBUG ": TKIP: failed to decrypt "
458
464
"received packet from %pM\n" ,
@@ -501,11 +507,12 @@ static int ieee80211_tkip_decrypt(struct sk_buff *skb, int hdr_len, void *priv)
501
507
return keyidx ;
502
508
}
503
509
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 ,
505
511
u8 * data , size_t data_len , u8 * mic )
506
512
{
507
- struct hash_desc desc ;
513
+ AHASH_REQUEST_ON_STACK ( req , tfm_michael ) ;
508
514
struct scatterlist sg [2 ];
515
+ int err ;
509
516
510
517
if (tfm_michael == NULL ) {
511
518
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,
516
523
sg_set_buf (& sg [0 ], hdr , 16 );
517
524
sg_set_buf (& sg [1 ], data , data_len );
518
525
519
- if (crypto_hash_setkey (tfm_michael , key , 8 ))
526
+ if (crypto_ahash_setkey (tfm_michael , key , 8 ))
520
527
return -1 ;
521
528
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 ;
525
535
}
526
536
527
537
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)
660
670
{
661
671
struct ieee80211_tkip_data * tkey = priv ;
662
672
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 ;
667
677
668
678
keyidx = tkey -> key_idx ;
669
679
memset (tkey , 0 , sizeof (* tkey ));
0 commit comments