Add SM2 signature algorithm to default provider#11248
Add SM2 signature algorithm to default provider#11248InfoHunter wants to merge 1 commit intoopenssl:masterfrom
Conversation
|
Perhaps I should skip CIs at current stage... |
|
Note that CIFuzz found a bug in this Pull request. It was not reported because CIfuzz was in dry_mode. |
Thanks and this PR is still not finished let's see if that exist after more commits are pushed. |
Since PR #11302 has been merged so I don't think this is a problem anymore |
|
@InfoHunter said this in #11302 (comment):
Not sure I understand the issue. The SM2 ID is set with |
|
Well, the calling sequence you mentioned requires the caller to set the ID by using |
|
You're right that The location for the EC control reimplementations is |
|
Actually I have some new ideas about the use case of handling the ID stuffs. It might be possible that some day in the future the compliance requirement changes to some new policies, say, the ID is required to less than 4 bytes..., so one can implement a 4-byte-ID-SM2 provider to comply with it... ;-) |
|
But this is low priority - need to get this PR done first |
|
Travis-CI failure is not relevant (timeout), considering to remove the |
crypto/sm2/sm2_aid.c
Outdated
There was a problem hiding this comment.
All of this seems a little overkill for one digest. Couldn't this be simplified on the assumption that there is only ever one interesting digest for use with SM2?
There was a problem hiding this comment.
Well, I am struggling with this. It seems that SM2 should only be used with SM3 since the spec says SM2 should only the hash functions designated by the cryptography administration department and, the only hash function defined in SM ciphers is SM3.
But this is the thing that interesting. SM2 actually can use other hash algorithm other than SM3. So what I consider is that if there are educational or experimental use cases that require to use other hash functions - for instance, to have a performance benchmark among different hash functions with SM2
There was a problem hiding this comment.
So maybe we need to provide the flexibility of the hash function choice and let the provider to decide if it will to be complied with Chinese validation programs.
There was a problem hiding this comment.
Yes...agree. Seems a little too much and could be removed.
There was a problem hiding this comment.
So, can we just delete this field? It seems unnecessary.
There was a problem hiding this comment.
Right, if we decide to limit the algorithm to SM3 only.
There was a problem hiding this comment.
Because initially when I was working on this file, I chose the name sm2_sign here and I found it conflicted with the internal sm2_sign - so I changed the sm2_sign into sm2sig_sign. I am not sure if other SM2 provider implementor will also confuse with this and feel it not convenient. (Other internal functions mostly are named with the upper-case name like ECDSA_sign or so)
There was a problem hiding this comment.
Other internal functions mostly are named with the upper-case name like ECDSA_sign or so
ECDSA_sign is (unfortunately) not internal. Generally speaking we prefer to reserve the capitilized form for external functions and non-capitalized for internal.
There was a problem hiding this comment.
So, it seems the name similar to sm2_internal_sign is more reasonable
There was a problem hiding this comment.
I changed the name to sm2_internal_sign and sm2_internal_verify respectively
There was a problem hiding this comment.
Should we simply disallow anything that isn't SM3?
There was a problem hiding this comment.
Not sure yet, all depend on how we treat https://github.com/openssl/openssl/pull/11248/files#r394931352
There was a problem hiding this comment.
Does it make sense to have this as a gettable parameter if the only digest we can ever have is SM3?
There was a problem hiding this comment.
Same answer as above ;-)
There was a problem hiding this comment.
Again - is this actually needed?
There was a problem hiding this comment.
Still the same issue...
|
@mattcaswell , for the SM3 considerations, I found in the legacy part there is not such limit, so do we need to limit that in default provider or should we just make it compatible with what legacy part does (OpenSSL 1.1.1) |
|
The |
|
Ping? |
|
What is the arrangement for this PR? Any dependencies yet? |
|
Ping @openssl/otc |
|
Should this be included in any alpha version? maybe the next alpha-2? |
|
This ought to be included at some point. It isn't essential for the alpha releases but it should be done before the first beta. I do not expect that any of the core team will have time to do this, we're relying on you or a Chinese compatriot to convert it into a provider based solution. The conversion isn't difficult, but it could be a bit tedious. |
|
@InfoHunter can you rebase this on latest master? A lot of things changed since the last push (sorry I did not find the time to review this sooner) so it would be better to test this against latest master. |
|
I believe it doesn't make much sense to include this without the corresponding keymgmt part |
|
Okay, no problem, I would probably find some time later next week to handle this. |
There was a problem hiding this comment.
Hmmm? I thought I have fixed this...Did you comment on an outdated code?
Okie, that's an argument.
Sure, but those signature operations, not keymgmt.
Only the keygen concern seems relevant for having a separate SM2 key type. |
Note that the legacy code for SM2 has changed in master, to avoid the dumber quirks that are still present in 1.1.1 |
@levitte they are still valid arguments because of this openssl/providers/implementations/keymgmt/ec_kmgmt.c Lines 54 to 64 in 93f99b6 The keymgmt says what are the operations names, so SM2 cannot reuse the EC keymgmt and then USE different operations! |
We have an open issue regarding the defect in the 1.1.1 implementation: #8435 (comment) The reason why it wasn't fixed yet is exactly because of how much in 1.1.1 SM2 and ec have been tied together due to the internal architecture and serialization/deserialization issues. |
We might have to re-think the returned value, for example make that a NULL-terminated array of string pointers instead of just one string. That would allow us to return |
We can only do so much! If the keys in PKCS#8 form don't have any indication other than the SM2 curve, we only have an educated guess, and in doing so, we would remove any possibility to run ECDSA with the SM2 curve or SM2 signatures with other curves. |
|
Deserialization is an issue bacuase the standardization of SM2 made them indistinguishable, true. Somewhere in the deserialization step we probably will need to keep defaulting to "create an SM2 key if this is serialized as an EC key over the so-called-SM2-curve". Yet it should be possible from an application that can sidestep or implement its own deserialization stage, to ask a provider to generate an EC key on the SM2 curve, and viceversa to generate an SM2 key on this nist curve. I don't see huge benefits in unifying again the SM2 and ec keymgmt, adding the complexity of multiple alternative options for the operations that a given key object supports. |
... and then it gets saved to file, and the next time it's read from that same file, it's suddenly potentially a different key type. If that isn't a source of confusion, I don't know what is. |
Well, I don't think the library can solve a confusion that is embedded in the result of the standardization process. Even having a single keymgmt for SM2 and EC will cause confusion if a user checks out the saved file: it is indistinguishable from an EC key on the SM2 curve. |
|
This is my personal opinion (and I am biased because it's my proposal), but I think that:
is going to be cleaner than
(*): depending on something internal and difficult to reach or override Yes, in both cases there will still be the issue of the confusion caused by the indistinguishability of the serialized format, but we can't really escape it until the SM2 spec is revised (and probably not even then, to retain compatibility with 1.1.1), but at least we avoid creating an overloaded key object standing for 2 different cryptosystems (keys are generated in different ways, they are associated with different operations) that only share (unluckily) the serialization format. |
|
Maybe @bbbrumley can share his thoughts about this as well, given that he has been struggling with trying to fix #8435 in 1.1.1 and can have even more insights on what could be done better at this time. |
One the advantages could be less code duplication. According to the discussions above, It seems the only difference we need to take care is the key generation process in the keymgmt scope. |
Why do you need to duplicate code? You could set a flag of some sort in the keydata (like we now do for the RSA sub-types), all that's needed then is a different constructor, and then pay attention to that flag in the few places where that's needed. The only thing that would be duplicated is the OSSL_DISPATCH array. I would much rather than a lot of code copying. |
|
This is just my opinion as some random guy on the Internet.
@levitte I feel like this is similar to the line of thinking that led to the 111 mess with SM2. "Well let's just piggy back off this -- it's similar enough" and turns out it wasn't, right?
I agree! And what you're doing in master is much better than the 111 state.
@romen I agree with this proposal. Even if it means duplicate code here and there, keep them as separate as possible. The way I look at it is this: what if SM2 had it's own OID that wasn't under the legacy EC hierarchy? Yes that is a standardization mistake, but put that aside. Step into fantasy land for a minute.
Ignore the standards mistake, and ask yourself these questions. I think you'll find the right decision for OpenSSL then. |
Thanks for the chuckle in these trying times! |
611110d to
c63f2a1
Compare
|
I just pushed a new commit containing the separated SM2 key management skeleton (and it's only a skeleton so please consider this as WIP at current stage). The current implementation is just a copy of the EC key management. According to what Nicola proposed in the emails during the weekend, I need to replace the content with SM2 implementation. We can have a discussion on this on the upcoming online meeting on Tuesday ;-) |
|
We could house the SM2 keymgmt in openssl/providers/implementations/keymgmt/rsa_kmgmt.c Lines 584 to 626 in 7e4f01d Most pointers in the dispatch table are identical, and only the ones that need to differ are actually different. This way we minimize duplication. At a first examination, I think the SM2 keymgmt should differ from the EC one in the following:
|
|
I am going to draw back the latest commits containing the keymgmt code in this PR and open a new PR to address this. |
And SM2 needn't to provide the ability of specifying curves, did we have a consensus on this yesterday? |
Regarding this I think the best course of action (and minimal work) is to leave the EC flexibility underneath, but filter so that if the curve id does not match That way when another supported curve is added to part 5 of the SM2 standards we just have to add one more entry to the allowlist and now we don't need to refractor extra code in the keymgmt. |
The SM2 user ID seems not a param with the key itself, this ID is involved in the SM2 signature computation progress which has been addressed by @levitte months ago IIRC. So it seems we don't need to consider supporting this in the key management part of SM2 |
c63f2a1 to
1dae589
Compare
|
As per #12536 (comment) and #12536 (comment) This PR is going to moved into PR #12536 , so this one can be closed now. |
Addressing #10357
This is still in a very early stage but the skeleton is almost done. I have several unclear things that need answers from the team:
how to pass values associated with the EVP_PKEY_CTX to the provider? (the SM2 identifier)how to turn the OID into DER format for the algorithm identifiers?Checklist