diff options
| author | Neil Horman <[email protected]> | 2026-05-07 23:05:11 +0200 |
|---|---|---|
| committer | Neil Horman <[email protected]> | 2026-06-25 23:25:05 +0200 |
| commit | d031b650a11dec0ac1976a29bc79445e044a4a2b (patch) | |
| tree | 48c217c76e63367c967d4d650bb3f5e2089266e0 /crypto/evp | |
| parent | Make EVP_MD's not need to take reference counts (diff) | |
| download | openssl-d031b650a11dec0ac1976a29bc79445e044a4a2b.tar.gz openssl-d031b650a11dec0ac1976a29bc79445e044a4a2b.zip | |
Make EVP_CIPHERS not need to take reference counts
Reviewed-by: Bob Beck <[email protected]>
Reviewed-by: Nikola Pajkovsky <[email protected]>
MergeDate: Thu Jun 25 21:25:49 2026
(Merged from https://github.com/openssl/openssl/pull/31143)
Diffstat (limited to 'crypto/evp')
| -rw-r--r-- | crypto/evp/evp_enc.c | 56 |
1 files changed, 32 insertions, 24 deletions
diff --git a/crypto/evp/evp_enc.c b/crypto/evp/evp_enc.c index a23846fdf13..07efde94e93 100644 --- a/crypto/evp/evp_enc.c +++ b/crypto/evp/evp_enc.c @@ -1340,6 +1340,30 @@ static void set_legacy_nid(const char *name, void *vlegacy_nid) } #endif +static int evp_cipher_up_ref(void *c) +{ + EVP_CIPHER *cipher = (EVP_CIPHER *)c; + int ref = 0; + + if (cipher->origin == EVP_ORIG_DYNAMIC) + CRYPTO_UP_REF(&cipher->refcnt, &ref); + return 1; +} + +static void evp_cipher_free(void *c) +{ + EVP_CIPHER *cipher = (EVP_CIPHER *)c; + int i; + + if (cipher == NULL || cipher->origin != EVP_ORIG_DYNAMIC) + return; + + CRYPTO_DOWN_REF(&cipher->refcnt, &i); + if (i > 0) + return; + evp_cipher_free_int(cipher); +} + static void *evp_cipher_from_algorithm(const int name_id, const OSSL_ALGORITHM *algodef, OSSL_PROVIDER *prov) @@ -1511,20 +1535,10 @@ static void *evp_cipher_from_algorithm(const int name_id, return cipher; err: - EVP_CIPHER_free(cipher); + evp_cipher_free(cipher); return NULL; } -static int evp_cipher_up_ref(void *cipher) -{ - return EVP_CIPHER_up_ref(cipher); -} - -static void evp_cipher_free(void *cipher) -{ - EVP_CIPHER_free(cipher); -} - EVP_CIPHER *EVP_CIPHER_fetch(OSSL_LIB_CTX *ctx, const char *algorithm, const char *properties) { @@ -1557,11 +1571,11 @@ int EVP_CIPHER_can_pipeline(const EVP_CIPHER *cipher, int enc) int EVP_CIPHER_up_ref(EVP_CIPHER *cipher) { - int ref = 0; - - if (cipher->origin == EVP_ORIG_DYNAMIC) - CRYPTO_UP_REF(&cipher->refcnt, &ref); +#ifdef OPENSSL_NO_CACHED_FETCH + return evp_cipher_up_ref(cipher); +#else return 1; +#endif } void evp_cipher_free_int(EVP_CIPHER *cipher) @@ -1574,15 +1588,9 @@ void evp_cipher_free_int(EVP_CIPHER *cipher) void EVP_CIPHER_free(EVP_CIPHER *cipher) { - int i; - - if (cipher == NULL || cipher->origin != EVP_ORIG_DYNAMIC) - return; - - CRYPTO_DOWN_REF(&cipher->refcnt, &i); - if (i > 0) - return; - evp_cipher_free_int(cipher); +#ifdef OPENSSL_NO_CACHED_FETCH + evp_cipher_free(cipher); +#endif } void EVP_CIPHER_do_all_provided(OSSL_LIB_CTX *libctx, |
