summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authortb <>2024-01-02 21:12:25 +0000
committertb <>2024-01-02 21:12:25 +0000
commit216b98e81b538b1efad6f22921c31880951ae373 (patch)
treee0d4ebdada31b4e1c251c10fc7d46b54954df143 /src
parentaef2d8eade403830e2678e242586504b864edea7 (diff)
downloadopenbsd-216b98e81b538b1efad6f22921c31880951ae373.tar.gz
openbsd-216b98e81b538b1efad6f22921c31880951ae373.tar.bz2
openbsd-216b98e81b538b1efad6f22921c31880951ae373.zip
Move down EVP_CIPHER_CTX accessors expose EVP_CIPHER internals
These confusingly named getters were added "for convenience" in 1.1. They fit best next to the EVP_CIPHER API.
Diffstat (limited to 'src')
-rw-r--r--src/lib/libcrypto/evp/evp_cipher.c80
1 files changed, 42 insertions, 38 deletions
diff --git a/src/lib/libcrypto/evp/evp_cipher.c b/src/lib/libcrypto/evp/evp_cipher.c
index 367cfb6e67..d8e802e94b 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.10 2024/01/02 20:48:40 tb Exp $ */ 1/* $OpenBSD: evp_cipher.c,v 1.11 2024/01/02 21:12:25 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 *
@@ -740,12 +740,6 @@ EVP_CIPHER_CTX_copy(EVP_CIPHER_CTX *out, const EVP_CIPHER_CTX *in)
740 return 1; 740 return 1;
741} 741}
742 742
743int
744EVP_CIPHER_CTX_block_size(const EVP_CIPHER_CTX *ctx)
745{
746 return ctx->cipher->block_size;
747}
748
749const EVP_CIPHER * 743const EVP_CIPHER *
750EVP_CIPHER_CTX_cipher(const EVP_CIPHER_CTX *ctx) 744EVP_CIPHER_CTX_cipher(const EVP_CIPHER_CTX *ctx)
751{ 745{
@@ -758,12 +752,6 @@ EVP_CIPHER_CTX_encrypting(const EVP_CIPHER_CTX *ctx)
758 return ctx->encrypt; 752 return ctx->encrypt;
759} 753}
760 754
761unsigned long
762EVP_CIPHER_CTX_flags(const EVP_CIPHER_CTX *ctx)
763{
764 return ctx->cipher->flags;
765}
766
767void * 755void *
768EVP_CIPHER_CTX_get_app_data(const EVP_CIPHER_CTX *ctx) 756EVP_CIPHER_CTX_get_app_data(const EVP_CIPHER_CTX *ctx)
769{ 757{
@@ -793,25 +781,6 @@ EVP_CIPHER_CTX_set_cipher_data(EVP_CIPHER_CTX *ctx, void *cipher_data)
793 return old_cipher_data; 781 return old_cipher_data;
794} 782}
795 783
796int
797EVP_CIPHER_CTX_iv_length(const EVP_CIPHER_CTX *ctx)
798{
799 int iv_length = 0;
800
801 if ((ctx->cipher->flags & EVP_CIPH_FLAG_CUSTOM_IV_LENGTH) == 0)
802 return ctx->cipher->iv_len;
803
804 /*
805 * XXX - sanity would suggest to pass the size of the pointer along,
806 * but unfortunately we have to match the other crowd.
807 */
808 if (EVP_CIPHER_CTX_ctrl((EVP_CIPHER_CTX *)ctx, EVP_CTRL_GET_IVLEN, 0,
809 &iv_length) != 1)
810 return -1;
811
812 return iv_length;
813}
814
815unsigned char * 784unsigned char *
816EVP_CIPHER_CTX_buf_noconst(EVP_CIPHER_CTX *ctx) 785EVP_CIPHER_CTX_buf_noconst(EVP_CIPHER_CTX *ctx)
817{ 786{
@@ -825,12 +794,6 @@ EVP_CIPHER_CTX_key_length(const EVP_CIPHER_CTX *ctx)
825} 794}
826 795
827int 796int
828EVP_CIPHER_CTX_nid(const EVP_CIPHER_CTX *ctx)
829{
830 return ctx->cipher->nid;
831}
832
833int
834EVP_CIPHER_CTX_get_iv(const EVP_CIPHER_CTX *ctx, unsigned char *iv, size_t len) 797EVP_CIPHER_CTX_get_iv(const EVP_CIPHER_CTX *ctx, unsigned char *iv, size_t len)
835{ 798{
836 if (ctx == NULL || len != EVP_CIPHER_CTX_iv_length(ctx)) 799 if (ctx == NULL || len != EVP_CIPHER_CTX_iv_length(ctx))
@@ -887,6 +850,47 @@ EVP_CIPHER_CTX_test_flags(const EVP_CIPHER_CTX *ctx, int flags)
887} 850}
888 851
889/* 852/*
853 * EVP_CIPHER_CTX getters that reach into the cipher attachted to the contex.
854 */
855
856int
857EVP_CIPHER_CTX_nid(const EVP_CIPHER_CTX *ctx)
858{
859 return ctx->cipher->nid;
860}
861
862int
863EVP_CIPHER_CTX_block_size(const EVP_CIPHER_CTX *ctx)
864{
865 return ctx->cipher->block_size;
866}
867
868int
869EVP_CIPHER_CTX_iv_length(const EVP_CIPHER_CTX *ctx)
870{
871 int iv_length = 0;
872
873 if ((ctx->cipher->flags & EVP_CIPH_FLAG_CUSTOM_IV_LENGTH) == 0)
874 return ctx->cipher->iv_len;
875
876 /*
877 * XXX - sanity would suggest to pass the size of the pointer along,
878 * but unfortunately we have to match the other crowd.
879 */
880 if (EVP_CIPHER_CTX_ctrl((EVP_CIPHER_CTX *)ctx, EVP_CTRL_GET_IVLEN, 0,
881 &iv_length) != 1)
882 return -1;
883
884 return iv_length;
885}
886
887unsigned long
888EVP_CIPHER_CTX_flags(const EVP_CIPHER_CTX *ctx)
889{
890 return ctx->cipher->flags;
891}
892
893/*
890 * Used by CMS and its predecessors. Only GOST and RC2 have a custom method. 894 * Used by CMS and its predecessors. Only GOST and RC2 have a custom method.
891 */ 895 */
892 896