chacha

The ChaCha20 stream cipher (docs.ppad.tech/chacha).
git clone git://git.ppad.tech/chacha.git
Log | Files | Refs | README | LICENSE

Main.hs (1153B)


      1 {-# OPTIONS_GHC -fno-warn-orphans #-}
      2 {-# LANGUAGE BangPatterns #-}
      3 {-# LANGUAGE DeriveGeneric #-}
      4 {-# LANGUAGE OverloadedStrings #-}
      5 {-# LANGUAGE StandaloneDeriving #-}
      6 
      7 module Main where
      8 
      9 import Control.DeepSeq
     10 import Criterion.Main
     11 import qualified Crypto.Cipher.ChaCha20 as ChaCha20
     12 import qualified Data.ByteString as BS
     13 import qualified Data.ByteString.Base16 as B16
     14 import Data.Maybe (fromJust)
     15 import GHC.Generics
     16 
     17 deriving instance Generic ChaCha20.Error
     18 
     19 instance NFData ChaCha20.Error
     20 
     21 main :: IO ()
     22 main = defaultMain [
     23     suite
     24   ]
     25 
     26 plain :: BS.ByteString
     27 plain = fromJust . B16.decode $
     28   "4c616469657320616e642047656e746c656d656e206f662074686520636c617373206f66202739393a204966204920636f756c64206f6666657220796f75206f6e6c79206f6e652074697020666f7220746865206675747572652c2073756e73637265656e20776f756c642062652069742e"
     29 
     30 key :: BS.ByteString
     31 key = fromJust . B16.decode $
     32   "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f"
     33 
     34 non :: BS.ByteString
     35 non = fromJust . B16.decode $
     36   "000000090000004a00000000"
     37 
     38 suite :: Benchmark
     39 suite =
     40   bgroup "ppad-chacha" [
     41     bench "cipher" $ nf (ChaCha20.cipher key 1 non) plain
     42   ]
     43