Conversation
|
THIS IS A VERY EARLY DRAFT! It is incomplete and doesn't even build right. I just wanted to expose the idea of being able to switch the keytype of the EC key structure. |
|
Heh, it turns out that this must wait on #11248, since there are tests that generate an SM2 key in this PR, and then have signature failing because that hasn't been implemented yet. |
|
I think we should discuss the approach of mixing SM2 and EC keygen.
|
|
I think we should discuss the approach of mixing SM2 and EC keygen.
Generally speaking, it's a good question, and it basically comes down to "no surprise". Essentially, the way the new legacy code works is by detection, i.e. change the key type based on curve name, currently only for SM2, but hang on, it'll be more interesting as I continue 😉. For the "push" that you mention, i.e. check at generation if the curve name was "SM2", and in that case, switch over to ask for an SM2 keymgmt instead of the EC keymgmt... this involves much more, and I think that this also ties into what you've talked about elsewhere, to be able to have keytypes that contain a bit more information, for example to be able to specify, say, the keytype "EC-P239v1".
So question is, when happens with the next key type that has similar properties, but is otherwise different? On the vid call today, you mentioned RSA (I supposed you meant things like RSASSA-PSS and RSAES-OAEP), so we'd have to hack in special knowledge about those. And then there was something about DSA... Do you see where I'm going with this, and how things could become quite "interesting" indeed?
I'll have to study that issue. I wonder if that could even be the issue to kill |
|
For SM2 my argument is slightly different than for ECDH/ECDSA over different curves.
So, originally, the issue of coercing "EC(DSA/DH) over SM2 ECC" serialized objects into "SM2" memory objects, could have been an issue to be handled only on deserialization, but the way we handled SM2 in 1.1.1 has created a problem that we have to deal with:
Relevant standardsUsing https://github.com/alipay/tls13-sm-spec and https://github.com/metanorma/gmt-0009-2012 for English translations.
Last one shows some ingredients for encoding private and public keys, but is not complete. |
Wait what?
I wholeheartedly agree with this. Upon a closer look, that won't be very much of a breaking change either. Basically, |
Well, technically it is not false, it happens that both ECDH and ECDSA were defined to share the key generation algorithm. I was oversimplifying, and focusing on the digital signature side of things, as we can see from the table above also SM2 can be declined not only in a digital signature algorithm, but also in key exchange/derivation (a la ECDH) and for public key encryption. |
|
I said:
I didn't look close enough, it's a bit more than that. |
|
Having looked around at the code in |
|
In the same vein, I'm move away the keytype change feature from this PR, even though I see uses in the future (if we do decide to "upgrade" EC keys to composite "EC-{grp}" key types)... |
|
I reworked this to really only include provider side EC key generation, and let `EVP_PKEY_gen() detect the SM2 curve, and downgrade it to a legacy key. This is as close to emulating what legacy EC key generation currently does as I can imagine. |
|
This is not a draft any more. Comments welcome |
Is it still pending on other PRs? Is the WIP label still appropriate? |
At least #11358, which quickly fixes the issues with
I want to try this PR merged with #11358 to see that they want to play well together. I'll remove the WIP marker when I've been able to do so. |
|
Still a couple of travis failures remaining (issues noted above) |
|
I could have sworn I had pushed exactly those fixes, @mattcaswell. Now done... |
romen
left a comment
There was a problem hiding this comment.
I have been slowly testing during the long weekend and this LGTM.
|
This pull request is ready to merge |
Reviewed-by: Matt Caswell <[email protected]> Reviewed-by: Nicola Tuveri <[email protected]> (Merged from #11328)
Reviewed-by: Matt Caswell <[email protected]> Reviewed-by: Nicola Tuveri <[email protected]> (Merged from #11328)
The macros are converted to functions, and are modified to support provider implementations. Reviewed-by: Matt Caswell <[email protected]> Reviewed-by: Nicola Tuveri <[email protected]> (Merged from #11328)
The reason to do this is many-fold. We need EC key generation for other work. However, SM2 are currently closely related to EC keys with legacy methods, but not with provider methods. To avoid having to wait on provider support for SM2, we temporarly do an extra check for what the legacy methods identify as SM2 keys (either the EVP_PKEY_SM2 pkey id was used, or the SM2 curve), and redirect to legacy code in one case, and in the other case, we forcedly downgrade provider side EC keys with SM2 curves to legacy SM2 keys, using available tools. Reviewed-by: Matt Caswell <[email protected]> Reviewed-by: Nicola Tuveri <[email protected]> (Merged from #11328)
The EVP_KEYMGMT pointer in the pkey is removed when downgrading, but wasn't necessarily freed when need, thus leaving an incorrect reference count. Reviewed-by: Matt Caswell <[email protected]> Reviewed-by: Nicola Tuveri <[email protected]> (Merged from #11328)
|
Merged 2b9add6 KEYMGMT: Add functions to get param/key generation parameters |
Both implemented at the same time, because they are so very closely related.
To get the same kind of functionality as with legacy keys, where we can basically switch back and forth between the EC and SM2 keytypes, this adds a
OP_keymgmt_gen_get_params, which can really be used to get all kinds of information from the key generation, but for the moment, it's used to get the resulting keytype after generation.UPDATE: SM2 key generation removed, and there's a hack in
crypto/evp/pmeth_gn.cto handle them by downgrading to legacy keys when appropriate