9
9
* more details.
10
10
*/
11
11
12
+ #include <crypto/hash.h>
13
+ #include <crypto/skcipher.h>
12
14
#include <linux/module.h>
13
15
#include <linux/init.h>
14
16
#include <linux/slab.h>
18
20
#include <linux/if_ether.h>
19
21
#include <linux/if_arp.h>
20
22
#include <linux/string.h>
21
- #include <linux/crypto.h>
22
23
#include <linux/scatterlist.h>
23
24
#include <linux/crc32.h>
24
25
#include <linux/etherdevice.h>
@@ -48,10 +49,10 @@ struct rtllib_tkip_data {
48
49
u32 dot11RSNAStatsTKIPLocalMICFailures ;
49
50
50
51
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 ;
55
56
/* scratch buffers for virt_to_page() (crypto API) */
56
57
u8 rx_hdr [16 ];
57
58
u8 tx_hdr [16 ];
@@ -65,32 +66,32 @@ static void *rtllib_tkip_init(int key_idx)
65
66
if (priv == NULL )
66
67
goto fail ;
67
68
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 );
70
71
if (IS_ERR (priv -> tx_tfm_arc4 )) {
71
72
pr_debug ("Could not allocate crypto API arc4\n" );
72
73
priv -> tx_tfm_arc4 = NULL ;
73
74
goto fail ;
74
75
}
75
76
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 );
78
79
if (IS_ERR (priv -> tx_tfm_michael )) {
79
80
pr_debug ("Could not allocate crypto API michael_mic\n" );
80
81
priv -> tx_tfm_michael = NULL ;
81
82
goto fail ;
82
83
}
83
84
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 );
86
87
if (IS_ERR (priv -> rx_tfm_arc4 )) {
87
88
pr_debug ("Could not allocate crypto API arc4\n" );
88
89
priv -> rx_tfm_arc4 = NULL ;
89
90
goto fail ;
90
91
}
91
92
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 );
94
95
if (IS_ERR (priv -> rx_tfm_michael )) {
95
96
pr_debug ("Could not allocate crypto API michael_mic\n" );
96
97
priv -> rx_tfm_michael = NULL ;
@@ -100,14 +101,10 @@ static void *rtllib_tkip_init(int key_idx)
100
101
101
102
fail :
102
103
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 );
111
108
kfree (priv );
112
109
}
113
110
@@ -120,14 +117,10 @@ static void rtllib_tkip_deinit(void *priv)
120
117
struct rtllib_tkip_data * _priv = priv ;
121
118
122
119
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 );
131
124
}
132
125
kfree (priv );
133
126
}
@@ -301,7 +294,6 @@ static int rtllib_tkip_encrypt(struct sk_buff *skb, int hdr_len, void *priv)
301
294
struct rtllib_hdr_4addr * hdr ;
302
295
struct cb_desc * tcb_desc = (struct cb_desc * )(skb -> cb +
303
296
MAX_DEV_ADDR_SIZE );
304
- struct blkcipher_desc desc = {.tfm = tkey -> tx_tfm_arc4 };
305
297
int ret = 0 ;
306
298
u8 rc4key [16 ], * icv ;
307
299
u32 crc ;
@@ -347,6 +339,8 @@ static int rtllib_tkip_encrypt(struct sk_buff *skb, int hdr_len, void *priv)
347
339
* pos ++ = (tkey -> tx_iv32 >> 24 ) & 0xff ;
348
340
349
341
if (!tcb_desc -> bHwSec ) {
342
+ SKCIPHER_REQUEST_ON_STACK (req , tkey -> tx_tfm_arc4 );
343
+
350
344
icv = skb_put (skb , 4 );
351
345
crc = ~crc32_le (~0 , pos , len );
352
346
icv [0 ] = crc ;
@@ -357,8 +351,12 @@ static int rtllib_tkip_encrypt(struct sk_buff *skb, int hdr_len, void *priv)
357
351
sg_init_one (& sg , pos , len + 4 );
358
352
359
353
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 );
362
360
}
363
361
364
362
tkey -> tx_iv16 ++ ;
@@ -384,12 +382,12 @@ static int rtllib_tkip_decrypt(struct sk_buff *skb, int hdr_len, void *priv)
384
382
struct rtllib_hdr_4addr * hdr ;
385
383
struct cb_desc * tcb_desc = (struct cb_desc * )(skb -> cb +
386
384
MAX_DEV_ADDR_SIZE );
387
- struct blkcipher_desc desc = {.tfm = tkey -> rx_tfm_arc4 };
388
385
u8 rc4key [16 ];
389
386
u8 icv [4 ];
390
387
u32 crc ;
391
388
struct scatterlist sg ;
392
389
int plen ;
390
+ int err ;
393
391
394
392
if (skb -> len < hdr_len + 8 + 4 )
395
393
return -1 ;
@@ -425,6 +423,8 @@ static int rtllib_tkip_decrypt(struct sk_buff *skb, int hdr_len, void *priv)
425
423
pos += 8 ;
426
424
427
425
if (!tcb_desc -> bHwSec || (skb -> cb [0 ] == 1 )) {
426
+ SKCIPHER_REQUEST_ON_STACK (req , tkey -> rx_tfm_arc4 );
427
+
428
428
if ((iv32 < tkey -> rx_iv32 ||
429
429
(iv32 == tkey -> rx_iv32 && iv16 <= tkey -> rx_iv16 )) &&
430
430
tkey -> initialized ) {
@@ -450,8 +450,13 @@ static int rtllib_tkip_decrypt(struct sk_buff *skb, int hdr_len, void *priv)
450
450
451
451
sg_init_one (& sg , pos , plen + 4 );
452
452
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 ) {
455
460
if (net_ratelimit ()) {
456
461
netdev_dbg (skb -> dev ,
457
462
"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)
500
505
}
501
506
502
507
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 ,
504
509
u8 * data , size_t data_len , u8 * mic )
505
510
{
506
- struct hash_desc desc ;
511
+ AHASH_REQUEST_ON_STACK ( req , tfm_michael ) ;
507
512
struct scatterlist sg [2 ];
513
+ int err ;
508
514
509
515
if (tfm_michael == NULL ) {
510
516
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,
514
520
sg_set_buf (& sg [0 ], hdr , 16 );
515
521
sg_set_buf (& sg [1 ], data , data_len );
516
522
517
- if (crypto_hash_setkey (tfm_michael , key , 8 ))
523
+ if (crypto_ahash_setkey (tfm_michael , key , 8 ))
518
524
return -1 ;
519
525
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 ;
523
532
}
524
533
525
534
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)
655
664
{
656
665
struct rtllib_tkip_data * tkey = priv ;
657
666
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 ;
662
671
663
672
keyidx = tkey -> key_idx ;
664
673
memset (tkey , 0 , sizeof (* tkey ));
0 commit comments