2929#include <linux/ieee80211.h>
3030#include <net/iw_handler.h>
3131
32- #include <linux/crypto.h>
32+ #include <crypto/hash.h>
33+ #include <crypto/skcipher.h>
3334#include <linux/crc32.h>
3435
3536#include <net/lib80211.h>
@@ -63,10 +64,10 @@ struct lib80211_tkip_data {
6364
6465 int key_idx ;
6566
66- struct crypto_blkcipher * rx_tfm_arc4 ;
67- struct crypto_hash * rx_tfm_michael ;
68- struct crypto_blkcipher * tx_tfm_arc4 ;
69- struct crypto_hash * tx_tfm_michael ;
67+ struct crypto_skcipher * rx_tfm_arc4 ;
68+ struct crypto_ahash * rx_tfm_michael ;
69+ struct crypto_skcipher * tx_tfm_arc4 ;
70+ struct crypto_ahash * tx_tfm_michael ;
7071
7172 /* scratch buffers for virt_to_page() (crypto API) */
7273 u8 rx_hdr [16 ], tx_hdr [16 ];
@@ -98,29 +99,29 @@ static void *lib80211_tkip_init(int key_idx)
9899
99100 priv -> key_idx = key_idx ;
100101
101- priv -> tx_tfm_arc4 = crypto_alloc_blkcipher ("ecb(arc4)" , 0 ,
102- CRYPTO_ALG_ASYNC );
102+ priv -> tx_tfm_arc4 = crypto_alloc_skcipher ("ecb(arc4)" , 0 ,
103+ CRYPTO_ALG_ASYNC );
103104 if (IS_ERR (priv -> tx_tfm_arc4 )) {
104105 priv -> tx_tfm_arc4 = NULL ;
105106 goto fail ;
106107 }
107108
108- priv -> tx_tfm_michael = crypto_alloc_hash ("michael_mic" , 0 ,
109- CRYPTO_ALG_ASYNC );
109+ priv -> tx_tfm_michael = crypto_alloc_ahash ("michael_mic" , 0 ,
110+ CRYPTO_ALG_ASYNC );
110111 if (IS_ERR (priv -> tx_tfm_michael )) {
111112 priv -> tx_tfm_michael = NULL ;
112113 goto fail ;
113114 }
114115
115- priv -> rx_tfm_arc4 = crypto_alloc_blkcipher ("ecb(arc4)" , 0 ,
116- CRYPTO_ALG_ASYNC );
116+ priv -> rx_tfm_arc4 = crypto_alloc_skcipher ("ecb(arc4)" , 0 ,
117+ CRYPTO_ALG_ASYNC );
117118 if (IS_ERR (priv -> rx_tfm_arc4 )) {
118119 priv -> rx_tfm_arc4 = NULL ;
119120 goto fail ;
120121 }
121122
122- priv -> rx_tfm_michael = crypto_alloc_hash ("michael_mic" , 0 ,
123- CRYPTO_ALG_ASYNC );
123+ priv -> rx_tfm_michael = crypto_alloc_ahash ("michael_mic" , 0 ,
124+ CRYPTO_ALG_ASYNC );
124125 if (IS_ERR (priv -> rx_tfm_michael )) {
125126 priv -> rx_tfm_michael = NULL ;
126127 goto fail ;
@@ -130,14 +131,10 @@ static void *lib80211_tkip_init(int key_idx)
130131
131132 fail :
132133 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 );
134+ crypto_free_ahash (priv -> tx_tfm_michael );
135+ crypto_free_skcipher (priv -> tx_tfm_arc4 );
136+ crypto_free_ahash (priv -> rx_tfm_michael );
137+ crypto_free_skcipher (priv -> rx_tfm_arc4 );
141138 kfree (priv );
142139 }
143140
@@ -148,14 +145,10 @@ static void lib80211_tkip_deinit(void *priv)
148145{
149146 struct lib80211_tkip_data * _priv = priv ;
150147 if (_priv ) {
151- if (_priv -> tx_tfm_michael )
152- crypto_free_hash (_priv -> tx_tfm_michael );
153- if (_priv -> tx_tfm_arc4 )
154- crypto_free_blkcipher (_priv -> tx_tfm_arc4 );
155- if (_priv -> rx_tfm_michael )
156- crypto_free_hash (_priv -> rx_tfm_michael );
157- if (_priv -> rx_tfm_arc4 )
158- crypto_free_blkcipher (_priv -> rx_tfm_arc4 );
148+ crypto_free_ahash (_priv -> tx_tfm_michael );
149+ crypto_free_skcipher (_priv -> tx_tfm_arc4 );
150+ crypto_free_ahash (_priv -> rx_tfm_michael );
151+ crypto_free_skcipher (_priv -> rx_tfm_arc4 );
159152 }
160153 kfree (priv );
161154}
@@ -353,11 +346,12 @@ static int lib80211_tkip_hdr(struct sk_buff *skb, int hdr_len,
353346static int lib80211_tkip_encrypt (struct sk_buff * skb , int hdr_len , void * priv )
354347{
355348 struct lib80211_tkip_data * tkey = priv ;
356- struct blkcipher_desc desc = { . tfm = tkey -> tx_tfm_arc4 } ;
349+ SKCIPHER_REQUEST_ON_STACK ( req , tkey -> tx_tfm_arc4 ) ;
357350 int len ;
358351 u8 rc4key [16 ], * pos , * icv ;
359352 u32 crc ;
360353 struct scatterlist sg ;
354+ int err ;
361355
362356 if (tkey -> flags & IEEE80211_CRYPTO_TKIP_COUNTERMEASURES ) {
363357 struct ieee80211_hdr * hdr = (struct ieee80211_hdr * )skb -> data ;
@@ -382,9 +376,14 @@ static int lib80211_tkip_encrypt(struct sk_buff *skb, int hdr_len, void *priv)
382376 icv [2 ] = crc >> 16 ;
383377 icv [3 ] = crc >> 24 ;
384378
385- crypto_blkcipher_setkey (tkey -> tx_tfm_arc4 , rc4key , 16 );
379+ crypto_skcipher_setkey (tkey -> tx_tfm_arc4 , rc4key , 16 );
386380 sg_init_one (& sg , pos , len + 4 );
387- return crypto_blkcipher_encrypt (& desc , & sg , & sg , len + 4 );
381+ skcipher_request_set_tfm (req , tkey -> tx_tfm_arc4 );
382+ skcipher_request_set_callback (req , 0 , NULL , NULL );
383+ skcipher_request_set_crypt (req , & sg , & sg , len + 4 , NULL );
384+ err = crypto_skcipher_encrypt (req );
385+ skcipher_request_zero (req );
386+ return err ;
388387}
389388
390389/*
@@ -403,7 +402,7 @@ static inline int tkip_replay_check(u32 iv32_n, u16 iv16_n,
403402static int lib80211_tkip_decrypt (struct sk_buff * skb , int hdr_len , void * priv )
404403{
405404 struct lib80211_tkip_data * tkey = priv ;
406- struct blkcipher_desc desc = { . tfm = tkey -> rx_tfm_arc4 } ;
405+ SKCIPHER_REQUEST_ON_STACK ( req , tkey -> rx_tfm_arc4 ) ;
407406 u8 rc4key [16 ];
408407 u8 keyidx , * pos ;
409408 u32 iv32 ;
@@ -413,6 +412,7 @@ static int lib80211_tkip_decrypt(struct sk_buff *skb, int hdr_len, void *priv)
413412 u32 crc ;
414413 struct scatterlist sg ;
415414 int plen ;
415+ int err ;
416416
417417 hdr = (struct ieee80211_hdr * )skb -> data ;
418418
@@ -465,9 +465,14 @@ static int lib80211_tkip_decrypt(struct sk_buff *skb, int hdr_len, void *priv)
465465
466466 plen = skb -> len - hdr_len - 12 ;
467467
468- crypto_blkcipher_setkey (tkey -> rx_tfm_arc4 , rc4key , 16 );
468+ crypto_skcipher_setkey (tkey -> rx_tfm_arc4 , rc4key , 16 );
469469 sg_init_one (& sg , pos , plen + 4 );
470- if (crypto_blkcipher_decrypt (& desc , & sg , & sg , plen + 4 )) {
470+ skcipher_request_set_tfm (req , tkey -> rx_tfm_arc4 );
471+ skcipher_request_set_callback (req , 0 , NULL , NULL );
472+ skcipher_request_set_crypt (req , & sg , & sg , plen + 4 , NULL );
473+ err = crypto_skcipher_decrypt (req );
474+ skcipher_request_zero (req );
475+ if (err ) {
471476 net_dbg_ratelimited ("TKIP: failed to decrypt received packet from %pM\n" ,
472477 hdr -> addr2 );
473478 return -7 ;
@@ -505,11 +510,12 @@ static int lib80211_tkip_decrypt(struct sk_buff *skb, int hdr_len, void *priv)
505510 return keyidx ;
506511}
507512
508- static int michael_mic (struct crypto_hash * tfm_michael , u8 * key , u8 * hdr ,
513+ static int michael_mic (struct crypto_ahash * tfm_michael , u8 * key , u8 * hdr ,
509514 u8 * data , size_t data_len , u8 * mic )
510515{
511- struct hash_desc desc ;
516+ AHASH_REQUEST_ON_STACK ( req , tfm_michael ) ;
512517 struct scatterlist sg [2 ];
518+ int err ;
513519
514520 if (tfm_michael == NULL ) {
515521 pr_warn ("%s(): tfm_michael == NULL\n" , __func__ );
@@ -519,12 +525,15 @@ static int michael_mic(struct crypto_hash *tfm_michael, u8 * key, u8 * hdr,
519525 sg_set_buf (& sg [0 ], hdr , 16 );
520526 sg_set_buf (& sg [1 ], data , data_len );
521527
522- if (crypto_hash_setkey (tfm_michael , key , 8 ))
528+ if (crypto_ahash_setkey (tfm_michael , key , 8 ))
523529 return -1 ;
524530
525- desc .tfm = tfm_michael ;
526- desc .flags = 0 ;
527- return crypto_hash_digest (& desc , sg , data_len + 16 , mic );
531+ ahash_request_set_tfm (req , tfm_michael );
532+ ahash_request_set_callback (req , 0 , NULL , NULL );
533+ ahash_request_set_crypt (req , sg , mic , data_len + 16 );
534+ err = crypto_ahash_digest (req );
535+ ahash_request_zero (req );
536+ return err ;
528537}
529538
530539static void michael_mic_hdr (struct sk_buff * skb , u8 * hdr )
@@ -645,10 +654,10 @@ static int lib80211_tkip_set_key(void *key, int len, u8 * seq, void *priv)
645654{
646655 struct lib80211_tkip_data * tkey = priv ;
647656 int keyidx ;
648- struct crypto_hash * tfm = tkey -> tx_tfm_michael ;
649- struct crypto_blkcipher * tfm2 = tkey -> tx_tfm_arc4 ;
650- struct crypto_hash * tfm3 = tkey -> rx_tfm_michael ;
651- struct crypto_blkcipher * tfm4 = tkey -> rx_tfm_arc4 ;
657+ struct crypto_ahash * tfm = tkey -> tx_tfm_michael ;
658+ struct crypto_skcipher * tfm2 = tkey -> tx_tfm_arc4 ;
659+ struct crypto_ahash * tfm3 = tkey -> rx_tfm_michael ;
660+ struct crypto_skcipher * tfm4 = tkey -> rx_tfm_arc4 ;
652661
653662 keyidx = tkey -> key_idx ;
654663 memset (tkey , 0 , sizeof (* tkey ));
0 commit comments