potatosalad / erlang-libdecaf

ed448goldilocks (libdecaf) NIF with timeslice reductions for Erlang and Elixir.
MIT License
29 stars 16 forks source link

Support Pre-NIST Keccak256 Digest #12

Closed heri16 closed 2 years ago

heri16 commented 2 years ago

Is there support for LegacyKeccak256 as implemented by Ethereum?

Golang stdlib has it: https://pkg.go.dev/golang.org/x/crypto/sha3#NewLegacyKeccak256

If no, what would be a good PR to make it work?

https://github.com/potatosalad/erlang-libdecaf/blob/ef040752a02e32d90aa0639a5e9a02406b8d634c/c_deps/ed448goldilocks/src/include/keccak_internal.h#L27-L29

https://github.com/potatosalad/erlang-libdecaf/blob/ef040752a02e32d90aa0639a5e9a02406b8d634c/c_deps/ed448goldilocks/src/shake.c#L213-L215

Defined here: https://github.com/potatosalad/erlang-libdecaf/blob/ef040752a02e32d90aa0639a5e9a02406b8d634c/c_deps/ed448goldilocks/src/public_include/decaf/shake.h#L272

https://github.com/potatosalad/erlang-libdecaf/blob/ef040752a02e32d90aa0639a5e9a02406b8d634c/c_deps/ed448goldilocks/src/shake.c#L236

heri16 commented 2 years ago

The Minor Difference: https://ethereum.stackexchange.com/a/554 (Slight difference in the padding)

SHA3 visualized: https://codesigningstore.com/hash-algorithm-comparison

We can see it's just changing the pad from 0x06 to 0x01:

rate_pad is the same at 0x80.

heri16 commented 2 years ago

Available in OpenSSL

https://github.com/openssl/openssl/issues/13033#issuecomment-925456698

https://github.com/openssl/openssl/commit/524f12611040de64cda13dd148ad1b8ca559c730

List of supported algo: https://www.openssl.org/docs/manmaster/man7/EVP_MD-KECCAK.html

ukazap commented 2 years ago

Kindly review #15 which addresses this issue.

potatosalad commented 2 years ago

@heri16 This is supported now in libdecaf 2.1.0, see this section of the README for example usage.