August 12, 2016

As ChaCha20 and Poly1305 make their way through the IETF standardization process, I thought it would be a good idea to get some experience implementing (at least one of) these algorithms. I also wanted to play around with implementing some cryptographic algorithms in Haskell. To that end, I implemented ChaCha20 in Haskell. This was fairly easy to do following the RFC [1]. The main entry point is the encryption function chaCha20Encrypt. (In retrospect, this should be renamed to chaCha20Mask or something similar since it’s the same function used for both encryption and decryption.) It has the following type signature:
chaCha20Encrypt :: [Word32] -> Word32 -> [Word32] -> [Word8] -> [Word8]