vincenthz / hs-crypto-cipher

DEPRECATED by cryptonite; A collection of cryptographic block and stream ciphers in haskell
22 stars 14 forks source link

Blowfish from s2k #23

Closed singpolyma closed 11 years ago

singpolyma commented 11 years ago

I'm implementing string2key stuff for OpenPGP, and Blowfish reports a keysize of 56, but wants 72 bytes for the Serialize.decode instance. If I use buildKey it "works", but the key I get seems to be the wrong one (stuff encrypted with GPG does not decrypt).

The AES instances work fine either way.

singpolyma commented 11 years ago

Hmm, ok, I solved it like this:

newtype Blowfish128 = Blowfish128 Blowfish

instance Serialize.Serialize Blowfish128 where
   put (Blowfish128 b) = Serialize.put b
   get = fmap Blowfish128 Serialize.get

instance BlockCipher Blowfish128 where
   blockSize = retag (blockSize :: Tagged Blowfish BitLength)
   encryptBlock (Blowfish128 k) = encryptBlock k
   decryptBlock (Blowfish128 k) = decryptBlock k
   buildKey = fmap Blowfish128 . buildKey
   keyLength = Tagged 128
vincenthz commented 11 years ago

Why is that not in a form of a bugfix for the original instance instead of redefining on your side the instance ?

singpolyma commented 11 years ago

@vincenthz because your instance isn't really broken, it's just that Blowfish works for multiple keysizes and your type is for a different size than I needed.