diff options
author | jsing <> | 2022-09-04 07:54:59 +0000 |
---|---|---|
committer | jsing <> | 2022-09-04 07:54:59 +0000 |
commit | 837f40f79fcf594e0b81c0a317eb99a10b93a3bb (patch) | |
tree | 4a60c0e81122638c9bb15ee8e9e79bbebbc66469 /src/lib | |
parent | bd0c1e8c9f376fe4beec69a2931ce916e2f1e76a (diff) | |
download | openbsd-837f40f79fcf594e0b81c0a317eb99a10b93a3bb.tar.gz openbsd-837f40f79fcf594e0b81c0a317eb99a10b93a3bb.tar.bz2 openbsd-837f40f79fcf594e0b81c0a317eb99a10b93a3bb.zip |
Mechanically expand IMPLEMENT_CFBR macros.
Only change to generated assembly is due to the use of EVPerror().
Diffstat (limited to 'src/lib')
-rw-r--r-- | src/lib/libcrypto/evp/e_camellia.c | 275 |
1 files changed, 267 insertions, 8 deletions
diff --git a/src/lib/libcrypto/evp/e_camellia.c b/src/lib/libcrypto/evp/e_camellia.c index 46b918c163..42c036a7ab 100644 --- a/src/lib/libcrypto/evp/e_camellia.c +++ b/src/lib/libcrypto/evp/e_camellia.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: e_camellia.c,v 1.10 2022/09/03 20:06:43 jsing Exp $ */ | 1 | /* $OpenBSD: e_camellia.c,v 1.11 2022/09/04 07:54:59 jsing Exp $ */ |
2 | /* ==================================================================== | 2 | /* ==================================================================== |
3 | * Copyright (c) 2006 The OpenSSL Project. All rights reserved. | 3 | * Copyright (c) 2006 The OpenSSL Project. All rights reserved. |
4 | * | 4 | * |
@@ -558,17 +558,276 @@ EVP_camellia_256_ecb(void) | |||
558 | return &camellia_256_ecb; | 558 | return &camellia_256_ecb; |
559 | } | 559 | } |
560 | 560 | ||
561 | static int | ||
562 | camellia_128_cfb1_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned char *in, size_t inl) | ||
563 | { | ||
564 | size_t chunk = EVP_MAXCHUNK; | ||
565 | |||
566 | if (1 == 1) | ||
567 | chunk >>= 3; | ||
568 | |||
569 | if (inl < chunk) | ||
570 | chunk = inl; | ||
571 | |||
572 | while (inl && inl >= chunk) { | ||
573 | Camellia_cfb1_encrypt(in, out, (long)((1 == 1) && !(ctx->flags & EVP_CIPH_FLAG_LENGTH_BITS) ? inl * 8 : inl), &((EVP_CAMELLIA_KEY *)ctx->cipher_data)->ks, ctx->iv, &ctx->num, ctx->encrypt); | ||
574 | inl -= chunk; | ||
575 | in += chunk; | ||
576 | out += chunk; | ||
577 | if (inl < chunk) | ||
578 | chunk = inl; | ||
579 | } | ||
580 | |||
581 | return 1; | ||
582 | } | ||
583 | |||
584 | static const EVP_CIPHER camellia_128_cfb1 = { | ||
585 | .nid = NID_camellia_128_cfb1, | ||
586 | .block_size = 1, | ||
587 | .key_len = 128/8, | ||
588 | .iv_len = 16, | ||
589 | .flags = 0 | EVP_CIPH_CFB_MODE, | ||
590 | .init = camellia_init_key, | ||
591 | .do_cipher = camellia_128_cfb1_cipher, | ||
592 | .cleanup = NULL, | ||
593 | .ctx_size = sizeof(EVP_CAMELLIA_KEY), | ||
594 | .set_asn1_parameters = EVP_CIPHER_set_asn1_iv, | ||
595 | .get_asn1_parameters = EVP_CIPHER_get_asn1_iv, | ||
596 | .ctrl = NULL, | ||
597 | .app_data = NULL, | ||
598 | }; | ||
599 | |||
600 | const EVP_CIPHER * | ||
601 | EVP_camellia_128_cfb1(void) | ||
602 | { | ||
603 | return &camellia_128_cfb1; | ||
604 | } | ||
605 | |||
606 | static int | ||
607 | camellia_192_cfb1_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned char *in, size_t inl) | ||
608 | { | ||
609 | size_t chunk = EVP_MAXCHUNK; | ||
610 | |||
611 | if (1 == 1) | ||
612 | chunk >>= 3; | ||
613 | |||
614 | if (inl < chunk) | ||
615 | chunk = inl; | ||
616 | |||
617 | while (inl && inl >= chunk) { | ||
618 | Camellia_cfb1_encrypt(in, out, (long)((1 == 1) && !(ctx->flags & EVP_CIPH_FLAG_LENGTH_BITS) ? inl * 8 : inl), &((EVP_CAMELLIA_KEY *)ctx->cipher_data)->ks, ctx->iv, &ctx->num, ctx->encrypt); | ||
619 | inl -= chunk; | ||
620 | in += chunk; | ||
621 | out += chunk; | ||
622 | if (inl < chunk) | ||
623 | chunk = inl; | ||
624 | } | ||
625 | |||
626 | return 1; | ||
627 | } | ||
628 | |||
629 | static const EVP_CIPHER camellia_192_cfb1 = { | ||
630 | .nid = NID_camellia_192_cfb1, | ||
631 | .block_size = 1, | ||
632 | .key_len = 192/8, | ||
633 | .iv_len = 16, | ||
634 | .flags = 0 | EVP_CIPH_CFB_MODE, | ||
635 | .init = camellia_init_key, | ||
636 | .do_cipher = camellia_192_cfb1_cipher, | ||
637 | .cleanup = NULL, | ||
638 | .ctx_size = sizeof(EVP_CAMELLIA_KEY), | ||
639 | .set_asn1_parameters = EVP_CIPHER_set_asn1_iv, | ||
640 | .get_asn1_parameters = EVP_CIPHER_get_asn1_iv, | ||
641 | .ctrl = NULL, | ||
642 | .app_data = NULL, | ||
643 | }; | ||
644 | |||
645 | const EVP_CIPHER * | ||
646 | EVP_camellia_192_cfb1(void) | ||
647 | { | ||
648 | return &camellia_192_cfb1; | ||
649 | } | ||
650 | |||
651 | static int | ||
652 | camellia_256_cfb1_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned char *in, size_t inl) | ||
653 | { | ||
654 | size_t chunk = EVP_MAXCHUNK; | ||
655 | |||
656 | if (1 == 1) | ||
657 | chunk >>= 3; | ||
658 | |||
659 | if (inl < chunk) | ||
660 | chunk = inl; | ||
661 | |||
662 | while (inl && inl >= chunk) { | ||
663 | Camellia_cfb1_encrypt(in, out, (long)((1 == 1) && !(ctx->flags & EVP_CIPH_FLAG_LENGTH_BITS) ? inl * 8 : inl), &((EVP_CAMELLIA_KEY *)ctx->cipher_data)->ks, ctx->iv, &ctx->num, ctx->encrypt); | ||
664 | inl -= chunk; | ||
665 | in += chunk; | ||
666 | out += chunk; | ||
667 | if (inl < chunk) | ||
668 | chunk = inl; | ||
669 | } | ||
670 | |||
671 | return 1; | ||
672 | } | ||
673 | |||
674 | static const EVP_CIPHER camellia_256_cfb1 = { | ||
675 | .nid = NID_camellia_256_cfb1, | ||
676 | .block_size = 1, | ||
677 | .key_len = 256/8, | ||
678 | .iv_len = 16, | ||
679 | .flags = 0 | EVP_CIPH_CFB_MODE, | ||
680 | .init = camellia_init_key, | ||
681 | .do_cipher = camellia_256_cfb1_cipher, | ||
682 | .cleanup = NULL, | ||
683 | .ctx_size = sizeof(EVP_CAMELLIA_KEY), | ||
684 | .set_asn1_parameters = EVP_CIPHER_set_asn1_iv, | ||
685 | .get_asn1_parameters = EVP_CIPHER_get_asn1_iv, | ||
686 | .ctrl = NULL, | ||
687 | .app_data = NULL, | ||
688 | }; | ||
689 | |||
690 | const EVP_CIPHER * | ||
691 | EVP_camellia_256_cfb1(void) | ||
692 | { | ||
693 | return &camellia_256_cfb1; | ||
694 | } | ||
695 | |||
696 | |||
697 | static int | ||
698 | camellia_128_cfb8_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned char *in, size_t inl) | ||
699 | { | ||
700 | size_t chunk = EVP_MAXCHUNK; | ||
701 | |||
702 | if (8 == 1) | ||
703 | chunk >>= 3; | ||
704 | |||
705 | if (inl < chunk) | ||
706 | chunk = inl; | ||
707 | |||
708 | while (inl && inl >= chunk) { | ||
709 | Camellia_cfb8_encrypt(in, out, (long)((8 == 1) && !(ctx->flags & EVP_CIPH_FLAG_LENGTH_BITS) ? inl * 8 : inl), &((EVP_CAMELLIA_KEY *)ctx->cipher_data)->ks, ctx->iv, &ctx->num, ctx->encrypt); | ||
710 | inl -= chunk; | ||
711 | in += chunk; | ||
712 | out += chunk; | ||
713 | if (inl < chunk) | ||
714 | chunk = inl; | ||
715 | } | ||
716 | |||
717 | return 1; | ||
718 | } | ||
719 | |||
720 | static const EVP_CIPHER camellia_128_cfb8 = { | ||
721 | .nid = NID_camellia_128_cfb8, | ||
722 | .block_size = 1, | ||
723 | .key_len = 128/8, | ||
724 | .iv_len = 16, | ||
725 | .flags = 0 | EVP_CIPH_CFB_MODE, | ||
726 | .init = camellia_init_key, | ||
727 | .do_cipher = camellia_128_cfb8_cipher, | ||
728 | .cleanup = NULL, | ||
729 | .ctx_size = sizeof(EVP_CAMELLIA_KEY), | ||
730 | .set_asn1_parameters = EVP_CIPHER_set_asn1_iv, | ||
731 | .get_asn1_parameters = EVP_CIPHER_get_asn1_iv, | ||
732 | .ctrl = NULL, | ||
733 | .app_data = NULL, | ||
734 | }; | ||
735 | |||
736 | const EVP_CIPHER * | ||
737 | EVP_camellia_128_cfb8(void) | ||
738 | { | ||
739 | return &camellia_128_cfb8; | ||
740 | } | ||
741 | |||
742 | static int | ||
743 | camellia_192_cfb8_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned char *in, size_t inl) | ||
744 | { | ||
745 | size_t chunk = EVP_MAXCHUNK; | ||
746 | |||
747 | if (8 == 1) | ||
748 | chunk >>= 3; | ||
749 | |||
750 | if (inl < chunk) | ||
751 | chunk = inl; | ||
752 | |||
753 | while (inl && inl >= chunk) { | ||
754 | Camellia_cfb8_encrypt(in, out, (long)((8 == 1) && !(ctx->flags & EVP_CIPH_FLAG_LENGTH_BITS) ? inl * 8 : inl), &((EVP_CAMELLIA_KEY *)ctx->cipher_data)->ks, ctx->iv, &ctx->num, ctx->encrypt); | ||
755 | inl -= chunk; | ||
756 | in += chunk; | ||
757 | out += chunk; | ||
758 | if (inl < chunk) | ||
759 | chunk = inl; | ||
760 | } | ||
561 | 761 | ||
562 | #define IMPLEMENT_CAMELLIA_CFBR(ksize,cbits) IMPLEMENT_CFBR(camellia,Camellia,EVP_CAMELLIA_KEY,ks,ksize,cbits,16) | 762 | return 1; |
763 | } | ||
563 | 764 | ||
564 | IMPLEMENT_CAMELLIA_CFBR(128, 1) | 765 | static const EVP_CIPHER camellia_192_cfb8 = { |
565 | IMPLEMENT_CAMELLIA_CFBR(192, 1) | 766 | .nid = NID_camellia_192_cfb8, |
566 | IMPLEMENT_CAMELLIA_CFBR(256, 1) | 767 | .block_size = 1, |
768 | .key_len = 192/8, | ||
769 | .iv_len = 16, | ||
770 | .flags = 0 | EVP_CIPH_CFB_MODE, | ||
771 | .init = camellia_init_key, | ||
772 | .do_cipher = camellia_192_cfb8_cipher, | ||
773 | .cleanup = NULL, | ||
774 | .ctx_size = sizeof(EVP_CAMELLIA_KEY), | ||
775 | .set_asn1_parameters = EVP_CIPHER_set_asn1_iv, | ||
776 | .get_asn1_parameters = EVP_CIPHER_get_asn1_iv, | ||
777 | .ctrl = NULL, | ||
778 | .app_data = NULL, | ||
779 | }; | ||
567 | 780 | ||
568 | IMPLEMENT_CAMELLIA_CFBR(128, 8) | 781 | const EVP_CIPHER * |
569 | IMPLEMENT_CAMELLIA_CFBR(192, 8) | 782 | EVP_camellia_192_cfb8(void) |
570 | IMPLEMENT_CAMELLIA_CFBR(256, 8) | 783 | { |
784 | return &camellia_192_cfb8; | ||
785 | } | ||
786 | |||
787 | static int | ||
788 | camellia_256_cfb8_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned char *in, size_t inl) | ||
789 | { | ||
790 | size_t chunk = EVP_MAXCHUNK; | ||
791 | |||
792 | if (8 == 1) | ||
793 | chunk >>= 3; | ||
794 | |||
795 | if (inl < chunk) | ||
796 | chunk = inl; | ||
571 | 797 | ||
798 | while (inl && inl >= chunk) { | ||
799 | Camellia_cfb8_encrypt(in, out, (long)((8 == 1) && !(ctx->flags & EVP_CIPH_FLAG_LENGTH_BITS) ? inl * 8 : inl), &((EVP_CAMELLIA_KEY *)ctx->cipher_data)->ks, ctx->iv, &ctx->num, ctx->encrypt); | ||
800 | inl -= chunk; | ||
801 | in += chunk; | ||
802 | out += chunk; | ||
803 | if (inl < chunk) | ||
804 | chunk = inl; | ||
805 | } | ||
806 | |||
807 | return 1; | ||
808 | } | ||
809 | |||
810 | static const EVP_CIPHER camellia_256_cfb8 = { | ||
811 | .nid = NID_camellia_256_cfb8, | ||
812 | .block_size = 1, | ||
813 | .key_len = 256/8, | ||
814 | .iv_len = 16, | ||
815 | .flags = 0 | EVP_CIPH_CFB_MODE, | ||
816 | .init = camellia_init_key, | ||
817 | .do_cipher = camellia_256_cfb8_cipher, | ||
818 | .cleanup = NULL, | ||
819 | .ctx_size = sizeof(EVP_CAMELLIA_KEY), | ||
820 | .set_asn1_parameters = EVP_CIPHER_set_asn1_iv, | ||
821 | .get_asn1_parameters = EVP_CIPHER_get_asn1_iv, | ||
822 | .ctrl = NULL, | ||
823 | .app_data = NULL, | ||
824 | }; | ||
825 | |||
826 | const EVP_CIPHER * | ||
827 | EVP_camellia_256_cfb8(void) | ||
828 | { | ||
829 | return &camellia_256_cfb8; | ||
830 | } | ||
572 | 831 | ||
573 | /* The subkey for Camellia is generated. */ | 832 | /* The subkey for Camellia is generated. */ |
574 | static int | 833 | static int |