New Erlang SHA-2 Implementation
February 20th, 2011 | Published in code, erlang, performance | Bookmark on Pinboard.in
A few years ago I wrote a pure Erlang version of the SHA-2 hash algorithms (SHA-224, SHA-256, SHA-384, SHA-512). They were kinda slow but they worked fine, and a number of people used them.
I’ve now rewritten the functions in a new Erlang library application named erlsha2
, available at github. The erlsha2
implementation uses Erlang NIFs, making it significantly faster than the original. The original Erlang implementations are still there too, but they’re automatically overridden by the NIF library when it loads.
Compared to the original module, the exported functions in this module have been renamed; they used to have names like hexdigest224
but they now have shorter names like sha224
to more closely match the Erlang crypto
module. I also implemented the init
/update
/final
function groups for each hash algorithm to allow data to be incrementally hashed, also to match the crypto
module.