44#include <linux/err.h>
55#include <linux/scatterlist.h>
66#include <linux/slab.h>
7- #include <crypto/hash.h>
7+ #include <crypto/aes.h>
8+ #include <crypto/skcipher.h>
89#include <linux/key-type.h>
910
1011#include <keys/ceph-type.h>
@@ -79,9 +80,9 @@ int ceph_crypto_key_unarmor(struct ceph_crypto_key *key, const char *inkey)
7980 return 0 ;
8081}
8182
82- static struct crypto_blkcipher * ceph_crypto_alloc_cipher (void )
83+ static struct crypto_skcipher * ceph_crypto_alloc_cipher (void )
8384{
84- return crypto_alloc_blkcipher ("cbc(aes)" , 0 , CRYPTO_ALG_ASYNC );
85+ return crypto_alloc_skcipher ("cbc(aes)" , 0 , CRYPTO_ALG_ASYNC );
8586}
8687
8788static const u8 * aes_iv = (u8 * )CEPH_AES_IV ;
@@ -162,11 +163,11 @@ static int ceph_aes_encrypt(const void *key, int key_len,
162163{
163164 struct scatterlist sg_in [2 ], prealloc_sg ;
164165 struct sg_table sg_out ;
165- struct crypto_blkcipher * tfm = ceph_crypto_alloc_cipher ();
166- struct blkcipher_desc desc = { . tfm = tfm , . flags = 0 } ;
166+ struct crypto_skcipher * tfm = ceph_crypto_alloc_cipher ();
167+ SKCIPHER_REQUEST_ON_STACK ( req , tfm ) ;
167168 int ret ;
168- void * iv ;
169- int ivsize ;
169+ int ivsize = AES_BLOCK_SIZE ;
170+ char iv [ ivsize ] ;
170171 size_t zero_padding = (0x10 - (src_len & 0x0f ));
171172 char pad [16 ];
172173
@@ -184,11 +185,14 @@ static int ceph_aes_encrypt(const void *key, int key_len,
184185 if (ret )
185186 goto out_tfm ;
186187
187- crypto_blkcipher_setkey ((void * )tfm , key , key_len );
188- iv = crypto_blkcipher_crt (tfm )-> iv ;
189- ivsize = crypto_blkcipher_ivsize (tfm );
188+ crypto_skcipher_setkey ((void * )tfm , key , key_len );
190189 memcpy (iv , aes_iv , ivsize );
191190
191+ skcipher_request_set_tfm (req , tfm );
192+ skcipher_request_set_callback (req , 0 , NULL , NULL );
193+ skcipher_request_set_crypt (req , sg_in , sg_out .sgl ,
194+ src_len + zero_padding , iv );
195+
192196 /*
193197 print_hex_dump(KERN_ERR, "enc key: ", DUMP_PREFIX_NONE, 16, 1,
194198 key, key_len, 1);
@@ -197,8 +201,8 @@ static int ceph_aes_encrypt(const void *key, int key_len,
197201 print_hex_dump(KERN_ERR, "enc pad: ", DUMP_PREFIX_NONE, 16, 1,
198202 pad, zero_padding, 1);
199203 */
200- ret = crypto_blkcipher_encrypt ( & desc , sg_out . sgl , sg_in ,
201- src_len + zero_padding );
204+ ret = crypto_skcipher_encrypt ( req );
205+ skcipher_request_zero ( req );
202206 if (ret < 0 ) {
203207 pr_err ("ceph_aes_crypt failed %d\n" , ret );
204208 goto out_sg ;
@@ -211,7 +215,7 @@ static int ceph_aes_encrypt(const void *key, int key_len,
211215out_sg :
212216 teardown_sgtable (& sg_out );
213217out_tfm :
214- crypto_free_blkcipher (tfm );
218+ crypto_free_skcipher (tfm );
215219 return ret ;
216220}
217221
@@ -222,11 +226,11 @@ static int ceph_aes_encrypt2(const void *key, int key_len, void *dst,
222226{
223227 struct scatterlist sg_in [3 ], prealloc_sg ;
224228 struct sg_table sg_out ;
225- struct crypto_blkcipher * tfm = ceph_crypto_alloc_cipher ();
226- struct blkcipher_desc desc = { . tfm = tfm , . flags = 0 } ;
229+ struct crypto_skcipher * tfm = ceph_crypto_alloc_cipher ();
230+ SKCIPHER_REQUEST_ON_STACK ( req , tfm ) ;
227231 int ret ;
228- void * iv ;
229- int ivsize ;
232+ int ivsize = AES_BLOCK_SIZE ;
233+ char iv [ ivsize ] ;
230234 size_t zero_padding = (0x10 - ((src1_len + src2_len ) & 0x0f ));
231235 char pad [16 ];
232236
@@ -245,11 +249,14 @@ static int ceph_aes_encrypt2(const void *key, int key_len, void *dst,
245249 if (ret )
246250 goto out_tfm ;
247251
248- crypto_blkcipher_setkey ((void * )tfm , key , key_len );
249- iv = crypto_blkcipher_crt (tfm )-> iv ;
250- ivsize = crypto_blkcipher_ivsize (tfm );
252+ crypto_skcipher_setkey ((void * )tfm , key , key_len );
251253 memcpy (iv , aes_iv , ivsize );
252254
255+ skcipher_request_set_tfm (req , tfm );
256+ skcipher_request_set_callback (req , 0 , NULL , NULL );
257+ skcipher_request_set_crypt (req , sg_in , sg_out .sgl ,
258+ src1_len + src2_len + zero_padding , iv );
259+
253260 /*
254261 print_hex_dump(KERN_ERR, "enc key: ", DUMP_PREFIX_NONE, 16, 1,
255262 key, key_len, 1);
@@ -260,8 +267,8 @@ static int ceph_aes_encrypt2(const void *key, int key_len, void *dst,
260267 print_hex_dump(KERN_ERR, "enc pad: ", DUMP_PREFIX_NONE, 16, 1,
261268 pad, zero_padding, 1);
262269 */
263- ret = crypto_blkcipher_encrypt ( & desc , sg_out . sgl , sg_in ,
264- src1_len + src2_len + zero_padding );
270+ ret = crypto_skcipher_encrypt ( req );
271+ skcipher_request_zero ( req );
265272 if (ret < 0 ) {
266273 pr_err ("ceph_aes_crypt2 failed %d\n" , ret );
267274 goto out_sg ;
@@ -274,7 +281,7 @@ static int ceph_aes_encrypt2(const void *key, int key_len, void *dst,
274281out_sg :
275282 teardown_sgtable (& sg_out );
276283out_tfm :
277- crypto_free_blkcipher (tfm );
284+ crypto_free_skcipher (tfm );
278285 return ret ;
279286}
280287
@@ -284,11 +291,11 @@ static int ceph_aes_decrypt(const void *key, int key_len,
284291{
285292 struct sg_table sg_in ;
286293 struct scatterlist sg_out [2 ], prealloc_sg ;
287- struct crypto_blkcipher * tfm = ceph_crypto_alloc_cipher ();
288- struct blkcipher_desc desc = { . tfm = tfm } ;
294+ struct crypto_skcipher * tfm = ceph_crypto_alloc_cipher ();
295+ SKCIPHER_REQUEST_ON_STACK ( req , tfm ) ;
289296 char pad [16 ];
290- void * iv ;
291- int ivsize ;
297+ int ivsize = AES_BLOCK_SIZE ;
298+ char iv [ 16 ] ;
292299 int ret ;
293300 int last_byte ;
294301
@@ -302,18 +309,22 @@ static int ceph_aes_decrypt(const void *key, int key_len,
302309 if (ret )
303310 goto out_tfm ;
304311
305- crypto_blkcipher_setkey ((void * )tfm , key , key_len );
306- iv = crypto_blkcipher_crt (tfm )-> iv ;
307- ivsize = crypto_blkcipher_ivsize (tfm );
312+ crypto_skcipher_setkey ((void * )tfm , key , key_len );
308313 memcpy (iv , aes_iv , ivsize );
309314
315+ skcipher_request_set_tfm (req , tfm );
316+ skcipher_request_set_callback (req , 0 , NULL , NULL );
317+ skcipher_request_set_crypt (req , sg_in .sgl , sg_out ,
318+ src_len , iv );
319+
310320 /*
311321 print_hex_dump(KERN_ERR, "dec key: ", DUMP_PREFIX_NONE, 16, 1,
312322 key, key_len, 1);
313323 print_hex_dump(KERN_ERR, "dec in: ", DUMP_PREFIX_NONE, 16, 1,
314324 src, src_len, 1);
315325 */
316- ret = crypto_blkcipher_decrypt (& desc , sg_out , sg_in .sgl , src_len );
326+ ret = crypto_skcipher_decrypt (req );
327+ skcipher_request_zero (req );
317328 if (ret < 0 ) {
318329 pr_err ("ceph_aes_decrypt failed %d\n" , ret );
319330 goto out_sg ;
@@ -338,7 +349,7 @@ static int ceph_aes_decrypt(const void *key, int key_len,
338349out_sg :
339350 teardown_sgtable (& sg_in );
340351out_tfm :
341- crypto_free_blkcipher (tfm );
352+ crypto_free_skcipher (tfm );
342353 return ret ;
343354}
344355
@@ -349,11 +360,11 @@ static int ceph_aes_decrypt2(const void *key, int key_len,
349360{
350361 struct sg_table sg_in ;
351362 struct scatterlist sg_out [3 ], prealloc_sg ;
352- struct crypto_blkcipher * tfm = ceph_crypto_alloc_cipher ();
353- struct blkcipher_desc desc = { . tfm = tfm } ;
363+ struct crypto_skcipher * tfm = ceph_crypto_alloc_cipher ();
364+ SKCIPHER_REQUEST_ON_STACK ( req , tfm ) ;
354365 char pad [16 ];
355- void * iv ;
356- int ivsize ;
366+ int ivsize = AES_BLOCK_SIZE ;
367+ char iv [ ivsize ] ;
357368 int ret ;
358369 int last_byte ;
359370
@@ -368,18 +379,22 @@ static int ceph_aes_decrypt2(const void *key, int key_len,
368379 if (ret )
369380 goto out_tfm ;
370381
371- crypto_blkcipher_setkey ((void * )tfm , key , key_len );
372- iv = crypto_blkcipher_crt (tfm )-> iv ;
373- ivsize = crypto_blkcipher_ivsize (tfm );
382+ crypto_skcipher_setkey ((void * )tfm , key , key_len );
374383 memcpy (iv , aes_iv , ivsize );
375384
385+ skcipher_request_set_tfm (req , tfm );
386+ skcipher_request_set_callback (req , 0 , NULL , NULL );
387+ skcipher_request_set_crypt (req , sg_in .sgl , sg_out ,
388+ src_len , iv );
389+
376390 /*
377391 print_hex_dump(KERN_ERR, "dec key: ", DUMP_PREFIX_NONE, 16, 1,
378392 key, key_len, 1);
379393 print_hex_dump(KERN_ERR, "dec in: ", DUMP_PREFIX_NONE, 16, 1,
380394 src, src_len, 1);
381395 */
382- ret = crypto_blkcipher_decrypt (& desc , sg_out , sg_in .sgl , src_len );
396+ ret = crypto_skcipher_decrypt (req );
397+ skcipher_request_zero (req );
383398 if (ret < 0 ) {
384399 pr_err ("ceph_aes_decrypt failed %d\n" , ret );
385400 goto out_sg ;
@@ -415,7 +430,7 @@ static int ceph_aes_decrypt2(const void *key, int key_len,
415430out_sg :
416431 teardown_sgtable (& sg_in );
417432out_tfm :
418- crypto_free_blkcipher (tfm );
433+ crypto_free_skcipher (tfm );
419434 return ret ;
420435}
421436
0 commit comments