diff options
author | Richard Levitte <levitte@openssl.org> | 2019-11-01 16:56:31 +0100 |
---|---|---|
committer | Richard Levitte <levitte@openssl.org> | 2019-11-03 18:33:43 +0100 |
commit | 3ee348b0dc5cd904fc2c022e6543f478c3d78732 (patch) | |
tree | 0cb4dd05a834849502e12a6b253a3d21198389c6 /crypto | |
parent | 60653e5b25242555446f8acf0abd5ab9ff83010c (diff) |
Change EVP_PKEY_CTX_new_provided() to take a library context too.
With provided algorithms, the library context is ever present, so of
course it should be specified alongside the algorithm name and
property query string.
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/10308)
Diffstat (limited to 'crypto')
-rw-r--r-- | crypto/evp/pmeth_lib.c | 24 |
1 files changed, 19 insertions, 5 deletions
diff --git a/crypto/evp/pmeth_lib.c b/crypto/evp/pmeth_lib.c index 5ba844f53e..d547e5a69d 100644 --- a/crypto/evp/pmeth_lib.c +++ b/crypto/evp/pmeth_lib.c @@ -111,7 +111,8 @@ const EVP_PKEY_METHOD *EVP_PKEY_meth_find(int type) return (**ret)(); } -static EVP_PKEY_CTX *int_ctx_new(EVP_PKEY *pkey, ENGINE *e, +static EVP_PKEY_CTX *int_ctx_new(OPENSSL_CTX *libctx, + EVP_PKEY *pkey, ENGINE *e, const char *name, const char *propquery, int id) { @@ -149,6 +150,16 @@ static EVP_PKEY_CTX *int_ctx_new(EVP_PKEY *pkey, ENGINE *e, if (e == NULL) name = OBJ_nid2sn(id); propquery = NULL; + /* + * We were called using legacy data, or an EVP_PKEY, but an EVP_PKEY + * isn't tied to a specific library context, so we fall back to the + * default library context. + * TODO(v3.0): an EVP_PKEY that doesn't originate from a leagacy key + * structure only has the pkeys[] cache, where the first element is + * considered the "origin". Investigate if that could be a suitable + * way to find a library context. + */ + libctx = NULL; #ifndef OPENSSL_NO_ENGINE if (e == NULL && pkey != NULL) @@ -191,6 +202,7 @@ static EVP_PKEY_CTX *int_ctx_new(EVP_PKEY *pkey, ENGINE *e, EVPerr(EVP_F_INT_CTX_NEW, ERR_R_MALLOC_FAILURE); return NULL; } + ret->libctx = libctx; ret->algorithm = name; ret->propquery = propquery; ret->engine = e; @@ -303,18 +315,19 @@ void EVP_PKEY_meth_free(EVP_PKEY_METHOD *pmeth) EVP_PKEY_CTX *EVP_PKEY_CTX_new(EVP_PKEY *pkey, ENGINE *e) { - return int_ctx_new(pkey, e, NULL, NULL, -1); + return int_ctx_new(NULL, pkey, e, NULL, NULL, -1); } EVP_PKEY_CTX *EVP_PKEY_CTX_new_id(int id, ENGINE *e) { - return int_ctx_new(NULL, e, NULL, NULL, id); + return int_ctx_new(NULL, NULL, e, NULL, NULL, id); } -EVP_PKEY_CTX *EVP_PKEY_CTX_new_provided(const char *name, +EVP_PKEY_CTX *EVP_PKEY_CTX_new_provided(OPENSSL_CTX *libctx, + const char *name, const char *propquery) { - return int_ctx_new(NULL, NULL, name, propquery, -1); + return int_ctx_new(libctx, NULL, NULL, name, propquery, -1); } EVP_PKEY_CTX *EVP_PKEY_CTX_dup(const EVP_PKEY_CTX *pctx) @@ -344,6 +357,7 @@ EVP_PKEY_CTX *EVP_PKEY_CTX_dup(const EVP_PKEY_CTX *pctx) EVP_PKEY_up_ref(pctx->pkey); rctx->pkey = pctx->pkey; rctx->operation = pctx->operation; + rctx->libctx = pctx->libctx; rctx->algorithm = pctx->algorithm; rctx->propquery = pctx->propquery; |