hc
2024-05-11 04dd17822334871b23ea2862f7798fb0e0007777
kernel/crypto/vmac.c
....@@ -36,6 +36,7 @@
3636 #include <linux/scatterlist.h>
3737 #include <asm/byteorder.h>
3838 #include <crypto/scatterwalk.h>
39
+#include <crypto/internal/cipher.h>
3940 #include <crypto/internal/hash.h>
4041
4142 /*
....@@ -435,10 +436,8 @@
435436 unsigned int i;
436437 int err;
437438
438
- if (keylen != VMAC_KEY_LEN) {
439
- crypto_shash_set_flags(tfm, CRYPTO_TFM_RES_BAD_KEY_LEN);
439
+ if (keylen != VMAC_KEY_LEN)
440440 return -EINVAL;
441
- }
442441
443442 err = crypto_cipher_setkey(tctx->cipher, key, keylen);
444443 if (err)
....@@ -598,7 +597,7 @@
598597 static int vmac_init_tfm(struct crypto_tfm *tfm)
599598 {
600599 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);
602601 struct vmac_tfm_ctx *tctx = crypto_tfm_ctx(tfm);
603602 struct crypto_cipher *cipher;
604603
....@@ -620,32 +619,33 @@
620619 static int vmac_create(struct crypto_template *tmpl, struct rtattr **tb)
621620 {
622621 struct shash_instance *inst;
622
+ struct crypto_cipher_spawn *spawn;
623623 struct crypto_alg *alg;
624
+ u32 mask;
624625 int err;
625626
626
- err = crypto_check_attr_type(tb, CRYPTO_ALG_TYPE_SHASH);
627
+ err = crypto_check_attr_type(tb, CRYPTO_ALG_TYPE_SHASH, &mask);
627628 if (err)
628629 return err;
629630
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);
634641
635642 err = -EINVAL;
636643 if (alg->cra_blocksize != VMAC_NONCEBYTES)
637
- goto out_put_alg;
644
+ goto err_free_inst;
638645
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);
647647 if (err)
648
- goto out_free_inst;
648
+ goto err_free_inst;
649649
650650 inst->alg.base.cra_priority = alg->cra_priority;
651651 inst->alg.base.cra_blocksize = alg->cra_blocksize;
....@@ -662,21 +662,19 @@
662662 inst->alg.final = vmac_final;
663663 inst->alg.setkey = vmac_setkey;
664664
665
+ inst->free = shash_free_singlespawn_instance;
666
+
665667 err = shash_register_instance(tmpl, inst);
666668 if (err) {
667
-out_free_inst:
668
- shash_free_instance(shash_crypto_instance(inst));
669
+err_free_inst:
670
+ shash_free_singlespawn_instance(inst);
669671 }
670
-
671
-out_put_alg:
672
- crypto_mod_put(alg);
673672 return err;
674673 }
675674
676675 static struct crypto_template vmac64_tmpl = {
677676 .name = "vmac64",
678677 .create = vmac_create,
679
- .free = shash_free_instance,
680678 .module = THIS_MODULE,
681679 };
682680
....@@ -690,9 +688,10 @@
690688 crypto_unregister_template(&vmac64_tmpl);
691689 }
692690
693
-module_init(vmac_module_init);
691
+subsys_initcall(vmac_module_init);
694692 module_exit(vmac_module_exit);
695693
696694 MODULE_LICENSE("GPL");
697695 MODULE_DESCRIPTION("VMAC hash algorithm");
698696 MODULE_ALIAS_CRYPTO("vmac64");
697
+MODULE_IMPORT_NS(CRYPTO_INTERNAL);