EVP: Implement data-driven translation between known ctrl and OSSL_PARAMs#13913
EVP: Implement data-driven translation between known ctrl and OSSL_PARAMs#13913levitte wants to merge 18 commits intoopenssl:masterfrom
Conversation
|
Note that this isn't finished yet, there are fixup functions missing. However, the functionality and structure have crystallised enough to make the idea reviewable. Please comment, even it doesn't build, early feedback welcome! |
|
The fixup functions need to know the insize and outsize of all params, right? This means that third-party providers cant add new controls. Or am I just misreading the code? |
|
@richsalz, I think you've misunderstood the purpose.
Regarding insize and outsize, the OSSL_PARAM structure already delivers that. However, the limiting factor is the ctrl functions, which do not easily supply this (well, you can pass the insize as So in the end, this is meant to support calling The life time of this source file is the same as the lifetime of legacy EVP_PKEYs, I totally expect them to be gone when ENGINE support is gone (ENGINE support being the last tangible reason why we retain legacy style EVP_PKEYs). That's also a reason to have all of this collected into one file. (while I'm at it, I also mean to clean away the current hackery which is spread all over the source instead of being concentrated to one spot, and that includes huge amounts of code copying ... you've heard me battle that tendency before 😉) |
|
This would be a great improvement! It would also allow to drop all the new convenience functions such as EVP_PKEY_get_group_name(). But on the other hand they could still be kept, just with very much simplified implementation. |
... and [ahem] we can revert all the older convenience functions to being macros calling |
|
Thank you for the detailed explanation. That should make it into the code/comments I think. At one point we liked the wrapper functions because they provided type-safety. |
IMO they definitely make sense for more common things. However for obscure parameters they make less sense as they contribute to API and code bloat. |
I agree that for ctrl wrapper, that's a nice benefit. |
e1afcbd to
0cc392f
Compare
|
Is there some test coverage in this area? I have some ad-hoc tests for legacy vs new EVP_PKEYs which I can clean up and supply a commit for. |
|
Please do, thank you 😊 |
|
Some tests. Will add checks for other get/set APIs in due course: |
|
Thanks Side note: github seemed to assume that commit belongs in openssl/openssl... it took me a moment to find out where it really belonged 😉 |
|
Linked to otc evaluated issue. |
9bb0069 to
634fc52
Compare
23b0d4c to
bce4661
Compare
00f8f72 to
df75f5a
Compare
|
There is one thing that comes to me a little bit awkward is that for the helper functions that used to call either set/get params or ctrl based on whether the key is legacy (like for example EVP_PKEY_CTX_set_dh_kdf_type()) we now call just the ctrl. Which is an obsolete API call so perhaps we should avoid using it internally. On the other hand it is indicative that it is extremely simple to convert the helpers to the ctrl call (as they were previously just macros, it makes it kind of obvious) but it is fairly harder to use the set/get_params instead. Could this mean we are missing some helper functions or macros for working with params? |
99bc21d to
2354269
Compare
|
Rebasing to resolve conflicts |
paulidale
left a comment
There was a problem hiding this comment.
Some little nits. Nothing significant.
Good comments, they really help with comprehension.
It's a bit of a shame to have such beautiful code for legacy support.
Legacy will go, but at least it will get to leave with some panache 😉 |
|
This triggers a question - should we deprecate EVP_PKEY_CTX_ctrl and all the other EVP*ctrl functions? |
Yes, we probably should. |
|
Issue filed #14287 for the deprecations. |
This does what was previously done by looking at pctx->pmeth->pkey_id, but handles both legacy and provider side contexts, and is supposed to become a replacement for the old way. Reviewed-by: Tomas Mraz <[email protected]> Reviewed-by: Paul Dale <[email protected]> (Merged from #13913)
This will help with transitioning diverse functions to be able to use the ctrl<->OSSL_PARAM translators. Reviewed-by: Tomas Mraz <[email protected]> Reviewed-by: Paul Dale <[email protected]> (Merged from #13913)
Reviewed-by: Tomas Mraz <[email protected]> Reviewed-by: Paul Dale <[email protected]> (Merged from #13913)
…RAMs The idea is to make it as transparent as possible to call things like EVP_PKEY_CTX_ctrl() with a provider backed EVP_PKEY_CTX, or things like EVP_PKEY_get_bn_param() with a legacy EVP_PKEY. All these sorts of calls demand that we translate between ctrl commands and OSSL_PARAM keys, and treat the arguments appropriately. This implementation has it being as data driven as possible, thereby centralizing everything into one table of translation data, which supports both directions. Fixes #13528 Reviewed-by: Tomas Mraz <[email protected]> Reviewed-by: Paul Dale <[email protected]> (Merged from #13913)
In the interest of calling these functions on legacy EVP_PKEY contexts, only check the settable / gettable params for provider side keys, leaving to the translated EVP_PKEY_CTX_ctrl() call check the ctrl commands on its own. Reviewed-by: Tomas Mraz <[email protected]> Reviewed-by: Paul Dale <[email protected]> (Merged from #13913)
EVP_PKEY_get_group_name() now simply calls EVP_PKEY_get_utf8_string_param().
EVP_PKEY_CTX_set_group_name() now simply calls EVP_PKEY_CTX_set_params().
EVP_PKEY_get_bn_param(), EVP_PKEY_get_octet_string_param(),
EVP_PKEY_get_utf8_string_param() and EVP_PKEY_get_int_param() can now
handle legacy EVP_PKEYs by calling evp_pkey_get_params_to_ctrl().
EVP_PKEY_CTX_get_params() can now handle a legacy backed EVP_PKEY_CTX
by calling evp_pkey_ctx_get_params_to_ctrl().
Note: EVP_PKEY_CTX_set_params() doesn't call the translator yet.
Should it ever?
Reviewed-by: Tomas Mraz <[email protected]>
Reviewed-by: Paul Dale <[email protected]>
(Merged from #13913)
legacy_ctrl_to_param() and legacy_ctrl_str_to_param() are now replaced with calls to evp_pkey_ctx_ctrl_to_param() and evp_pkey_ctx_ctrl_str_to_param(). Reviewed-by: Tomas Mraz <[email protected]> Reviewed-by: Paul Dale <[email protected]> (Merged from #13913)
Reviewed-by: Tomas Mraz <[email protected]> Reviewed-by: Paul Dale <[email protected]> (Merged from #13913)
Reviewed-by: Tomas Mraz <[email protected]> Reviewed-by: Paul Dale <[email protected]> (Merged from #13913)
It would check the keytype and optype before determining if it even supported the ctrl command number. This turned out to be disruptive, so we make it check that it supports the request ctrl command number first. Reviewed-by: Tomas Mraz <[email protected]> Reviewed-by: Paul Dale <[email protected]> (Merged from #13913)
Reviewed-by: Tomas Mraz <[email protected]> Reviewed-by: Paul Dale <[email protected]> (Merged from #13913)
|
Merged 6179dfc EVP: Implement EVP_PKEY_CTX_is_a() |
The idea is to make it as transparent as possible to call things like
EVP_PKEY_CTX_ctrl() with a provider backed EVP_PKEY_CTX, or things
like EVP_PKEY_get_bn_param() with a legacy EVP_PKEY.
All these sorts of calls demand that we translate between ctrl
commands and OSSL_PARAM keys, and treat the arguments appropriately.
This implementation has it being as data driven as possible, thereby
centralizing everything into one table of translation data, which
supports both directions.
Fixes #13528