@@ -255,17 +255,18 @@ static void cryptd_blkcipher_exit_tfm(struct crypto_tfm *tfm)
255255 crypto_free_blkcipher (ctx -> child );
256256}
257257
258- static struct crypto_instance * cryptd_alloc_instance (struct crypto_alg * alg ,
259- unsigned int tail )
258+ static void * cryptd_alloc_instance (struct crypto_alg * alg , unsigned int head ,
259+ unsigned int tail )
260260{
261+ char * p ;
261262 struct crypto_instance * inst ;
262263 int err ;
263264
264- inst = kzalloc (sizeof (* inst ) + tail , GFP_KERNEL );
265- if (!inst ) {
266- inst = ERR_PTR (- ENOMEM );
267- goto out ;
268- }
265+ p = kzalloc (head + sizeof (* inst ) + tail , GFP_KERNEL );
266+ if (!p )
267+ return ERR_PTR (- ENOMEM );
268+
269+ inst = ( void * )( p + head );
269270
270271 err = - ENAMETOOLONG ;
271272 if (snprintf (inst -> alg .cra_driver_name , CRYPTO_MAX_ALG_NAME ,
@@ -279,11 +280,11 @@ static struct crypto_instance *cryptd_alloc_instance(struct crypto_alg *alg,
279280 inst -> alg .cra_alignmask = alg -> cra_alignmask ;
280281
281282out :
282- return inst ;
283+ return p ;
283284
284285out_free_inst :
285- kfree (inst );
286- inst = ERR_PTR (err );
286+ kfree (p );
287+ p = ERR_PTR (err );
287288 goto out ;
288289}
289290
@@ -301,7 +302,7 @@ static int cryptd_create_blkcipher(struct crypto_template *tmpl,
301302 if (IS_ERR (alg ))
302303 return PTR_ERR (alg );
303304
304- inst = cryptd_alloc_instance (alg , sizeof (* ctx ));
305+ inst = cryptd_alloc_instance (alg , 0 , sizeof (* ctx ));
305306 if (IS_ERR (inst ))
306307 goto out_put_alg ;
307308
@@ -509,7 +510,7 @@ static int cryptd_create_hash(struct crypto_template *tmpl, struct rtattr **tb,
509510 struct cryptd_queue * queue )
510511{
511512 struct hashd_instance_ctx * ctx ;
512- struct crypto_instance * inst ;
513+ struct ahash_instance * inst ;
513514 struct shash_alg * salg ;
514515 struct crypto_alg * alg ;
515516 int err ;
@@ -519,33 +520,34 @@ static int cryptd_create_hash(struct crypto_template *tmpl, struct rtattr **tb,
519520 return PTR_ERR (salg );
520521
521522 alg = & salg -> base ;
522- inst = cryptd_alloc_instance (alg , sizeof (* ctx ));
523+ inst = cryptd_alloc_instance (alg , ahash_instance_headroom (),
524+ sizeof (* ctx ));
523525 if (IS_ERR (inst ))
524526 goto out_put_alg ;
525527
526- ctx = crypto_instance_ctx (inst );
528+ ctx = ahash_instance_ctx (inst );
527529 ctx -> queue = queue ;
528530
529- err = crypto_init_shash_spawn (& ctx -> spawn , salg , inst );
531+ err = crypto_init_shash_spawn (& ctx -> spawn , salg ,
532+ ahash_crypto_instance (inst ));
530533 if (err )
531534 goto out_free_inst ;
532535
533- inst -> alg .cra_flags = CRYPTO_ALG_TYPE_AHASH | CRYPTO_ALG_ASYNC ;
534- inst -> alg .cra_type = & crypto_ahash_type ;
536+ inst -> alg .halg .base .cra_flags = CRYPTO_ALG_ASYNC ;
535537
536- inst -> alg .cra_ahash .digestsize = salg -> digestsize ;
537- inst -> alg .cra_ctxsize = sizeof (struct cryptd_hash_ctx );
538+ inst -> alg .halg .digestsize = salg -> digestsize ;
539+ inst -> alg .halg . base . cra_ctxsize = sizeof (struct cryptd_hash_ctx );
538540
539- inst -> alg .cra_init = cryptd_hash_init_tfm ;
540- inst -> alg .cra_exit = cryptd_hash_exit_tfm ;
541+ inst -> alg .halg . base . cra_init = cryptd_hash_init_tfm ;
542+ inst -> alg .halg . base . cra_exit = cryptd_hash_exit_tfm ;
541543
542- inst -> alg .cra_ahash . init = cryptd_hash_init_enqueue ;
543- inst -> alg .cra_ahash . update = cryptd_hash_update_enqueue ;
544- inst -> alg .cra_ahash . final = cryptd_hash_final_enqueue ;
545- inst -> alg .cra_ahash . setkey = cryptd_hash_setkey ;
546- inst -> alg .cra_ahash . digest = cryptd_hash_digest_enqueue ;
544+ inst -> alg .init = cryptd_hash_init_enqueue ;
545+ inst -> alg .update = cryptd_hash_update_enqueue ;
546+ inst -> alg .final = cryptd_hash_final_enqueue ;
547+ inst -> alg .setkey = cryptd_hash_setkey ;
548+ inst -> alg .digest = cryptd_hash_digest_enqueue ;
547549
548- err = crypto_register_instance (tmpl , inst );
550+ err = ahash_register_instance (tmpl , inst );
549551 if (err ) {
550552 crypto_drop_shash (& ctx -> spawn );
551553out_free_inst :
@@ -580,6 +582,14 @@ static int cryptd_create(struct crypto_template *tmpl, struct rtattr **tb)
580582static void cryptd_free (struct crypto_instance * inst )
581583{
582584 struct cryptd_instance_ctx * ctx = crypto_instance_ctx (inst );
585+ struct hashd_instance_ctx * hctx = crypto_instance_ctx (inst );
586+
587+ switch (inst -> alg .cra_flags & CRYPTO_ALG_TYPE_MASK ) {
588+ case CRYPTO_ALG_TYPE_AHASH :
589+ crypto_drop_shash (& hctx -> spawn );
590+ kfree (ahash_instance (inst ));
591+ return ;
592+ }
583593
584594 crypto_drop_spawn (& ctx -> spawn );
585595 kfree (inst );
0 commit comments