vincenthz / hs-cryptohash

efficient and practical cryptohashing in haskell. DEPRECATED in favor of cryptonite
Other
30 stars 24 forks source link

Blake2 #23

Closed tsuraan closed 1 year ago

tsuraan commented 10 years ago

I've started sketching out a Blake2 binding that will be similar to the current cryptohash apis. The code is at http://github.com/tsuraan/hs-blake2. Currently it only has the simple "hash :: ByteString -> ByteString" style functions, but I'll be adding the context/update style ones soon.

I'm wondering if this is something that could be added to cryptohash once it's complete. It currently requires the blake2 "libb2" library; cryptohash is entirely self-contained right now, so I'm not sure how a dependency on an external library would work.

I think this would be a worthwhile addition; blake2 is supposed to be as good as any hashing function out there, and my benchmarks are showing it to be faster than Tiger, Skein, SHA2, or even MD5 on moderately large chunks of data.

This is also my first FFI binding in Haskell, so if there's anything that I did terribly wrong (probably in src/Crytpo/Hash/Tsuraan/Blake2/Internal.hs), I'd love to hear about it.

vincenthz commented 10 years ago

Cool stuff. blake2 is an amazing hash, sadly an outside dependency is a non-starter to go in cryptohash. Provided libb2 get inlined or reimplemented with the correct license, it would be great.

tsuraan commented 10 years ago

The code in libb2 is "public domain" (CC0 license). I guess it would be legal to pretty much drop it straight into cryptohash's "cbits" directory, but that would be another 19,800 lines of C code. Its init/update/finalize API is also entirely mutation-based, so maybe that API just doesn't fit into what cryptohash is trying to do. I guess I'll just leave my hs-blake2 up until somebody gets motivated to write a properly pure version of blake2, maybe just using important bits of the libb2 source for inspiration/acceleration.

vincenthz commented 9 years ago

cryptohash's C implementations are all mutable, the foreign bindings on top just do for every objects that can be mutated:

1) allocate memory of same size 2) copy the thing that is going to be mutated byte by byte 3) pass the new copied thing to the foreign function