chacha

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

commit 9bf3be8f1fdf42e5258c17207ff475896274675d
parent f2982de08481e285393cd19a4240a0f5bf42fdfe
Author: Jared Tobin <jared@jtobin.io>
Date:   Sun, 26 Apr 2026 07:02:20 -0230

bench: add weigh suite

Diffstat:
Abench/Weight.hs | 48++++++++++++++++++++++++++++++++++++++++++++++++
Mppad-chacha.cabal | 18++++++++++++++++++
2 files changed, 66 insertions(+), 0 deletions(-)

diff --git a/bench/Weight.hs b/bench/Weight.hs @@ -0,0 +1,48 @@ +{-# OPTIONS_GHC -fno-warn-orphans #-} +{-# LANGUAGE BangPatterns #-} +{-# LANGUAGE DeriveGeneric #-} +{-# LANGUAGE OverloadedStrings #-} +{-# LANGUAGE StandaloneDeriving #-} + +module Main where + +import Control.DeepSeq +import qualified Crypto.Cipher.ChaCha20 as ChaCha20 +import qualified Data.ByteString as BS +import GHC.Generics +import Weigh + +deriving instance Generic ChaCha20.Error + +instance NFData ChaCha20.Error + +-- note that 'weigh' doesn't work properly in a repl +main :: IO () +main = mainWith $ do + block + cipher + +block :: Weigh () +block = + let !key = BS.replicate 32 0x88 + !non = BS.replicate 12 0x00 + in wgroup "block" $ + func "block" (ChaCha20.block key 1) non + +cipher :: Weigh () +cipher = + let !key = BS.replicate 32 0x88 + !non = BS.replicate 12 0x00 + !bs0 = BS.replicate 64 0 + !bs1 = BS.replicate 256 0 + !bs2 = BS.replicate 1024 0 + !bs3 = BS.replicate 4096 0 + in wgroup "cipher" $ do + func "cipher (64B input)" + (ChaCha20.cipher key 1 non) bs0 + func "cipher (256B input)" + (ChaCha20.cipher key 1 non) bs1 + func "cipher (1024B input)" + (ChaCha20.cipher key 1 non) bs2 + func "cipher (4096B input)" + (ChaCha20.cipher key 1 non) bs3 diff --git a/ppad-chacha.cabal b/ppad-chacha.cabal @@ -71,3 +71,21 @@ benchmark chacha-bench , ppad-base16 , ppad-chacha +benchmark chacha-weigh + type: exitcode-stdio-1.0 + default-language: Haskell2010 + hs-source-dirs: bench + main-is: Weight.hs + + ghc-options: + -rtsopts -O2 -Wall -fno-warn-orphans + if flag(llvm) + ghc-options: -fllvm + + build-depends: + base + , bytestring + , deepseq + , ppad-chacha + , weigh +