More SHA in Erlang

January 3rd, 2009  |  Published in code, erlang  |  5 Comments  |  Bookmark on Pinboard.in

Yesterday I posted a SHA-256 Erlang module, but I figured since other SHA algorithms are similar, I might as well finish the job. I grabbed the Secure Hash Standard and went to work.

The resulting new module is named sha2 and it implements SHA-224, SHA-256, SHA-384, and SHA-512.

I hope you find it useful.

Responses

  1. MononcQc says:

    January 5th, 2009 at 9:42 am (#)

    Thanks a lot! I was definitely looking for a better sha module for erlang just this week and it seems this comes in right in time.

    This will prove itself to be really useful, and if good enough, I hope it can eventually make it into the standard erlang library.

  2. Steve says:

    January 7th, 2009 at 7:08 am (#)

    Thanks for keeping Erlang “on the curve” :)

  3. Nicolas says:

    January 8th, 2009 at 7:18 am (#)

    I wrote a SHA-1 library for Erlang in 2007, just to play with pattern matching:

    http://journal.batard.info/post/2007/07/19/erlang-sha-1-library

    I am aware of crypto:sha/1, this was not meant to be used, but rather just a demo.

    I’m writing as the performance of my module was astoundingly bad; is yours better? Have you tried hashing even just a 50MB file?

    Looking forward to hearing from you,

    Nicolas.

  4. steve says:

    January 8th, 2009 at 10:51 am (#)

    @Nicolas: no, I don’t think performance would be all that great for a 50MB file. One of the test vectors is 393216 bytes, for example, and it takes 4.33s to run through SHA-256. Given that the performance appears to be fairly linear with respect to the input message size, I think it would take over 10 minutes to deal with a 50MB file.

    Still, the performance is better than nothing, which is the support the crypto module currently gives us for these functions.

  5. Matt Williamson says:

    January 22nd, 2009 at 8:37 am (#)

    Thanks man, I was about to write a C driver because I was getting desperate.