summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTheo Buehler <tb@cvs.openbsd.org>2023-12-26 08:39:29 +0000
committerTheo Buehler <tb@cvs.openbsd.org>2023-12-26 08:39:29 +0000
commite42951aa5d08a6dc5dd54cf670deed016de83d52 (patch)
tree874e29ea02b9e470ea48794432404c27c520cb64
parentd8dddd107fe1ddc5415268ffd0cd6e1ba40b5fec (diff)
EVP_CipherInit_ex() merge two code paths
Clean up the cipher context unconditionally if the cipher is being set. This allows doing the dance to retain the key wrap flag only once and makes it more obvious that allocating the cipher data doesn't leak. suggested by/ok jsing
-rw-r--r--lib/libcrypto/evp/evp_enc.c13
1 files changed, 4 insertions, 9 deletions
diff --git a/lib/libcrypto/evp/evp_enc.c b/lib/libcrypto/evp/evp_enc.c
index 1bde05f4935..7c25b59dce5 100644
--- a/lib/libcrypto/evp/evp_enc.c
+++ b/lib/libcrypto/evp/evp_enc.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: evp_enc.c,v 1.79 2023/12/23 13:05:06 tb Exp $ */
+/* $OpenBSD: evp_enc.c,v 1.80 2023/12/26 08:39:28 tb Exp $ */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
@@ -93,23 +93,18 @@ EVP_CipherInit_ex(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher, ENGINE *engine,
}
/*
- * If the ctx is reused and a cipher is passed in, reset the ctx but
- * remember enc and whether key wrap was enabled.
+ * Set up cipher and context. Allocate cipher data and initialize ctx.
+ * On ctx reuse only retain encryption direction and key wrap flag.
*/
- if (cipher != NULL && ctx->cipher != NULL) {
+ if (cipher != NULL) {
unsigned long flags = ctx->flags;
EVP_CIPHER_CTX_cleanup(ctx);
-
ctx->encrypt = enc;
ctx->flags = flags & EVP_CIPHER_CTX_FLAG_WRAP_ALLOW;
- }
- /* Set up cipher. Allocate cipher data and initialize if necessary. */
- if (cipher != NULL) {
ctx->cipher = cipher;
ctx->key_len = cipher->key_len;
- ctx->flags &= EVP_CIPHER_CTX_FLAG_WRAP_ALLOW;
if (ctx->cipher->ctx_size != 0) {
ctx->cipher_data = calloc(1, ctx->cipher->ctx_size);