Skip to content

Add EVP/KDF API - #6674

Closed
davidmakepeace wants to merge 1 commit into
openssl:masterfrom
davidmakepeace:add-evp-kdf-api
Closed

davidmakepeace wants to merge 1 commit into
openssl:masterfrom
davidmakepeace:add-evp-kdf-api

Conversation

@davidmakepeace

@davidmakepeace davidmakepeace commented Jul 9, 2018 •

Copy link
Copy Markdown
Contributor

This PR adds a new EVP/KDF API that collects all KDFs and PRFs under the one API.

#include <openssl/kdf.h>

Currently some KDFs are available directly (PBKDF2 and scrypt) while others are available through the PKEY API (scrypt, TLS1 PRF and HKDF) even though the PKEY API was originally intended for Public Key algorithms. Note that the low level KDF functions (PKCS5_PBKDF2_HMAC and EVP_PBE_scrypt) are defined in openssl/evp.h even though EVP is the high level interface.

The new API is modeled after the current KDF support under the PKEY API in order to minimize the work required to update applications to use the new API. Support is included for PBKDF2, scrypt, TLS1 PRF and HKDF. PBKDF1 and PKCS12 KDF are not implemented.

The low level KDF functions and PKEY KDF support have been changed to wrap the new API. Other parts of OpenSSL have not yet been updated to call the new API.

Documentation to follow.

  • documentation is added or updated
  • tests are added or updated

@davidmakepeace davidmakepeace changed the title WIP Add EVP/KDF API WIP: Add EVP/KDF API Jul 9, 2018
@davidmakepeace
davidmakepeace force-pushed the add-evp-kdf-api branch 2 times, most recently from a4b5940 to 1615c66 Compare July 10, 2018 01:40
Comment thread include/openssl/evp_kdf.h Resolved
@davidmakepeace
davidmakepeace force-pushed the add-evp-kdf-api branch 4 times, most recently from 868ad00 to 2a1efeb Compare July 13, 2018 00:07
@mattcaswell mattcaswell added this to the Post 1.1.1 milestone Jul 13, 2018
@paulidale

Copy link
Copy Markdown
Contributor

We've got a single step KDF (SP 800-56) implemented and passing test vectors but it will need some cleanup to fit into this framework. The intention is to submit this it after this PR has been accepted or at least after the final form of these changes are determined.

@paulidale

Copy link
Copy Markdown
Contributor

Thought from today: this interface should deal with NULL result buffers better. Some of the algorithms use this to request the size of the result. The rest are variably sized and don't support this functionality. Uniformity would be better here.

My suggestion is that a new API is introduced that requests the size of the result (which matches digests) and that this returns 0 or -1 for variable size outcomes (I favour zero). Then, the NULL checking can be removed from the new APIs and handed off to the legacy wrappers.

Thoughts?

@t-j-h

t-j-h commented Aug 27, 2018

Copy link
Copy Markdown
Member

Do we really need the uint64 in the scrypt interface?

@levitte

levitte commented Aug 27, 2018

Copy link
Copy Markdown
Member

The scrypt page on tarsnap seems to indicate that at least N can be a large enough integer to warrant 64 bits...

@t-j-h

t-j-h commented Aug 27, 2018

Copy link
Copy Markdown
Member

Sure it can technically go that high - but pragmatically would anyone ever exceed 2^32 - that I seriously doubt is realistic in any context

@levitte

levitte commented Sep 20, 2018

Copy link
Copy Markdown
Member

@paulidale, it would be great if you could rebase and fix the conflicts.
(re crypto/err/openssl.txt, crypto/evp/evp_err.c, include/openssl/evperr.h and util/libcrypto.num, I would just toss them and do make update again)

Comment thread crypto/evp/evp_kdf.c Resolved
Comment thread include/openssl/evp_kdf.h Resolved
@paulidale

Copy link
Copy Markdown
Contributor

I'll ask @davidmakepeace to update tomorrow.

@levitte

levitte commented Sep 20, 2018

Copy link
Copy Markdown
Member

Oh oops, I mixed you guys up... sorry :-/

@paulidale

Copy link
Copy Markdown
Contributor

I'm fatter and uglier. I figured it would have been hard to mix us up :)

Comment thread crypto/evp/pkey_kdf.c Resolved
@simo5

simo5 commented Sep 20, 2018

Copy link
Copy Markdown

@davidmakepeace any chance you will rebase this PR soonish, it's been indicated as a base to be used to implement SSHKDF and it'd be nice to start on a fresh rebase that does not conflict with master

@davidmakepeace
davidmakepeace force-pushed the add-evp-kdf-api branch 2 times, most recently from cd71808 to bfa7eaa Compare September 21, 2018 04:12
Comment thread include/openssl/evp_kdf.h Resolved
@levitte

levitte commented Feb 13, 2019

Copy link
Copy Markdown
Member

This was great work, @davidmakepeace

levitte pushed a commit that referenced this pull request Feb 13, 2019
Changed PKEY/KDF API to call the new API.
Added wrappers for PKCS5_PBKDF2_HMAC() and EVP_PBE_scrypt() to call the new EVP KDF APIs.
Documentation updated.

Reviewed-by: Paul Dale <[email protected]>
Reviewed-by: Richard Levitte <[email protected]>
(Merged from #6674)
@paulidale

Copy link
Copy Markdown
Contributor

219 days in coming. A great effort and a very worthwhile contribution. Thanks to all who assisted and contributed.

The various follow on KDFs can now be tapped onto this work. @slontis has single step KDF, @romen has one too I believe. No doubt there are others. Let the floodgates open to the pressure of the 617th.

@levitte

levitte commented Feb 13, 2019

Copy link
Copy Markdown
Member

This search shows all the KDF related PRs. I'll have a quick run through, as I'm sure some can just be closed by now

@davidmakepeace
davidmakepeace deleted the add-evp-kdf-api branch February 18, 2019 22:21
@tomato42

Copy link
Copy Markdown
Contributor

I must be missing something, but I don't see a way to run PBKDF2 using command line tools (see #4021), just the TLS KDF, HKDF and scrypt...

@mattcaswell

Copy link
Copy Markdown
Member

I must be missing something, but I don't see a way to run PBKDF2 using command line tools (see #4021), just the TLS KDF, HKDF and scrypt...

It seems that PBKDF2 does not appear in crypto/evp/pkey_kdf.c like the others do. @davidmakepeace is this an accidental omission or was there a reason for that?

@t8m

t8m commented Apr 15, 2019 •

Copy link
Copy Markdown
Member

I suppose only KDF algorithms that were previously implemented in the PKEY interface were ported via wrapping the KDF API. Anything newly implemented (PBKDF2, SSHKDF, ...) does not have this wrapping as the PKEY interface should be seen as legacy for kdfs?

@mattcaswell

Copy link
Copy Markdown
Member

I suppose only KDF algorithms that were previously implemented in the PKEY interface were ported via wrapping the KDF API. Anything newly implemented (PBKDF2, SSHKDF, ...) does not have this wrapping as the PKEY interface should be seen as legacy for kdfs?

Yes, perhaps that is the reason. That has the unfortunate side-effect that they're not available to pkeyutl. That might suggest that pkeyutl should be ported to use the new API - which is itself problematic since the whole structure of pkeyutl is focused around handling EVP_PKEY objects (hence the name of the application). Or alternatively we decide to retrofit the PKEY interface for these "new" KDFs.

@levitte

levitte commented Apr 15, 2019

Copy link
Copy Markdown
Member

Didn't someone submit a PR to create a `openssl kdf' command? I think I remember seeing that, but can't find it right now

@davidmakepeace

Copy link
Copy Markdown
Contributor Author

Yes, the PBKDF2 algorithm was not previously supported by the PKEY interface, which is now considered legacy with respect to KDF algorithms.
The intention was to eventually change everything that was using PKEY for KDFs to using the KDF API but there is no hurry due to the wrappers.

We could change the pkeyutl app to use the KDF API for KDFs. Alternatively a new kdf app could be added specifically for KDFs.

@mattcaswell

Copy link
Copy Markdown
Member

A KDF app seems like a good option to me.

@slontis

slontis commented Apr 16, 2019

Copy link
Copy Markdown
Member

I had added a mac app, but not a kdf one.
I will submit a PR for this very soon.
Not sure that it is a good idea to use a utility like this to do anything other than do testing.
Deriving a key via a command-line tool seems a bit shady to me..

@tomato42

Copy link
Copy Markdown
Contributor

there are two purposes, primary is to verify if a different implementation implements the KDF correctly[1], and secondary is for tools like https://testssl.sh/

so yes, diagnostics/debugging

1 - including a situation where the KDF is implemented in an engine or pkcs11 module

@slontis

slontis commented Apr 16, 2019

Copy link
Copy Markdown
Member

Added KDF app PR: #8762

@slontis

slontis commented Apr 22, 2019

Copy link
Copy Markdown
Member

Added EVP_KDF PR: #8808

hustliyilin pushed a commit to hustliyilin/BabaSSL that referenced this pull request Oct 22, 2021
…d wrappers for PKCS5_PBKDF2_HMAC() and EVP_PBE_scrypt() to call the new EVP KDF APIs. Documentation updated.

Reviewed-by: Paul Dale <[email protected]>
Reviewed-by: Richard Levitte <[email protected]>
(Merged from openssl/openssl#6674)

(cherry picked from commit 5a285addbf39f91d567f95f04b2b41764127950d)
[Yilin: rebase babassl master]

Signed-off-by: YiLin.Li <[email protected]>
hustliyilin pushed a commit to hustliyilin/BabaSSL that referenced this pull request Oct 25, 2021
…d wrappers for PKCS5_PBKDF2_HMAC() and EVP_PBE_scrypt() to call the new EVP KDF APIs. Documentation updated.

Reviewed-by: Paul Dale <[email protected]>
Reviewed-by: Richard Levitte <[email protected]>
(Merged from openssl/openssl#6674)

(cherry picked from commit 5a285addbf39f91d567f95f04b2b41764127950d)
[Yilin: rebase babassl master]

Signed-off-by: YiLin.Li <[email protected]>
hustliyilin pushed a commit to hustliyilin/BabaSSL that referenced this pull request Oct 25, 2021
…d wrappers for PKCS5_PBKDF2_HMAC() and EVP_PBE_scrypt() to call the new EVP KDF APIs. Documentation updated.

Reviewed-by: Paul Dale <[email protected]>
Reviewed-by: Richard Levitte <[email protected]>
(Merged from openssl/openssl#6674)

(cherry picked from commit 5a285addbf39f91d567f95f04b2b41764127950d)
[Yilin: rebase babassl master]

Signed-off-by: YiLin.Li <[email protected]>
hustliyilin pushed a commit to hustliyilin/BabaSSL that referenced this pull request Oct 25, 2021
…d wrappers for PKCS5_PBKDF2_HMAC() and EVP_PBE_scrypt() to call the new EVP KDF APIs. Documentation updated.

Reviewed-by: Paul Dale <[email protected]>
Reviewed-by: Richard Levitte <[email protected]>
(Merged from openssl/openssl#6674)

(cherry picked from commit 5a285addbf39f91d567f95f04b2b41764127950d)
[Yilin: rebase babassl master]

Signed-off-by: YiLin.Li <[email protected]>
hustliyilin pushed a commit to hustliyilin/BabaSSL that referenced this pull request Oct 25, 2021
…d wrappers for PKCS5_PBKDF2_HMAC() and EVP_PBE_scrypt() to call the new EVP KDF APIs. Documentation updated.

Reviewed-by: Paul Dale <[email protected]>
Reviewed-by: Richard Levitte <[email protected]>
(Merged from openssl/openssl#6674)

(cherry picked from commit 5a285addbf39f91d567f95f04b2b41764127950d)
[Yilin: rebase babassl master]

Signed-off-by: YiLin.Li <[email protected]>
hustliyilin pushed a commit to hustliyilin/BabaSSL that referenced this pull request Oct 25, 2021
…d wrappers for PKCS5_PBKDF2_HMAC() and EVP_PBE_scrypt() to call the new EVP KDF APIs. Documentation updated.

Reviewed-by: Paul Dale <[email protected]>
Reviewed-by: Richard Levitte <[email protected]>
(Merged from openssl/openssl#6674)

(cherry picked from commit 5a285addbf39f91d567f95f04b2b41764127950d)
[Yilin: rebase babassl master]

Signed-off-by: YiLin.Li <[email protected]>
hustliyilin pushed a commit to hustliyilin/BabaSSL that referenced this pull request Oct 26, 2021
…d wrappers for PKCS5_PBKDF2_HMAC() and EVP_PBE_scrypt() to call the new EVP KDF APIs. Documentation updated.

Reviewed-by: Paul Dale <[email protected]>
Reviewed-by: Richard Levitte <[email protected]>
(Merged from openssl/openssl#6674)

(cherry picked from commit 5a285addbf39f91d567f95f04b2b41764127950d)
[Yilin: rebase babassl master]

Signed-off-by: YiLin.Li <[email protected]>
hustliyilin pushed a commit to hustliyilin/BabaSSL that referenced this pull request Oct 28, 2021
…d wrappers for PKCS5_PBKDF2_HMAC() and EVP_PBE_scrypt() to call the new EVP KDF APIs. Documentation updated.

Reviewed-by: Paul Dale <[email protected]>
Reviewed-by: Richard Levitte <[email protected]>
(Merged from openssl/openssl#6674)

(cherry picked from commit 5a285addbf39f91d567f95f04b2b41764127950d)
[Yilin: rebase babassl master]

Signed-off-by: YiLin.Li <[email protected]>
hustliyilin pushed a commit to hustliyilin/BabaSSL that referenced this pull request Oct 28, 2021
…d wrappers for PKCS5_PBKDF2_HMAC() and EVP_PBE_scrypt() to call the new EVP KDF APIs. Documentation updated.

Reviewed-by: Paul Dale <[email protected]>
Reviewed-by: Richard Levitte <[email protected]>
(Merged from openssl/openssl#6674)

(cherry picked from commit 5a285addbf39f91d567f95f04b2b41764127950d)
[Yilin: rebase babassl master]

Signed-off-by: YiLin.Li <[email protected]>
hustliyilin pushed a commit to hustliyilin/BabaSSL that referenced this pull request Oct 28, 2021
…d wrappers for PKCS5_PBKDF2_HMAC() and EVP_PBE_scrypt() to call the new EVP KDF APIs. Documentation updated.

Reviewed-by: Paul Dale <[email protected]>
Reviewed-by: Richard Levitte <[email protected]>
(Merged from openssl/openssl#6674)

(cherry picked from commit 5a285addbf39f91d567f95f04b2b41764127950d)
[Yilin: rebase babassl master]

Signed-off-by: YiLin.Li <[email protected]>
uudiin pushed a commit to Tongsuo-Project/Tongsuo that referenced this pull request Oct 30, 2021
…d wrappers for PKCS5_PBKDF2_HMAC() and EVP_PBE_scrypt() to call the new EVP KDF APIs. Documentation updated.

Reviewed-by: Paul Dale <[email protected]>
Reviewed-by: Richard Levitte <[email protected]>
(Merged from openssl/openssl#6674)

(cherry picked from commit 5a285addbf39f91d567f95f04b2b41764127950d)
[Yilin: rebase babassl master]

Signed-off-by: YiLin.Li <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approval: done This pull request has the required number of approvals branch: master Applies to master branch

Projects

None yet

Development

Successfully merging this pull request may close these issues.