summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authortb <>2023-12-26 09:04:30 +0000
committertb <>2023-12-26 09:04:30 +0000
commitd9fc8c2bb8070dda582528ac18d1b7c5dbdbc66e (patch)
tree8d00017df4520e4a3984b24d36feccf3d87160c4 /src/lib
parent36bb2ac5a296266e1cb29ed2ba5bab36231b3e10 (diff)
downloadopenbsd-d9fc8c2bb8070dda582528ac18d1b7c5dbdbc66e.tar.gz
openbsd-d9fc8c2bb8070dda582528ac18d1b7c5dbdbc66e.tar.bz2
openbsd-d9fc8c2bb8070dda582528ac18d1b7c5dbdbc66e.zip
EVP_CipherInit(): remove cleanup call
There is a bizarre EVP_CIPHER_CTX_cleanup() call in EVP_CipherInit() leading to a subtle behavior difference with EVP_CipherInit_ex(). The history is that before EVP_CIPHER_CTX was made opaque, a context would often live on the stack (hello, MariaDB) and the EVP_CIPHER_CTX_cleanup() call was in fact an EVP_CIPHER_CTX_init() which just zeroes out the struct. The problem with doing this is that on context reuse there could be data hanging off it, causing leaks. Attempts were made to clean up things in EVP_CipherFinal*(), but that broke applications reaching into the context afterward, so they were removed again. Later on, opacity allowed changing the _init() to a _cleanup() since EVP_CIPHER_CTX could no longer live on the stack, so it would no longer contain garbage. I have to correct myself: it would no longer contain stack garbage. Now: EVP_CipherInit_ex() does some extra dances to preserve the AES key wrap flag, which is cleared unconditionally in EVP_CipherInit(). That's annoying to document and very likely never going to be an issue in the wild: you'd need to do key wrap and then use the same context for use with a cipher that does not allow key wrap for this to make a difference. This way, all our EVP_{Cipher,Decrypt,Encrypt}*_ex() functions are now trivially wrapped by their non-_ex() versions. ok jsing
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/libcrypto/evp/evp_enc.c4
1 files changed, 1 insertions, 3 deletions
diff --git a/src/lib/libcrypto/evp/evp_enc.c b/src/lib/libcrypto/evp/evp_enc.c
index 7c25b59dce..3eef53c2d6 100644
--- a/src/lib/libcrypto/evp/evp_enc.c
+++ b/src/lib/libcrypto/evp/evp_enc.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: evp_enc.c,v 1.80 2023/12/26 08:39:28 tb Exp $ */ 1/* $OpenBSD: evp_enc.c,v 1.81 2023/12/26 09:04:30 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 *
@@ -72,8 +72,6 @@ int
72EVP_CipherInit(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher, 72EVP_CipherInit(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher,
73 const unsigned char *key, const unsigned char *iv, int enc) 73 const unsigned char *key, const unsigned char *iv, int enc)
74{ 74{
75 if (cipher != NULL)
76 EVP_CIPHER_CTX_cleanup(ctx);
77 return EVP_CipherInit_ex(ctx, cipher, NULL, key, iv, enc); 75 return EVP_CipherInit_ex(ctx, cipher, NULL, key, iv, enc);
78} 76}
79 77