-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Add SHA2 512 truncated hashes #7680
base: master
Are you sure you want to change the base?
Conversation
CT Test Results 2 files 14 suites 7m 18s ⏱️ Results for commit d595652. ♻️ 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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new atoms sha512_224
and sha512_256
should be added to the appropriate type(s) in crypto.erl
. I don't know if that means only the type hash_algoritm()
or in sha2()
which is referred in more places.
SHA2 512/224 and SHA2 512/256 are truncated versions of the SHA2 512 hash function. They are different to truncating the output of the SHA2 512 because they use different initialisation of the hash state.
I've added it to the hash algorithms as the sha2 type is used in more places than the new hashes are supported. |
d595652
to
ea617b3
Compare
Should it be supported in the other places as well? |
Well, clearly, ideally yes :-) I did try it out with hmac using:
And libsodium gives the sequence:
These are clearly not the same. This is the libsodium code I used: #include <sodium.h>
#include <array>
#include <iostream>
int main() {
std::array<unsigned char, crypto_auth_hmacsha512256_BYTES> output{};
std::array<unsigned char, crypto_auth_hmacsha512256_KEYBYTES> key{};
key[0] = 'a';
key[1] = 'b';
key[2] = 'c';
std::array<unsigned char, 3> msg{'d', 'e', 'f'};
std::cout << "key length " << key.size() << '\n';
std::cout << crypto_auth_hmacsha512256(output.data(), msg.data(), msg.size(), key.data()) << '\n';
for (auto const c : output) {
std::cout << int(c) << ' ';
}
std::cout << '\n';
return 0;
} There is potentially a difference in bit packing for the key argument here, but the following erlang code gives identical output: I would assume that the libsodium results are correct, so I doubt we should trust the HMAC result here. |
It would be great to see these added because of the length-extension resistance that these provide. |
SHA2 512/224 and SHA2 512/256 are truncated versions of the SHA2 512 hash function. They are different to truncating the output of the SHA2 512 because they use different initialisation of the hash state.
This will close #5087