vincenthz / hs-cryptohash

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

Incompatibility between crypto-api hash and crytphash hash #6

Closed istathar closed 12 years ago

istathar commented 12 years ago

Crypto.Classes's hash function takes a lazy bytestring

hash :: Hash ctx d => L.ByteString -> d

whereas cryptohash's hash functions (specifically SHA1's) take a strict bytestring

hash :: S.ByteString -> S.ByteString

You suggest in the package documentation that cryptohash is suitable for use with crypto-api, but this would seem to be an incompatibility; while I'm aware that you recommend importing SHA1 qualified, this divergence has made things difficult for me as I've been exploring the APIs.

AfC

vincenthz commented 12 years ago

why would you need to bring both functions in your namespace ?

istathar commented 12 years ago

{shrug} after you know everything and have several years of Haskell under your belt, then maybe you know perfectly exactly what to use and what not to. But in the mean time, when you're exploring and trying to learn and trying to figure out what the use and significance of crypto-api is, and (having decided it's a good idea) whether or not the instances supplied by $whatever library are useful, one tends to try and test things, at which point GHCi barfs, because they aren't compatible.

You obviously have a reason why you made them use different inputs, but at the very least you might consider adding documentation to the effect of "note that this hash function is NOT the same as the Crypto.Classes hash function. You cannot use both in the same code. In order to use the crypto-api interface, you must instead do ___."

Something like that would be very helpful to people who aren't already exceedingly proficient in the use of your library.

AfC

vincenthz commented 12 years ago

(i hope i didn't come as rude or anything, this was a genuine question from me.)

Now, it's hard to fix the problem you are mentioning for a compatibility point of view. the hash and hashlazy function have been exported like this since the beginning of cryptohash and changing it might bring lots of misery to existing users.

Crypto-api came later and added its own hash and hash' functions, and as crypto-api have extra type-ness in its interface, it will always have a difference interface, unless i go down the same route of added types.

I think for now the only reasonable course of action is documenting it.

to use crypto-api with hashes, there's example in the crypto-api source, and IIRC the following will give you a function to make SHA1 hash:

import Crypto.Classes
import Crypto.Hash.SHA1 (SHA1)
hashSHA1 b = hash b :: SHA1