diff options
author | Aaron Thompson <dev@aaront.org> | 2020-04-07 00:18:09 +0000 |
---|---|---|
committer | Dmitry Belyavskiy <beldmit@gmail.com> | 2020-04-14 17:58:17 +0300 |
commit | ff1f7cdeb159e89ce305422b6e2a7e4002d825ab (patch) | |
tree | 84c03fb009b4be1564009aae97d66509be9e3e19 /crypto | |
parent | 0437435a960123be1ced766d18d715f939698345 (diff) |
Add ex_data to EVP_PKEY.
Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Dmitry Belyavskiy <beldmit@gmail.com>
(Merged from https://github.com/openssl/openssl/pull/11515)
Diffstat (limited to 'crypto')
-rw-r--r-- | crypto/evp/p_lib.c | 27 |
1 files changed, 25 insertions, 2 deletions
diff --git a/crypto/evp/p_lib.c b/crypto/evp/p_lib.c index 85b5cc8127..c1a8a8804d 100644 --- a/crypto/evp/p_lib.c +++ b/crypto/evp/p_lib.c @@ -96,6 +96,16 @@ int EVP_PKEY_save_parameters(EVP_PKEY *pkey, int mode) return 0; } +int EVP_PKEY_set_ex_data(EVP_PKEY *key, int idx, void *arg) +{ + return CRYPTO_set_ex_data(&key->ex_data, idx, arg); +} + +void *EVP_PKEY_get_ex_data(const EVP_PKEY *key, int idx) +{ + return CRYPTO_get_ex_data(&key->ex_data, idx); +} + int EVP_PKEY_copy_parameters(EVP_PKEY *to, const EVP_PKEY *from) { /* @@ -1090,10 +1100,20 @@ EVP_PKEY *EVP_PKEY_new(void) ret->lock = CRYPTO_THREAD_lock_new(); if (ret->lock == NULL) { EVPerr(EVP_F_EVP_PKEY_NEW, ERR_R_MALLOC_FAILURE); - OPENSSL_free(ret); - return NULL; + goto err; + } +#ifndef FIPS_MODE + if (!CRYPTO_new_ex_data(CRYPTO_EX_INDEX_EVP_PKEY, ret, &ret->ex_data)) { + EVPerr(EVP_F_EVP_PKEY_NEW, ERR_R_MALLOC_FAILURE); + goto err; } +#endif return ret; + + err: + CRYPTO_THREAD_lock_free(ret->lock); + OPENSSL_free(ret); + return NULL; } /* @@ -1328,6 +1348,9 @@ void EVP_PKEY_free(EVP_PKEY *x) return; REF_ASSERT_ISNT(i < 0); evp_pkey_free_it(x); +#ifndef FIPS_MODE + CRYPTO_free_ex_data(CRYPTO_EX_INDEX_EVP_PKEY, x, &x->ex_data); +#endif CRYPTO_THREAD_lock_free(x->lock); #ifndef FIPS_MODE sk_X509_ATTRIBUTE_pop_free(x->attributes, X509_ATTRIBUTE_free); |