summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authortb <>2024-01-02 21:24:42 +0000
committertb <>2024-01-02 21:24:42 +0000
commit16b520c3902de336471d389012fb6c3b57ff3bcd (patch)
tree6e777567de9e2a8a12030ed376ee1d40244294e3 /src
parent216b98e81b538b1efad6f22921c31880951ae373 (diff)
downloadopenbsd-16b520c3902de336471d389012fb6c3b57ff3bcd.tar.gz
openbsd-16b520c3902de336471d389012fb6c3b57ff3bcd.tar.bz2
openbsd-16b520c3902de336471d389012fb6c3b57ff3bcd.zip
Match struct order for the EVP_CIPHER_CTX accessors
This isn't great since the struct is ordered in about the silliest way imaginable, but it is better than it was before. Bringing order into this mess is harder than solving a Rubik's cube.
Diffstat (limited to 'src')
-rw-r--r--src/lib/libcrypto/evp/evp_cipher.c142
1 files changed, 73 insertions, 69 deletions
diff --git a/src/lib/libcrypto/evp/evp_cipher.c b/src/lib/libcrypto/evp/evp_cipher.c
index d8e802e94b..1ee52cb615 100644
--- a/src/lib/libcrypto/evp/evp_cipher.c
+++ b/src/lib/libcrypto/evp/evp_cipher.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: evp_cipher.c,v 1.11 2024/01/02 21:12:25 tb Exp $ */ 1/* $OpenBSD: evp_cipher.c,v 1.12 2024/01/02 21:24:42 tb Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -643,33 +643,6 @@ EVP_CIPHER_CTX_cleanup(EVP_CIPHER_CTX *ctx)
643} 643}
644 644
645int 645int
646EVP_CIPHER_CTX_set_key_length(EVP_CIPHER_CTX *ctx, int key_len)
647{
648 /* XXX - remove this. It's unused. */
649 if (ctx->cipher->flags & EVP_CIPH_CUSTOM_KEY_LENGTH)
650 return EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_SET_KEY_LENGTH,
651 key_len, NULL);
652 if (ctx->key_len == key_len)
653 return 1;
654 if (key_len > 0 && (ctx->cipher->flags & EVP_CIPH_VARIABLE_LENGTH)) {
655 ctx->key_len = key_len;
656 return 1;
657 }
658 EVPerror(EVP_R_INVALID_KEY_LENGTH);
659 return 0;
660}
661
662int
663EVP_CIPHER_CTX_set_padding(EVP_CIPHER_CTX *ctx, int pad)
664{
665 if (pad)
666 ctx->flags &= ~EVP_CIPH_NO_PADDING;
667 else
668 ctx->flags |= EVP_CIPH_NO_PADDING;
669 return 1;
670}
671
672int
673EVP_CIPHER_CTX_ctrl(EVP_CIPHER_CTX *ctx, int type, int arg, void *ptr) 646EVP_CIPHER_CTX_ctrl(EVP_CIPHER_CTX *ctx, int type, int arg, void *ptr)
674{ 647{
675 int ret; 648 int ret;
@@ -740,6 +713,10 @@ EVP_CIPHER_CTX_copy(EVP_CIPHER_CTX *out, const EVP_CIPHER_CTX *in)
740 return 1; 713 return 1;
741} 714}
742 715
716/*
717 * EVP_CIPHER_CTX accessors.
718 */
719
743const EVP_CIPHER * 720const EVP_CIPHER *
744EVP_CIPHER_CTX_cipher(const EVP_CIPHER_CTX *ctx) 721EVP_CIPHER_CTX_cipher(const EVP_CIPHER_CTX *ctx)
745{ 722{
@@ -752,47 +729,6 @@ EVP_CIPHER_CTX_encrypting(const EVP_CIPHER_CTX *ctx)
752 return ctx->encrypt; 729 return ctx->encrypt;
753} 730}
754 731
755void *
756EVP_CIPHER_CTX_get_app_data(const EVP_CIPHER_CTX *ctx)
757{
758 return ctx->app_data;
759}
760
761void
762EVP_CIPHER_CTX_set_app_data(EVP_CIPHER_CTX *ctx, void *data)
763{
764 ctx->app_data = data;
765}
766
767void *
768EVP_CIPHER_CTX_get_cipher_data(const EVP_CIPHER_CTX *ctx)
769{
770 return ctx->cipher_data;
771}
772
773void *
774EVP_CIPHER_CTX_set_cipher_data(EVP_CIPHER_CTX *ctx, void *cipher_data)
775{
776 void *old_cipher_data;
777
778 old_cipher_data = ctx->cipher_data;
779 ctx->cipher_data = cipher_data;
780
781 return old_cipher_data;
782}
783
784unsigned char *
785EVP_CIPHER_CTX_buf_noconst(EVP_CIPHER_CTX *ctx)
786{
787 return ctx->buf;
788}
789
790int
791EVP_CIPHER_CTX_key_length(const EVP_CIPHER_CTX *ctx)
792{
793 return ctx->key_len;
794}
795
796int 732int
797EVP_CIPHER_CTX_get_iv(const EVP_CIPHER_CTX *ctx, unsigned char *iv, size_t len) 733EVP_CIPHER_CTX_get_iv(const EVP_CIPHER_CTX *ctx, unsigned char *iv, size_t len)
798{ 734{
@@ -831,6 +767,57 @@ EVP_CIPHER_CTX_set_iv(EVP_CIPHER_CTX *ctx, const unsigned char *iv, size_t len)
831 return 1; 767 return 1;
832} 768}
833 769
770unsigned char *
771EVP_CIPHER_CTX_buf_noconst(EVP_CIPHER_CTX *ctx)
772{
773 return ctx->buf;
774}
775
776void *
777EVP_CIPHER_CTX_get_app_data(const EVP_CIPHER_CTX *ctx)
778{
779 return ctx->app_data;
780}
781
782void
783EVP_CIPHER_CTX_set_app_data(EVP_CIPHER_CTX *ctx, void *data)
784{
785 ctx->app_data = data;
786}
787
788int
789EVP_CIPHER_CTX_key_length(const EVP_CIPHER_CTX *ctx)
790{
791 return ctx->key_len;
792}
793
794int
795EVP_CIPHER_CTX_set_key_length(EVP_CIPHER_CTX *ctx, int key_len)
796{
797 /* XXX - remove this. It's unused. */
798 if (ctx->cipher->flags & EVP_CIPH_CUSTOM_KEY_LENGTH)
799 return EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_SET_KEY_LENGTH,
800 key_len, NULL);
801 if (ctx->key_len == key_len)
802 return 1;
803 if (key_len > 0 && (ctx->cipher->flags & EVP_CIPH_VARIABLE_LENGTH)) {
804 ctx->key_len = key_len;
805 return 1;
806 }
807 EVPerror(EVP_R_INVALID_KEY_LENGTH);
808 return 0;
809}
810
811int
812EVP_CIPHER_CTX_set_padding(EVP_CIPHER_CTX *ctx, int pad)
813{
814 if (pad)
815 ctx->flags &= ~EVP_CIPH_NO_PADDING;
816 else
817 ctx->flags |= EVP_CIPH_NO_PADDING;
818 return 1;
819}
820
834void 821void
835EVP_CIPHER_CTX_set_flags(EVP_CIPHER_CTX *ctx, int flags) 822EVP_CIPHER_CTX_set_flags(EVP_CIPHER_CTX *ctx, int flags)
836{ 823{
@@ -849,6 +836,23 @@ EVP_CIPHER_CTX_test_flags(const EVP_CIPHER_CTX *ctx, int flags)
849 return (ctx->flags & flags); 836 return (ctx->flags & flags);
850} 837}
851 838
839void *
840EVP_CIPHER_CTX_get_cipher_data(const EVP_CIPHER_CTX *ctx)
841{
842 return ctx->cipher_data;
843}
844
845void *
846EVP_CIPHER_CTX_set_cipher_data(EVP_CIPHER_CTX *ctx, void *cipher_data)
847{
848 void *old_cipher_data;
849
850 old_cipher_data = ctx->cipher_data;
851 ctx->cipher_data = cipher_data;
852
853 return old_cipher_data;
854}
855
852/* 856/*
853 * EVP_CIPHER_CTX getters that reach into the cipher attachted to the contex. 857 * EVP_CIPHER_CTX getters that reach into the cipher attachted to the contex.
854 */ 858 */