Open faried opened 3 years ago
This is currently not prioritized by Erlang/OTP, but Pull Requests are welcome.
I'm wondering about taking a stab at adding the two truncated hash functions to the crypto module. I guess my strategy will be to go through occurrences of sha512
in the crypto module and add sha512_224
and sha512_256
where appropriate.
The open_ssl documentation https://www.openssl.org/docs/manmaster/man3/EVP_sha512_224.html lumps the truncated functions in with the ones that are already being used, so it should be a very simple change (I hope).
Is there anything I should keep in mind? So far I've cloned and built this project and I can run the tests using make ARGS="-suite crypto_SUITE"
and I've read the contributing guide.
@KayEss
If this is just about adding a new digest version then it should be quite straight forward. You will end up down in lib/crypto/c_src/digest.c
and the array digest_types
containing all the different supported digest types. Note that OpenSSL >= 3.0 uses a slightly different initialization with EVP_MD_fetch.
Then also add tests and documentation.
@sverker I have a commit that does the hash part of this: https://github.com/BiggestLab/otp/commit/d595652a47c763b0b491550ee94d77083e2a6ad7
Should I do a PR with this, or is there something obvious I ought to fix first?
@KayEss Looks good. Make it a PR.
Is your feature request related to a problem? Please describe.
I was trying to port some code over from Javascript when I found out that
crypto
did not implement SHA-512. Truncated SHA-512 is SHA-512 with a different initial value, and with the output truncated at the right place (32 bytes for SHA-512/256, for example). Thecrypto
module does not appear to export anything that will let me fiddle with this initial value.OpenSSL has supported these functions 1.1.1, released almost three years ago.
Describe the solution you'd like
Add support for SHA512/256 to
crypto
.Describe alternatives you've considered
I forked a pure Erlang implementation of SHA2 from 2015, disabled the code that loaded the NIF, and added my functions. It's not ideal, but it'll work for my current project.