chacha

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

Weight.hs (1248B)


      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 qualified Crypto.Cipher.ChaCha20 as ChaCha20
     11 import qualified Data.ByteString as BS
     12 import GHC.Generics
     13 import Weigh
     14 
     15 deriving instance Generic ChaCha20.Error
     16 
     17 instance NFData ChaCha20.Error
     18 
     19 -- note that 'weigh' doesn't work properly in a repl
     20 main :: IO ()
     21 main = mainWith $ do
     22   block
     23   cipher
     24 
     25 block :: Weigh ()
     26 block =
     27   let !key = BS.replicate 32 0x88
     28       !non = BS.replicate 12 0x00
     29   in  wgroup "block" $
     30         func "block" (ChaCha20.block key 1) non
     31 
     32 cipher :: Weigh ()
     33 cipher =
     34   let !key = BS.replicate 32 0x88
     35       !non = BS.replicate 12 0x00
     36       !bs0 = BS.replicate 64 0
     37       !bs1 = BS.replicate 256 0
     38       !bs2 = BS.replicate 1024 0
     39       !bs3 = BS.replicate 4096 0
     40   in  wgroup "cipher" $ do
     41         func "cipher (64B   input)"
     42           (ChaCha20.cipher key 1 non) bs0
     43         func "cipher (256B  input)"
     44           (ChaCha20.cipher key 1 non) bs1
     45         func "cipher (1024B input)"
     46           (ChaCha20.cipher key 1 non) bs2
     47         func "cipher (4096B input)"
     48           (ChaCha20.cipher key 1 non) bs3