42
42
* deprecated in 2.6
43
43
*/
44
44
45
+ #include <crypto/hash.h>
46
+ #include <crypto/skcipher.h>
45
47
#include <linux/err.h>
46
48
#include <linux/module.h>
47
49
#include <linux/kernel.h>
48
50
#include <linux/init.h>
49
51
#include <linux/types.h>
50
52
#include <linux/slab.h>
51
53
#include <linux/string.h>
52
- #include <linux/crypto.h>
53
54
#include <linux/mm.h>
54
55
#include <linux/ppp_defs.h>
55
56
#include <linux/ppp-comp.h>
@@ -94,8 +95,8 @@ static inline void sha_pad_init(struct sha_pad *shapad)
94
95
* State for an MPPE (de)compressor.
95
96
*/
96
97
struct ppp_mppe_state {
97
- struct crypto_blkcipher * arc4 ;
98
- struct crypto_hash * sha1 ;
98
+ struct crypto_skcipher * arc4 ;
99
+ struct crypto_ahash * sha1 ;
99
100
unsigned char * sha1_digest ;
100
101
unsigned char master_key [MPPE_MAX_KEY_LEN ];
101
102
unsigned char session_key [MPPE_MAX_KEY_LEN ];
@@ -135,7 +136,7 @@ struct ppp_mppe_state {
135
136
*/
136
137
static void get_new_key_from_sha (struct ppp_mppe_state * state )
137
138
{
138
- struct hash_desc desc ;
139
+ AHASH_REQUEST_ON_STACK ( req , state -> sha1 ) ;
139
140
struct scatterlist sg [4 ];
140
141
unsigned int nbytes ;
141
142
@@ -148,10 +149,12 @@ static void get_new_key_from_sha(struct ppp_mppe_state * state)
148
149
nbytes += setup_sg (& sg [3 ], sha_pad -> sha_pad2 ,
149
150
sizeof (sha_pad -> sha_pad2 ));
150
151
151
- desc .tfm = state -> sha1 ;
152
- desc .flags = 0 ;
152
+ ahash_request_set_tfm (req , state -> sha1 );
153
+ ahash_request_set_callback (req , 0 , NULL , NULL );
154
+ ahash_request_set_crypt (req , sg , state -> sha1_digest , nbytes );
153
155
154
- crypto_hash_digest (& desc , sg , nbytes , state -> sha1_digest );
156
+ crypto_ahash_digest (req );
157
+ ahash_request_zero (req );
155
158
}
156
159
157
160
/*
@@ -161,20 +164,23 @@ static void get_new_key_from_sha(struct ppp_mppe_state * state)
161
164
static void mppe_rekey (struct ppp_mppe_state * state , int initial_key )
162
165
{
163
166
struct scatterlist sg_in [1 ], sg_out [1 ];
164
- struct blkcipher_desc desc = { .tfm = state -> arc4 };
167
+ SKCIPHER_REQUEST_ON_STACK (req , state -> arc4 );
168
+
169
+ skcipher_request_set_tfm (req , state -> arc4 );
170
+ skcipher_request_set_callback (req , 0 , NULL , NULL );
165
171
166
172
get_new_key_from_sha (state );
167
173
if (!initial_key ) {
168
- crypto_blkcipher_setkey (state -> arc4 , state -> sha1_digest ,
169
- state -> keylen );
174
+ crypto_skcipher_setkey (state -> arc4 , state -> sha1_digest ,
175
+ state -> keylen );
170
176
sg_init_table (sg_in , 1 );
171
177
sg_init_table (sg_out , 1 );
172
178
setup_sg (sg_in , state -> sha1_digest , state -> keylen );
173
179
setup_sg (sg_out , state -> session_key , state -> keylen );
174
- if (crypto_blkcipher_encrypt (& desc , sg_out , sg_in ,
175
- state -> keylen ) != 0 ) {
180
+ skcipher_request_set_crypt (req , sg_in , sg_out , state -> keylen ,
181
+ NULL );
182
+ if (crypto_skcipher_encrypt (req ))
176
183
printk (KERN_WARNING "mppe_rekey: cipher_encrypt failed\n" );
177
- }
178
184
} else {
179
185
memcpy (state -> session_key , state -> sha1_digest , state -> keylen );
180
186
}
@@ -184,7 +190,8 @@ static void mppe_rekey(struct ppp_mppe_state * state, int initial_key)
184
190
state -> session_key [1 ] = 0x26 ;
185
191
state -> session_key [2 ] = 0x9e ;
186
192
}
187
- crypto_blkcipher_setkey (state -> arc4 , state -> session_key , state -> keylen );
193
+ crypto_skcipher_setkey (state -> arc4 , state -> session_key , state -> keylen );
194
+ skcipher_request_zero (req );
188
195
}
189
196
190
197
/*
@@ -204,19 +211,19 @@ static void *mppe_alloc(unsigned char *options, int optlen)
204
211
goto out ;
205
212
206
213
207
- state -> arc4 = crypto_alloc_blkcipher ("ecb(arc4)" , 0 , CRYPTO_ALG_ASYNC );
214
+ state -> arc4 = crypto_alloc_skcipher ("ecb(arc4)" , 0 , CRYPTO_ALG_ASYNC );
208
215
if (IS_ERR (state -> arc4 )) {
209
216
state -> arc4 = NULL ;
210
217
goto out_free ;
211
218
}
212
219
213
- state -> sha1 = crypto_alloc_hash ("sha1" , 0 , CRYPTO_ALG_ASYNC );
220
+ state -> sha1 = crypto_alloc_ahash ("sha1" , 0 , CRYPTO_ALG_ASYNC );
214
221
if (IS_ERR (state -> sha1 )) {
215
222
state -> sha1 = NULL ;
216
223
goto out_free ;
217
224
}
218
225
219
- digestsize = crypto_hash_digestsize (state -> sha1 );
226
+ digestsize = crypto_ahash_digestsize (state -> sha1 );
220
227
if (digestsize < MPPE_MAX_KEY_LEN )
221
228
goto out_free ;
222
229
@@ -237,15 +244,12 @@ static void *mppe_alloc(unsigned char *options, int optlen)
237
244
238
245
return (void * )state ;
239
246
240
- out_free :
241
- if (state -> sha1_digest )
242
- kfree (state -> sha1_digest );
243
- if (state -> sha1 )
244
- crypto_free_hash (state -> sha1 );
245
- if (state -> arc4 )
246
- crypto_free_blkcipher (state -> arc4 );
247
- kfree (state );
248
- out :
247
+ out_free :
248
+ kfree (state -> sha1_digest );
249
+ crypto_free_ahash (state -> sha1 );
250
+ crypto_free_skcipher (state -> arc4 );
251
+ kfree (state );
252
+ out :
249
253
return NULL ;
250
254
}
251
255
@@ -256,13 +260,10 @@ static void mppe_free(void *arg)
256
260
{
257
261
struct ppp_mppe_state * state = (struct ppp_mppe_state * ) arg ;
258
262
if (state ) {
259
- if (state -> sha1_digest )
260
263
kfree (state -> sha1_digest );
261
- if (state -> sha1 )
262
- crypto_free_hash (state -> sha1 );
263
- if (state -> arc4 )
264
- crypto_free_blkcipher (state -> arc4 );
265
- kfree (state );
264
+ crypto_free_ahash (state -> sha1 );
265
+ crypto_free_skcipher (state -> arc4 );
266
+ kfree (state );
266
267
}
267
268
}
268
269
@@ -368,8 +369,9 @@ mppe_compress(void *arg, unsigned char *ibuf, unsigned char *obuf,
368
369
int isize , int osize )
369
370
{
370
371
struct ppp_mppe_state * state = (struct ppp_mppe_state * ) arg ;
371
- struct blkcipher_desc desc = { . tfm = state -> arc4 } ;
372
+ SKCIPHER_REQUEST_ON_STACK ( req , state -> arc4 ) ;
372
373
int proto ;
374
+ int err ;
373
375
struct scatterlist sg_in [1 ], sg_out [1 ];
374
376
375
377
/*
@@ -426,7 +428,13 @@ mppe_compress(void *arg, unsigned char *ibuf, unsigned char *obuf,
426
428
sg_init_table (sg_out , 1 );
427
429
setup_sg (sg_in , ibuf , isize );
428
430
setup_sg (sg_out , obuf , osize );
429
- if (crypto_blkcipher_encrypt (& desc , sg_out , sg_in , isize ) != 0 ) {
431
+
432
+ skcipher_request_set_tfm (req , state -> arc4 );
433
+ skcipher_request_set_callback (req , 0 , NULL , NULL );
434
+ skcipher_request_set_crypt (req , sg_in , sg_out , isize , NULL );
435
+ err = crypto_skcipher_encrypt (req );
436
+ skcipher_request_zero (req );
437
+ if (err ) {
430
438
printk (KERN_DEBUG "crypto_cypher_encrypt failed\n" );
431
439
return -1 ;
432
440
}
@@ -475,7 +483,7 @@ mppe_decompress(void *arg, unsigned char *ibuf, int isize, unsigned char *obuf,
475
483
int osize )
476
484
{
477
485
struct ppp_mppe_state * state = (struct ppp_mppe_state * ) arg ;
478
- struct blkcipher_desc desc = { . tfm = state -> arc4 } ;
486
+ SKCIPHER_REQUEST_ON_STACK ( req , state -> arc4 ) ;
479
487
unsigned ccount ;
480
488
int flushed = MPPE_BITS (ibuf ) & MPPE_BIT_FLUSHED ;
481
489
struct scatterlist sg_in [1 ], sg_out [1 ];
@@ -609,9 +617,14 @@ mppe_decompress(void *arg, unsigned char *ibuf, int isize, unsigned char *obuf,
609
617
sg_init_table (sg_out , 1 );
610
618
setup_sg (sg_in , ibuf , 1 );
611
619
setup_sg (sg_out , obuf , 1 );
612
- if (crypto_blkcipher_decrypt (& desc , sg_out , sg_in , 1 ) != 0 ) {
620
+
621
+ skcipher_request_set_tfm (req , state -> arc4 );
622
+ skcipher_request_set_callback (req , 0 , NULL , NULL );
623
+ skcipher_request_set_crypt (req , sg_in , sg_out , 1 , NULL );
624
+ if (crypto_skcipher_decrypt (req )) {
613
625
printk (KERN_DEBUG "crypto_cypher_decrypt failed\n" );
614
- return DECOMP_ERROR ;
626
+ osize = DECOMP_ERROR ;
627
+ goto out_zap_req ;
615
628
}
616
629
617
630
/*
@@ -629,9 +642,11 @@ mppe_decompress(void *arg, unsigned char *ibuf, int isize, unsigned char *obuf,
629
642
/* And finally, decrypt the rest of the packet. */
630
643
setup_sg (sg_in , ibuf + 1 , isize - 1 );
631
644
setup_sg (sg_out , obuf + 1 , osize - 1 );
632
- if (crypto_blkcipher_decrypt (& desc , sg_out , sg_in , isize - 1 )) {
645
+ skcipher_request_set_crypt (req , sg_in , sg_out , isize - 1 , NULL );
646
+ if (crypto_skcipher_decrypt (req )) {
633
647
printk (KERN_DEBUG "crypto_cypher_decrypt failed\n" );
634
- return DECOMP_ERROR ;
648
+ osize = DECOMP_ERROR ;
649
+ goto out_zap_req ;
635
650
}
636
651
637
652
state -> stats .unc_bytes += osize ;
@@ -642,6 +657,8 @@ mppe_decompress(void *arg, unsigned char *ibuf, int isize, unsigned char *obuf,
642
657
/* good packet credit */
643
658
state -> sanity_errors >>= 1 ;
644
659
660
+ out_zap_req :
661
+ skcipher_request_zero (req );
645
662
return osize ;
646
663
647
664
sanity_error :
@@ -714,8 +731,8 @@ static struct compressor ppp_mppe = {
714
731
static int __init ppp_mppe_init (void )
715
732
{
716
733
int answer ;
717
- if (!(crypto_has_blkcipher ("ecb(arc4)" , 0 , CRYPTO_ALG_ASYNC ) &&
718
- crypto_has_hash ("sha1" , 0 , CRYPTO_ALG_ASYNC )))
734
+ if (!(crypto_has_skcipher ("ecb(arc4)" , 0 , CRYPTO_ALG_ASYNC ) &&
735
+ crypto_has_ahash ("sha1" , 0 , CRYPTO_ALG_ASYNC )))
719
736
return - ENODEV ;
720
737
721
738
sha_pad = kmalloc (sizeof (struct sha_pad ), GFP_KERNEL );
0 commit comments