bolt8

Encrypted and authenticated transport, per BOLT #8 (docs.ppad.tech/bolt8).
git clone git://git.ppad.tech/bolt8.git
Log | Files | Refs | README | LICENSE

Main.hs (1704B)


      1 module Main where
      2 
      3 import Criterion.Main
      4 import qualified Data.ByteString as BS
      5 import Fixture
      6 import qualified Lightning.Protocol.BOLT8 as BOLT8
      7 
      8 main :: IO ()
      9 main = do
     10   fx <- fixture
     11   defaultMain [
     12       keys fx
     13     , handshake fx
     14     , transport fx
     15     ]
     16 
     17 keys :: Fixture -> Benchmark
     18 keys fx = bgroup "keys" [
     19     bench "keypair" $ nf BOLT8.keypair i_s_ent
     20   , bench "parse_pub" $ nf BOLT8.parse_pub pub_bs
     21   , bench "serialize_pub" $ nf BOLT8.serialize_pub pub
     22   ]
     23   where
     24     pub = BOLT8.keypair_pub (fx_r fx)
     25     pub_bs = BOLT8.serialize_pub pub
     26 
     27 handshake :: Fixture -> Benchmark
     28 handshake fx = bgroup "handshake" [
     29     bench "act1" $
     30       nf (BOLT8.act1 (fx_i fx) (BOLT8.keypair_pub (fx_r fx))) i_e_ent
     31   , bench "act2" $ nf (BOLT8.act2 (fx_r fx) r_e_ent) (fx_msg1 fx)
     32   , bench "act3" $ nf (BOLT8.act3 (fx_i_hs fx)) (fx_msg2 fx)
     33   , bench "finalize" $ nf (BOLT8.finalize (fx_r_hs fx)) (fx_msg3 fx)
     34   ]
     35 
     36 transport :: Fixture -> Benchmark
     37 transport fx = bgroup "transport" [
     38     bench "encrypt (32B)" $ nf (BOLT8.encrypt (fx_snd fx)) msg_32
     39   , bench "encrypt (1KB)" $ nf (BOLT8.encrypt (fx_snd fx)) msg_1k
     40   , bench "encrypt (64KB)" $ nf (BOLT8.encrypt (fx_snd fx)) msg_64k
     41   , bench "encrypt (32B, rotating)" $
     42       nf (BOLT8.encrypt (fx_snd_rot fx)) msg_32
     43   , bench "decrypt (32B)" $ nf (BOLT8.decrypt (fx_rcv fx)) (fx_ct_32 fx)
     44   , bench "decrypt (1KB)" $ nf (BOLT8.decrypt (fx_rcv fx)) (fx_ct_1k fx)
     45   , bench "decrypt (64KB)" $ nf (BOLT8.decrypt (fx_rcv fx)) (fx_ct_64k fx)
     46   , bench "decrypt_header" $
     47       nf (BOLT8.decrypt_header (fx_rcv fx)) (BS.take 18 (fx_ct_1k fx))
     48   , bench "decrypt_body (1KB)" $
     49       nf (BOLT8.decrypt_body (fx_pend_1k fx)) (BS.drop 18 (fx_ct_1k fx))
     50   ]