Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[crypto/4871] Add support for SHAKE128 and SHAKE256. #6203

Merged

Conversation

marcellanz
Copy link
Contributor

This should fix #4871.
Passes tests with /lib/crypto for openssl@3/3.0.5 and openssl@1.1/1.1.1q.

@github-actions
Copy link
Contributor

github-actions bot commented Aug 8, 2022

CT Test Results

    2 files    14 suites   5m 18s ⏱️
183 tests 169 ✔️   14 💤 0
462 runs  329 ✔️ 133 💤 0

Results for commit fb86085.

♻️ This comment has been updated with latest results.

To speed up review, make sure that you have read Contributing to Erlang/OTP and that all checks pass.

See the TESTING and DEVELOPMENT HowTo guides for details about how to run test locally.

Artifacts

// Erlang/OTP Github Action Bot

@marcellanz marcellanz force-pushed the crypto/4871_support_for_SHAKE128_and_SHAKE256 branch from 4f3bad6 to 9dbf022 Compare August 8, 2022 19:10
@marcellanz marcellanz force-pushed the crypto/4871_support_for_SHAKE128_and_SHAKE256 branch from 9dbf022 to 710ef35 Compare August 8, 2022 21:22
@marcellanz marcellanz marked this pull request as ready for review August 9, 2022 07:34
@HansN HansN added team:PS Assigned to OTP team PS feature testing currently being tested, tag is used by OTP internal CI labels Aug 9, 2022
@HansN HansN self-assigned this Aug 9, 2022
@HansN HansN removed the testing currently being tested, tag is used by OTP internal CI label Aug 9, 2022
lib/crypto/c_src/digest.c Outdated Show resolved Hide resolved
lib/crypto/c_src/digest.c Outdated Show resolved Hide resolved
lib/crypto/c_src/digest.c Outdated Show resolved Hide resolved
@HansN
Copy link
Contributor

HansN commented Aug 9, 2022

Great work! And complete with tests and documentation - very good!

But, for certain reasons it must be compileable also with OpenSSL versions less than 1.1.1. Less that 0.9.8c is not needed. It is not necessary to return any other result than that is not supported when running given that the algorithms are not present in crypto:supported.

If the PR is compiled with 1.1.0 or less the function hash_final_xof_nif is not declared. We usually solve this by another declaration in the #else part which just only returns an EXCP_NOTSUP

@marcellanz
Copy link
Contributor Author

marcellanz commented Aug 9, 2022

Thanks :)
I missed that case and will adapt to have returned EXCP_NOTSUP for OPENSSL_VERSION_NUMBER < 1.0.
With returning EXCP_NOTSUP, consequently, I would not remove shake128 and shake256 from crypto:supports(hashs) at all when compiled with OpenSSL < 1.0, right?

@HansN
Copy link
Contributor

HansN commented Aug 9, 2022

If an algorithm is present in crypto:supports, it should return a value and not NOTSUP. That exception means that the algorithm is supported by Erlang/OTP, but not by the current cryptolib. The algorithm is therefore not in crypto:supports for the current cryptolib.

So yes, keep the #ifdef HAVE_SHAKExxx in algorithms.c.

You could then #undef HAVE_SHAKExxx in openssl_config.h for versions you do not want to support with old function calls.

@HansN HansN added waiting waiting for changes/input from author in progress labels Aug 10, 2022
@marcellanz
Copy link
Contributor Author

marcellanz commented Aug 11, 2022

Got it – I think. So hash_final_xof_nif is defined unconditionally in hash.h as OTP could support XOF functions. HAVE_SHAKExxx flags are defined as soon as openssl 1.1.1 or above is choosen for the build and their implementation in hash.c depends on the two HAVE_SHAKExxx flags, with one falling back implementation returning EXCP_NOTSUP if called but not supported.

Implemented with fb86085

@HansN HansN added testing currently being tested, tag is used by OTP internal CI and removed waiting waiting for changes/input from author labels Aug 12, 2022
@HansN HansN merged commit f4d5d05 into erlang:master Aug 17, 2022
@HansN
Copy link
Contributor

HansN commented Aug 17, 2022

Thanks for the PR!

@HansN HansN removed testing currently being tested, tag is used by OTP internal CI in progress labels Aug 17, 2022
@marcellanz
Copy link
Contributor Author

Thanks for the PR!

You're welcome. Thanks for guiding me through the details.

@lorenzosinisi
Copy link

Hi and great work on this particular algo! It will be very useful :) May I ask what is needed to include it in the next release and why wasn't it added in the latest one already? Is there any way to help?

@marcellanz
Copy link
Contributor Author

Thanks @lorenzosinisi. As it introduces addition to library API I assume it would be released with the next major version of OTP?
I think it would be listed here https://github.com/erlang/otp/milestone/162?closed=1 but its not so far.

@lorenzosinisi
Copy link

Thanks @lorenzosinisi. As it introduces addition to library API I assume it would be released with the next major version of OTP?

I think it would be listed here https://github.com/erlang/otp/milestone/162?closed=1 but its not so far.

Thank you! I'll take a closer look there 👍👍 yes I can imagine how the APIs would change given that shake256 would take also additional args

@IngelaAndin IngelaAndin added this to the OTP-26.0 milestone Oct 13, 2022
@IngelaAndin
Copy link
Contributor

This PR was merged to master and will hence be part of OTP-26. We are still adopting our ways of working with GitHub features so I guess it never got a milestone attached to it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature team:PS Assigned to OTP team PS
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add support for SHAKE128 and SHAKE256
4 participants