Closed tsuraan closed 1 year 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.
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.
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
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.