diff options
author | tb <> | 2023-09-10 16:53:56 +0000 |
---|---|---|
committer | tb <> | 2023-09-10 16:53:56 +0000 |
commit | 3ffd50d46144ae89cb26a04218127b0cf3038673 (patch) | |
tree | dc2f850c2a6a79fc072ad216f6c8f0ea4e6f3e92 | |
parent | bf15262a311df853b072fcf1dedb7cc8735057ea (diff) | |
download | openbsd-3ffd50d46144ae89cb26a04218127b0cf3038673.tar.gz openbsd-3ffd50d46144ae89cb26a04218127b0cf3038673.tar.bz2 openbsd-3ffd50d46144ae89cb26a04218127b0cf3038673.zip |
EVP_CipherInit(): use EVP_CIPHER_CTX_cleanup()
Before EVP_CIPHER_CTX was opaque, callers could pass an uninitialized
ctx into EVP_CipherInit() and calling EVP_CIPHER_CTX_cleanup() on such
a ctx would end in tears.
The only way to initialize a ctx is by way of EVP_CIPHER_CTX_new(), on
which we can call EVP_CIPHER_CTX_cleanup() and avoid silly leaks on ctx
reuse. This also allows some simplifications in the documentation.
There are more changes of this kind that should be done all over libcrypto.
They will be tackled in subsequent commits.
"makes a lot of sense" schwarze
ok jsing
-rw-r--r-- | src/lib/libcrypto/evp/evp_enc.c | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/src/lib/libcrypto/evp/evp_enc.c b/src/lib/libcrypto/evp/evp_enc.c index 27f753baa0..7534b4c9d2 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.52 2023/07/07 19:37:53 beck Exp $ */ | 1 | /* $OpenBSD: evp_enc.c,v 1.53 2023/09/10 16:53:56 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 | * |
@@ -78,8 +78,8 @@ int | |||
78 | EVP_CipherInit(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher, | 78 | EVP_CipherInit(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher, |
79 | const unsigned char *key, const unsigned char *iv, int enc) | 79 | const unsigned char *key, const unsigned char *iv, int enc) |
80 | { | 80 | { |
81 | if (cipher) | 81 | if (cipher != NULL) |
82 | EVP_CIPHER_CTX_init(ctx); | 82 | EVP_CIPHER_CTX_cleanup(ctx); |
83 | return EVP_CipherInit_ex(ctx, cipher, NULL, key, iv, enc); | 83 | return EVP_CipherInit_ex(ctx, cipher, NULL, key, iv, enc); |
84 | } | 84 | } |
85 | 85 | ||