Repository navigation
Add the ability to set raw private/public keys in EVP - #5520
mattcaswell wants to merge 14 commits into
Conversation
|
@kroeckx - any thoughts on this? |
|
I've some thoughts on this...
|
There was a problem hiding this comment.
You should add functions to set these, in crypto/asn1/ameth_lib.c, and document them in doc/man3/EVP_PKEY_ASN1_METHOD.pod
Well I was thinking slightly differently. I see the private/public keys set via these functions as just a block of binary data without any real structure to it. Instead, where there are algos which require a structured key we should have an individual function for each of them, e.g. Each of those would then take the relevant component parts required to construct the key as arguments e.g. You can of course already do this today by creating an But all of that is for a different PR. I wanted to see how this one was received first. |
|
New commit pushed addressing comments. |
|
Ping @levitte. |
Not all algorithms will support this, since their keys are not a simple block of data. But many can.
Also to use the new EVP_PKEY_new_CMAC_key()
Also adds some documentation for related existing functions/macros
Previously private and public keys had to be pem encoded to be read by evp_test. This enables us to embed the raw private/public key values in the test file. The algorithm has to support EVP_PKEY_new_private_key() and EVP_PKEY_new_public_key() for this to work.
Include more information about how to create keys for these algorithms.
0cfbc19 to
962d262
Compare
|
Rebased to resolve a conflict with master. @levitte? |
|
I read your explanation, and while I understand what you say and can get along with that, I stil think that a very generic name like However, unless the intent is to have the function being used as generically as the name suggests (regardless of the itty gritty details in the docs), I cannot see that function name as acceptable. |
|
So would EVP_PKEY_new_binary_key or EVP_PKEY_new_raw_key be better names? |
|
That's not really the point... but you know, whatever @mattcaswell says, I'm sure that sooner or later, someone is going to want to create RSA keys that way, and will implement the necessary method. With that line of thought, I can play :-) |
|
... although, even though add |
Renamed to EVP_PKEY_new_raw_private_key()/EVP_new_raw_public_key() as per feedback.
|
Ok I did the rename (pushed). Is this better @levitte? |
|
Pushed (I fixed a trivial whitespace issue in libcrypto.num first). |
Not all algorithms will support this, since their keys are not a simple block of data. But many can. Reviewed-by: Richard Levitte <[email protected]> (Merged from #5520)
Reviewed-by: Richard Levitte <[email protected]> (Merged from #5520)
Reviewed-by: Richard Levitte <[email protected]> (Merged from #5520)
Reviewed-by: Richard Levitte <[email protected]> (Merged from #5520)
Reviewed-by: Richard Levitte <[email protected]> (Merged from #5520)
Reviewed-by: Richard Levitte <[email protected]> (Merged from #5520)
Also to use the new EVP_PKEY_new_CMAC_key() Reviewed-by: Richard Levitte <[email protected]> (Merged from #5520)
Also adds some documentation for related existing functions/macros Reviewed-by: Richard Levitte <[email protected]> (Merged from #5520)
Previously private and public keys had to be pem encoded to be read by evp_test. This enables us to embed the raw private/public key values in the test file. The algorithm has to support EVP_PKEY_new_private_key() and EVP_PKEY_new_public_key() for this to work. Reviewed-by: Richard Levitte <[email protected]> (Merged from #5520)
Reviewed-by: Richard Levitte <[email protected]> (Merged from #5520)
Include more information about how to create keys for these algorithms. Reviewed-by: Richard Levitte <[email protected]> (Merged from #5520)
Reviewed-by: Richard Levitte <[email protected]> (Merged from #5520)
Reviewed-by: Richard Levitte <[email protected]> (Merged from #5520)
Renamed to EVP_PKEY_new_raw_private_key()/EVP_new_raw_public_key() as per feedback. Reviewed-by: Richard Levitte <[email protected]> (Merged from #5520)
|
Any chance to get a set of functions to export the raw key data to a buffer to use elsewhere outside of openssl? |
|
It's too late to add this new feature for this release, sorry. |
Darn...I should have added that. Please could you create an issue for this? |
|
Yes I will thanks, and even if it doesn't make it in the current release, it would be very useful to have in a future release. |
|
@mattcaswell @kareldonk I can confirm that a feature to export raw keys would be very useful. I use Curve25519 and send the public keys on the wire in JSON Web Key format (RFC7517). I can import the peer key received on the wire with EVP_PKEY_new_public_key() and derive the shared secret. For exporting I just read the last 32 bytes (BITSTRING) from the EVP_PKEY. Would be nice to have a cleaner solution in the next release. |
The EVP interface that we have for X25519/X448/Ed25519/X25519 is very bare bones and provides just enough to use it for TLS. It is difficult to use directly because it is hard to setup private/public keys. You either have to load them from a file, or generate completely new ones. If you have the raw key data from some external source you cannot get OpenSSL to use it.
This PR adds functions to enable that. It provides a new function which is almost identical in behaviour to the existing EVP_PKEY_new_mac_key(). This PR introduces the function EVP_PKEY_new_private_key() which can be used by all the 25519/448 functions, as well as all of the functions supported by EVP_PKEY_new_mac_key(). Although the external behaviour between the two is similar the internal implementation is completely different. The initial attempt to implement these new functions was in #5419 and was heavily based on the EVP_PKEY_new_mac_key() implementation. However that implementation turned out to be controversial and was therefore removed from #5419.
This new PR implements the same functions as were removed from #5419 but does so in a completely different (and I hope less controversial) way.
I think this should be included in the beta1 release.
Checklist