Repository navigation
WIP: Add scrypt as EVP_PKEY_METHOD - #4026
johndoe31415 wants to merge 3 commits into
Conversation
|
@snhenson Regarding your comment about the uint64_t parsing, is maybe sscanf with the SCNu64 macro defined in <inttypes.h> something we can use? Only came to my mind after-the-fact. |
|
I don't know if there is a portable way to do things. Some of the obscure platforms of interest might not even have sscanf hence my question. |
There was a problem hiding this comment.
I'd suggest macros for these too. So something like EVP_PKEY_CTX_set_scrypt_N etc. as we do with the TLS PRF. The uint64_t cases maybe a new wrapper function that takes a uint64_t parameter and passes it to the underlying ctrl as a pointer?
|
Just do the "obvious" |
|
@richsalz The parser in evp_test.c isn't entirely correct, however. It will successfully parse 18446744073709551616 as 0 up including 18446744073709551619 (which it parses as 3). For the test I figured this to be okay, but for code that's actively used I thought this might be unwanted. Therefore the own parser. |
There was a problem hiding this comment.
Typo in comment which I thought I'd fixed. I meant add ": scrypt" at the end. That should keep SN_id_scrypt unchanged (which we should do for compatibility reasons) and add a new LN_id_scrypt.
There was a problem hiding this comment.
Hmmm, still not sure about this. Just tried it like this:
1 3 6 1 4 1 11591 4 11 : id-scrypt : scrypt
But then the NID symbol name changes from NID_id_scrypt to NID_scrypt and I get
crypto/asn1/p5_scrypt.c: In function ‘pkcs5_scrypt_set’:
crypto/asn1/p5_scrypt.c:202:38: error: ‘NID_id_scrypt’ undeclared (first use in this function)
keyfunc->algorithm = OBJ_nid2obj(NID_id_scrypt);
Is this okay, i.e., should I simply change all occurences of NID_id_scrcypt to NID_scrypt?
There was a problem hiding this comment.
Hmm... try this:
!Cname id-scrypt
1 3 6 1 4 1 11591 4 11 : id-scrypt : scrypt
There was a problem hiding this comment.
Tried this as well (see latest commit) -- still doesn't work unfortunately.
|
Rebased to master, because I'm unsure if the build failure is because of something I accidently messed up in objects.txt. |
|
FYI now #4079 has been implemented using "scrypt" for the name in evp_test and pkeyutl should work. |
|
Thank you, @snhenson -- I just rebased to be able to use your changes and will try it our right away! |
|
Worked perfectly. Thank you again, @snhenson! With the major roadblocks out the way, I figure adding PBKDF2 is quite straightforward. If there aren't any objections, I'd get to it then? Maybe one more question about a corner case: The current way that the PKEY_METHOD scrypt implementation handles passphrases and salts, it isn't possible to specify a zero-length password or salt. Therefore the testcase for this (which was present in testing the scrypt PBE) is commented out for KDF-scrypt. It's an esoteric corner case, should I change the code so that it's possible to set zero-length salt/passphrase for the scrypt KDF as well? |
There was a problem hiding this comment.
I think it's important that we find a way to support this. The reason is that in future I'd like to make EVP_PKEY_METHOD the preferred interface for scrypt (and other PBE algorithms) so it must be at least as flexible as the underlying function. I can think of several ways to do that, one is to allocate the fields when set even if they're zero length so the != NULL check passes.
There was a problem hiding this comment.
Done for PBKDF2 right off the bat and for scrypt now as well with 305df7b.
|
This is looking closer to something which can be included. Couple of additions needed though: this needs to be documented. Also some of the commits can be squashed (and log messages edited) and the whole thing rebased against the current master. |
|
I think PBKDF2 should be easier to handle: in some ways scrypt is the most difficult case. |
|
Hi @snhenson, that's great news! I've already rebased to master, will write some documentation as well and then squash the whole scrypt odysee in one commit, the PBKDF2 as another. The thing I'm not feeling entirely comfortable with right now is the macro setters, which don't have any tests. I'd like to write a small example program that at least tests one vector for each manually. This would ensure that stupid mistakes (copy/paste kind of stuff or some erroneous typo in one of the header files) gets caught right away. I'm writing this code anyways for the "EXAMPLE" section of the manpage, so I figure we could as well include it as a test if that's okay? Thanks again so much for your support! |
There was a problem hiding this comment.
Suggest we have a common name for this without reference to the algorithm. For example EVP_PKEY_CTX_set1_pbe_pass() the expectation here is that all PBE KDFs will support it.
There was a problem hiding this comment.
Fixed in be01d24384. In your comment you wrote about pbe_pass(), but the highlighted code shows scrypt_salt(). Do you suggest that I rename the _salt() functions as well? For now, the patch only introduces pbe_pass().
There was a problem hiding this comment.
No I think the salt can stay as it is. The salt (or at least how it is encoded) can vary from one PBE algorithm to another.
There was a problem hiding this comment.
I don't think it's a good idea to use the above by default. It requires 1GB+ of memory and on some systems that could grind them to a halt or cause "make test" to fail with an out of memory error. It did that on my VM when I was first testing scrypt.
There was a problem hiding this comment.
Fixed in ee41de12af.
|
Can you exclude the PBKDF2 KDF from this PR? That can be a separate PR once this is merged. |
7df6382 to
c883d25
Compare
|
Rebased to master and squashed everything into three commits (the original contribution, the documentation and the new test file). Removed PBKDF2 entirely from this PR and extracted it into #4087. |
ce75a4e to
2f49822
Compare
There was a problem hiding this comment.
Coding style says blank line after declarations.
There was a problem hiding this comment.
I'd suggest the documentation follows the style of other algorithms like RSA-PSS: that is located in man7 and named after the algorithm itself. There are some existing KDFs (like the TLS1 PRF) that don't yet follow this but they will be updated at some point.
|
Hi @snhenson, thanks for your review. I've addressed all of your comments in c0deff0. |
There was a problem hiding this comment.
Is this left over from a previous version? On my system after making the changes to objects.txt and doing make update I get no changes in obj_mac.num
There was a problem hiding this comment.
Well spotted. I've reverted
crypto/asn1/charmap.h \
crypto/conf/conf_def.h \
crypto/objects/obj_dat.h \
crypto/objects/obj_mac.num \
crypto/objects/obj_xref.h \
crypto/objects/obj_xref.txt \
include/openssl/obj_mac.h
and ran make update. Can confirm that this is a leftover from the previous runs that became obsolete. b7c9b69 fixes this.
|
Approved subject to squashing the last two fixes. Many thanks for your contribution! |
Add an interface that allows accessing the scrypt KDF as a PKEY_METHOD. This fixes openssl#4021 (at least for the scrypt portion of the issue).
Added the pkey_meth_kdf_test tests which test the PKEY_METHOD macros (at the moment, of HKDF and scrypt).
Added manpage for the new scrypt EVP_PKEY_METHOD KDF interface.
|
Hi @snhenson, that's awesome news! I've squashed/fixuped the last hiccups and rebased to master. Thanks again for your patience. Cheers, Johannes |
|
Pushed now, thanks everyone. |
Add an interface that allows accessing the scrypt KDF as a PKEY_METHOD. This fixes #4021 (at least for the scrypt portion of the issue). Reviewed-by: Paul Dale <[email protected]> Reviewed-by: Stephen Henson <[email protected]> (Merged from #4026)
Added the pkey_meth_kdf_test tests which test the PKEY_METHOD macros (at the moment, of HKDF and scrypt). Reviewed-by: Paul Dale <[email protected]> Reviewed-by: Stephen Henson <[email protected]> (Merged from #4026)
Added manpage for the new scrypt EVP_PKEY_METHOD KDF interface. Reviewed-by: Paul Dale <[email protected]> Reviewed-by: Stephen Henson <[email protected]> (Merged from #4026)
| } | ||
|
|
||
| int EVP_PKEY_CTX_ctrl_uint64(EVP_PKEY_CTX *ctx, int keytype, int optype, | ||
| int cmd, uint64_t value) |
There was a problem hiding this comment.
Formatting nit. There is corresponding misalignment in include/openssl/evp.h. It wouldn't be inappropriate to fix it in new request, @johndoe31415.
There was a problem hiding this comment.
Ah, dang! As requested, new PR: #4166 -- thanks for the review!
This adds the scrypt KDF as a EVP_PKEY_METHOD. It is onging work in progress; converted to a PR as of the request by @snhenson.
Checklist