diff options
Diffstat (limited to 'crypto/blkcipher.c')
-rw-r--r-- | crypto/blkcipher.c | 185 |
1 files changed, 0 insertions, 185 deletions
diff --git a/crypto/blkcipher.c b/crypto/blkcipher.c index 8cc1622b2ee0..369999530108 100644 --- a/crypto/blkcipher.c +++ b/crypto/blkcipher.c | |||
@@ -21,7 +21,6 @@ | |||
21 | #include <linux/hardirq.h> | 21 | #include <linux/hardirq.h> |
22 | #include <linux/kernel.h> | 22 | #include <linux/kernel.h> |
23 | #include <linux/module.h> | 23 | #include <linux/module.h> |
24 | #include <linux/scatterlist.h> | ||
25 | #include <linux/seq_file.h> | 24 | #include <linux/seq_file.h> |
26 | #include <linux/slab.h> | 25 | #include <linux/slab.h> |
27 | #include <linux/string.h> | 26 | #include <linux/string.h> |
@@ -466,10 +465,6 @@ static int crypto_init_blkcipher_ops_async(struct crypto_tfm *tfm) | |||
466 | crt->setkey = async_setkey; | 465 | crt->setkey = async_setkey; |
467 | crt->encrypt = async_encrypt; | 466 | crt->encrypt = async_encrypt; |
468 | crt->decrypt = async_decrypt; | 467 | crt->decrypt = async_decrypt; |
469 | if (!alg->ivsize) { | ||
470 | crt->givencrypt = skcipher_null_givencrypt; | ||
471 | crt->givdecrypt = skcipher_null_givdecrypt; | ||
472 | } | ||
473 | crt->base = __crypto_ablkcipher_cast(tfm); | 468 | crt->base = __crypto_ablkcipher_cast(tfm); |
474 | crt->ivsize = alg->ivsize; | 469 | crt->ivsize = alg->ivsize; |
475 | 470 | ||
@@ -560,185 +555,5 @@ const struct crypto_type crypto_blkcipher_type = { | |||
560 | }; | 555 | }; |
561 | EXPORT_SYMBOL_GPL(crypto_blkcipher_type); | 556 | EXPORT_SYMBOL_GPL(crypto_blkcipher_type); |
562 | 557 | ||
563 | static int crypto_grab_nivcipher(struct crypto_skcipher_spawn *spawn, | ||
564 | const char *name, u32 type, u32 mask) | ||
565 | { | ||
566 | struct crypto_alg *alg; | ||
567 | int err; | ||
568 | |||
569 | type = crypto_skcipher_type(type); | ||
570 | mask = crypto_skcipher_mask(mask)| CRYPTO_ALG_GENIV; | ||
571 | |||
572 | alg = crypto_alg_mod_lookup(name, type, mask); | ||
573 | if (IS_ERR(alg)) | ||
574 | return PTR_ERR(alg); | ||
575 | |||
576 | err = crypto_init_spawn(&spawn->base, alg, spawn->base.inst, mask); | ||
577 | crypto_mod_put(alg); | ||
578 | return err; | ||
579 | } | ||
580 | |||
581 | struct crypto_instance *skcipher_geniv_alloc(struct crypto_template *tmpl, | ||
582 | struct rtattr **tb, u32 type, | ||
583 | u32 mask) | ||
584 | { | ||
585 | struct { | ||
586 | int (*setkey)(struct crypto_ablkcipher *tfm, const u8 *key, | ||
587 | unsigned int keylen); | ||
588 | int (*encrypt)(struct ablkcipher_request *req); | ||
589 | int (*decrypt)(struct ablkcipher_request *req); | ||
590 | |||
591 | unsigned int min_keysize; | ||
592 | unsigned int max_keysize; | ||
593 | unsigned int ivsize; | ||
594 | |||
595 | const char *geniv; | ||
596 | } balg; | ||
597 | const char *name; | ||
598 | struct crypto_skcipher_spawn *spawn; | ||
599 | struct crypto_attr_type *algt; | ||
600 | struct crypto_instance *inst; | ||
601 | struct crypto_alg *alg; | ||
602 | int err; | ||
603 | |||
604 | algt = crypto_get_attr_type(tb); | ||
605 | if (IS_ERR(algt)) | ||
606 | return ERR_CAST(algt); | ||
607 | |||
608 | if ((algt->type ^ (CRYPTO_ALG_TYPE_GIVCIPHER | CRYPTO_ALG_GENIV)) & | ||
609 | algt->mask) | ||
610 | return ERR_PTR(-EINVAL); | ||
611 | |||
612 | name = crypto_attr_alg_name(tb[1]); | ||
613 | if (IS_ERR(name)) | ||
614 | return ERR_CAST(name); | ||
615 | |||
616 | inst = kzalloc(sizeof(*inst) + sizeof(*spawn), GFP_KERNEL); | ||
617 | if (!inst) | ||
618 | return ERR_PTR(-ENOMEM); | ||
619 | |||
620 | spawn = crypto_instance_ctx(inst); | ||
621 | |||
622 | /* Ignore async algorithms if necessary. */ | ||
623 | mask |= crypto_requires_sync(algt->type, algt->mask); | ||
624 | |||
625 | crypto_set_skcipher_spawn(spawn, inst); | ||
626 | err = crypto_grab_nivcipher(spawn, name, type, mask); | ||
627 | if (err) | ||
628 | goto err_free_inst; | ||
629 | |||
630 | alg = crypto_skcipher_spawn_alg(spawn); | ||
631 | |||
632 | if ((alg->cra_flags & CRYPTO_ALG_TYPE_MASK) == | ||
633 | CRYPTO_ALG_TYPE_BLKCIPHER) { | ||
634 | balg.ivsize = alg->cra_blkcipher.ivsize; | ||
635 | balg.min_keysize = alg->cra_blkcipher.min_keysize; | ||
636 | balg.max_keysize = alg->cra_blkcipher.max_keysize; | ||
637 | |||
638 | balg.setkey = async_setkey; | ||
639 | balg.encrypt = async_encrypt; | ||
640 | balg.decrypt = async_decrypt; | ||
641 | |||
642 | balg.geniv = alg->cra_blkcipher.geniv; | ||
643 | } else { | ||
644 | balg.ivsize = alg->cra_ablkcipher.ivsize; | ||
645 | balg.min_keysize = alg->cra_ablkcipher.min_keysize; | ||
646 | balg.max_keysize = alg->cra_ablkcipher.max_keysize; | ||
647 | |||
648 | balg.setkey = alg->cra_ablkcipher.setkey; | ||
649 | balg.encrypt = alg->cra_ablkcipher.encrypt; | ||
650 | balg.decrypt = alg->cra_ablkcipher.decrypt; | ||
651 | |||
652 | balg.geniv = alg->cra_ablkcipher.geniv; | ||
653 | } | ||
654 | |||
655 | err = -EINVAL; | ||
656 | if (!balg.ivsize) | ||
657 | goto err_drop_alg; | ||
658 | |||
659 | /* | ||
660 | * This is only true if we're constructing an algorithm with its | ||
661 | * default IV generator. For the default generator we elide the | ||
662 | * template name and double-check the IV generator. | ||
663 | */ | ||
664 | if (algt->mask & CRYPTO_ALG_GENIV) { | ||
665 | if (!balg.geniv) | ||
666 | balg.geniv = crypto_default_geniv(alg); | ||
667 | err = -EAGAIN; | ||
668 | if (strcmp(tmpl->name, balg.geniv)) | ||
669 | goto err_drop_alg; | ||
670 | |||
671 | memcpy(inst->alg.cra_name, alg->cra_name, CRYPTO_MAX_ALG_NAME); | ||
672 | memcpy(inst->alg.cra_driver_name, alg->cra_driver_name, | ||
673 | CRYPTO_MAX_ALG_NAME); | ||
674 | } else { | ||
675 | err = -ENAMETOOLONG; | ||
676 | if (snprintf(inst->alg.cra_name, CRYPTO_MAX_ALG_NAME, | ||
677 | "%s(%s)", tmpl->name, alg->cra_name) >= | ||
678 | CRYPTO_MAX_ALG_NAME) | ||
679 | goto err_drop_alg; | ||
680 | if (snprintf(inst->alg.cra_driver_name, CRYPTO_MAX_ALG_NAME, | ||
681 | "%s(%s)", tmpl->name, alg->cra_driver_name) >= | ||
682 | CRYPTO_MAX_ALG_NAME) | ||
683 | goto err_drop_alg; | ||
684 | } | ||
685 | |||
686 | inst->alg.cra_flags = CRYPTO_ALG_TYPE_GIVCIPHER | CRYPTO_ALG_GENIV; | ||
687 | inst->alg.cra_flags |= alg->cra_flags & CRYPTO_ALG_ASYNC; | ||
688 | inst->alg.cra_priority = alg->cra_priority; | ||
689 | inst->alg.cra_blocksize = alg->cra_blocksize; | ||
690 | inst->alg.cra_alignmask = alg->cra_alignmask; | ||
691 | inst->alg.cra_type = &crypto_givcipher_type; | ||
692 | |||
693 | inst->alg.cra_ablkcipher.ivsize = balg.ivsize; | ||
694 | inst->alg.cra_ablkcipher.min_keysize = balg.min_keysize; | ||
695 | inst->alg.cra_ablkcipher.max_keysize = balg.max_keysize; | ||
696 | inst->alg.cra_ablkcipher.geniv = balg.geniv; | ||
697 | |||
698 | inst->alg.cra_ablkcipher.setkey = balg.setkey; | ||
699 | inst->alg.cra_ablkcipher.encrypt = balg.encrypt; | ||
700 | inst->alg.cra_ablkcipher.decrypt = balg.decrypt; | ||
701 | |||
702 | out: | ||
703 | return inst; | ||
704 | |||
705 | err_drop_alg: | ||
706 | crypto_drop_skcipher(spawn); | ||
707 | err_free_inst: | ||
708 | kfree(inst); | ||
709 | inst = ERR_PTR(err); | ||
710 | goto out; | ||
711 | } | ||
712 | EXPORT_SYMBOL_GPL(skcipher_geniv_alloc); | ||
713 | |||
714 | void skcipher_geniv_free(struct crypto_instance *inst) | ||
715 | { | ||
716 | crypto_drop_skcipher(crypto_instance_ctx(inst)); | ||
717 | kfree(inst); | ||
718 | } | ||
719 | EXPORT_SYMBOL_GPL(skcipher_geniv_free); | ||
720 | |||
721 | int skcipher_geniv_init(struct crypto_tfm *tfm) | ||
722 | { | ||
723 | struct crypto_instance *inst = (void *)tfm->__crt_alg; | ||
724 | struct crypto_ablkcipher *cipher; | ||
725 | |||
726 | cipher = crypto_spawn_skcipher(crypto_instance_ctx(inst)); | ||
727 | if (IS_ERR(cipher)) | ||
728 | return PTR_ERR(cipher); | ||
729 | |||
730 | tfm->crt_ablkcipher.base = cipher; | ||
731 | tfm->crt_ablkcipher.reqsize += crypto_ablkcipher_reqsize(cipher); | ||
732 | |||
733 | return 0; | ||
734 | } | ||
735 | EXPORT_SYMBOL_GPL(skcipher_geniv_init); | ||
736 | |||
737 | void skcipher_geniv_exit(struct crypto_tfm *tfm) | ||
738 | { | ||
739 | crypto_free_ablkcipher(tfm->crt_ablkcipher.base); | ||
740 | } | ||
741 | EXPORT_SYMBOL_GPL(skcipher_geniv_exit); | ||
742 | |||
743 | MODULE_LICENSE("GPL"); | 558 | MODULE_LICENSE("GPL"); |
744 | MODULE_DESCRIPTION("Generic block chaining cipher type"); | 559 | MODULE_DESCRIPTION("Generic block chaining cipher type"); |