| .. | .. |
|---|
| 36 | 36 | #include <linux/scatterlist.h> |
|---|
| 37 | 37 | #include <asm/byteorder.h> |
|---|
| 38 | 38 | #include <crypto/scatterwalk.h> |
|---|
| 39 | +#include <crypto/internal/cipher.h> |
|---|
| 39 | 40 | #include <crypto/internal/hash.h> |
|---|
| 40 | 41 | |
|---|
| 41 | 42 | /* |
|---|
| .. | .. |
|---|
| 435 | 436 | unsigned int i; |
|---|
| 436 | 437 | int err; |
|---|
| 437 | 438 | |
|---|
| 438 | | - if (keylen != VMAC_KEY_LEN) { |
|---|
| 439 | | - crypto_shash_set_flags(tfm, CRYPTO_TFM_RES_BAD_KEY_LEN); |
|---|
| 439 | + if (keylen != VMAC_KEY_LEN) |
|---|
| 440 | 440 | return -EINVAL; |
|---|
| 441 | | - } |
|---|
| 442 | 441 | |
|---|
| 443 | 442 | err = crypto_cipher_setkey(tctx->cipher, key, keylen); |
|---|
| 444 | 443 | if (err) |
|---|
| .. | .. |
|---|
| 598 | 597 | static int vmac_init_tfm(struct crypto_tfm *tfm) |
|---|
| 599 | 598 | { |
|---|
| 600 | 599 | struct crypto_instance *inst = crypto_tfm_alg_instance(tfm); |
|---|
| 601 | | - struct crypto_spawn *spawn = crypto_instance_ctx(inst); |
|---|
| 600 | + struct crypto_cipher_spawn *spawn = crypto_instance_ctx(inst); |
|---|
| 602 | 601 | struct vmac_tfm_ctx *tctx = crypto_tfm_ctx(tfm); |
|---|
| 603 | 602 | struct crypto_cipher *cipher; |
|---|
| 604 | 603 | |
|---|
| .. | .. |
|---|
| 620 | 619 | static int vmac_create(struct crypto_template *tmpl, struct rtattr **tb) |
|---|
| 621 | 620 | { |
|---|
| 622 | 621 | struct shash_instance *inst; |
|---|
| 622 | + struct crypto_cipher_spawn *spawn; |
|---|
| 623 | 623 | struct crypto_alg *alg; |
|---|
| 624 | + u32 mask; |
|---|
| 624 | 625 | int err; |
|---|
| 625 | 626 | |
|---|
| 626 | | - err = crypto_check_attr_type(tb, CRYPTO_ALG_TYPE_SHASH); |
|---|
| 627 | + err = crypto_check_attr_type(tb, CRYPTO_ALG_TYPE_SHASH, &mask); |
|---|
| 627 | 628 | if (err) |
|---|
| 628 | 629 | return err; |
|---|
| 629 | 630 | |
|---|
| 630 | | - alg = crypto_get_attr_alg(tb, CRYPTO_ALG_TYPE_CIPHER, |
|---|
| 631 | | - CRYPTO_ALG_TYPE_MASK); |
|---|
| 632 | | - if (IS_ERR(alg)) |
|---|
| 633 | | - return PTR_ERR(alg); |
|---|
| 631 | + inst = kzalloc(sizeof(*inst) + sizeof(*spawn), GFP_KERNEL); |
|---|
| 632 | + if (!inst) |
|---|
| 633 | + return -ENOMEM; |
|---|
| 634 | + spawn = shash_instance_ctx(inst); |
|---|
| 635 | + |
|---|
| 636 | + err = crypto_grab_cipher(spawn, shash_crypto_instance(inst), |
|---|
| 637 | + crypto_attr_alg_name(tb[1]), 0, mask); |
|---|
| 638 | + if (err) |
|---|
| 639 | + goto err_free_inst; |
|---|
| 640 | + alg = crypto_spawn_cipher_alg(spawn); |
|---|
| 634 | 641 | |
|---|
| 635 | 642 | err = -EINVAL; |
|---|
| 636 | 643 | if (alg->cra_blocksize != VMAC_NONCEBYTES) |
|---|
| 637 | | - goto out_put_alg; |
|---|
| 644 | + goto err_free_inst; |
|---|
| 638 | 645 | |
|---|
| 639 | | - inst = shash_alloc_instance(tmpl->name, alg); |
|---|
| 640 | | - err = PTR_ERR(inst); |
|---|
| 641 | | - if (IS_ERR(inst)) |
|---|
| 642 | | - goto out_put_alg; |
|---|
| 643 | | - |
|---|
| 644 | | - err = crypto_init_spawn(shash_instance_ctx(inst), alg, |
|---|
| 645 | | - shash_crypto_instance(inst), |
|---|
| 646 | | - CRYPTO_ALG_TYPE_MASK); |
|---|
| 646 | + err = crypto_inst_setname(shash_crypto_instance(inst), tmpl->name, alg); |
|---|
| 647 | 647 | if (err) |
|---|
| 648 | | - goto out_free_inst; |
|---|
| 648 | + goto err_free_inst; |
|---|
| 649 | 649 | |
|---|
| 650 | 650 | inst->alg.base.cra_priority = alg->cra_priority; |
|---|
| 651 | 651 | inst->alg.base.cra_blocksize = alg->cra_blocksize; |
|---|
| .. | .. |
|---|
| 662 | 662 | inst->alg.final = vmac_final; |
|---|
| 663 | 663 | inst->alg.setkey = vmac_setkey; |
|---|
| 664 | 664 | |
|---|
| 665 | + inst->free = shash_free_singlespawn_instance; |
|---|
| 666 | + |
|---|
| 665 | 667 | err = shash_register_instance(tmpl, inst); |
|---|
| 666 | 668 | if (err) { |
|---|
| 667 | | -out_free_inst: |
|---|
| 668 | | - shash_free_instance(shash_crypto_instance(inst)); |
|---|
| 669 | +err_free_inst: |
|---|
| 670 | + shash_free_singlespawn_instance(inst); |
|---|
| 669 | 671 | } |
|---|
| 670 | | - |
|---|
| 671 | | -out_put_alg: |
|---|
| 672 | | - crypto_mod_put(alg); |
|---|
| 673 | 672 | return err; |
|---|
| 674 | 673 | } |
|---|
| 675 | 674 | |
|---|
| 676 | 675 | static struct crypto_template vmac64_tmpl = { |
|---|
| 677 | 676 | .name = "vmac64", |
|---|
| 678 | 677 | .create = vmac_create, |
|---|
| 679 | | - .free = shash_free_instance, |
|---|
| 680 | 678 | .module = THIS_MODULE, |
|---|
| 681 | 679 | }; |
|---|
| 682 | 680 | |
|---|
| .. | .. |
|---|
| 690 | 688 | crypto_unregister_template(&vmac64_tmpl); |
|---|
| 691 | 689 | } |
|---|
| 692 | 690 | |
|---|
| 693 | | -module_init(vmac_module_init); |
|---|
| 691 | +subsys_initcall(vmac_module_init); |
|---|
| 694 | 692 | module_exit(vmac_module_exit); |
|---|
| 695 | 693 | |
|---|
| 696 | 694 | MODULE_LICENSE("GPL"); |
|---|
| 697 | 695 | MODULE_DESCRIPTION("VMAC hash algorithm"); |
|---|
| 698 | 696 | MODULE_ALIAS_CRYPTO("vmac64"); |
|---|
| 697 | +MODULE_IMPORT_NS(CRYPTO_INTERNAL); |
|---|