Implementing ex_sha3 was an experiment of a pure Elixir version of the fips-202 sha3 and original keccak algorithms. ex_sha3 works platform independent without any nif wrapper, requires no c compilation. Also, this is the first library I’m aware of that exposes both algorithms, the original keccak hash as used in Ethereum, and the sha3 hash that got standardized. They are slightly different in padding and so return different hash results. Most implementations only do one or the other.
Size wise I’m pretty happy about this port. The implementation is in a single .ex file of 232 lines of code. Derived from the tiny-keccak implementation used by nim, exposing sha3, keccak and shake independently.
Unfortunately, the performance is abysmal compared to existing nif based implementations:
> mix run benchmark.exs Operating System: Linux *snip* Comparison: short nif_sha3_256 198.18 K long nif_sha3_256 2.13 K - 93.24x slower +465.43 μs short ex_sha3_256 0.102 K - 1946.84x slower +9818.31 μs long ex_sha3_256 0.00069 K - 285946.87x slower +1442824.24 μs
Haven’t yet looked into optimizing the performance as I was just in need of a short correct implementation, but would be happy to entertain anything to speed it up. The 2000x performance difference is a bit devastating I have to say.