auditor

An aarch64 constant-time memory access auditing tool.
git clone git://git.ppad.tech/auditor.git
Log | Files | Refs | README | LICENSE

Main.hs (1920B)


      1 {-# LANGUAGE OverloadedStrings #-}
      2 
      3 -- |
      4 -- Module: Main
      5 -- Copyright: (c) 2025 Jared Tobin
      6 -- License: MIT
      7 -- Maintainer: jared@ppad.tech
      8 --
      9 -- Criterion benchmarks for parser, CFG, and taint analysis.
     10 
     11 module Main where
     12 
     13 import Audit.AArch64.CFG (buildCFG)
     14 import Audit.AArch64.Check
     15   (checkCFG, checkCFGInterProc)
     16 import Audit.AArch64.Parser (parseAsm)
     17 import Audit.AArch64.Runtime.GHC (ghcRuntime)
     18 import Criterion.Main
     19 import qualified Data.ByteString as BS
     20 import Data.Text (Text)
     21 import Data.Text.Encoding (decodeUtf8)
     22 
     23 main :: IO ()
     24 main = do
     25   -- Load fixtures
     26   smallSrc <- loadFixture "etc/CurveNCG.s"
     27   largeSrc <- loadFixture "etc/secp256k1NCG.s"
     28 
     29   -- Pre-parse for CFG and analysis benchmarks
     30   smallLines <- case parseAsm smallSrc of
     31     Right lns -> pure lns
     32     Left e -> error $
     33       "Failed to parse CurveNCG.s: " ++ show e
     34   largeLines <- case parseAsm largeSrc of
     35     Right lns -> pure lns
     36     Left e -> error $
     37       "Failed to parse secp256k1NCG.s: " ++ show e
     38   let rt = ghcRuntime
     39       smallCFG = buildCFG rt smallLines
     40       largeCFG = buildCFG rt largeLines
     41 
     42   defaultMain
     43     [ bgroup "parse"
     44         [ bench "small (CurveNCG)" $
     45             nf parseAsm smallSrc
     46         , bench "large (secp256k1NCG)" $
     47             nf parseAsm largeSrc
     48         ]
     49     , bgroup "cfg"
     50         [ bench "small (CurveNCG)" $
     51             nf (buildCFG rt) smallLines
     52         , bench "large (secp256k1NCG)" $
     53             nf (buildCFG rt) largeLines
     54         ]
     55     , bgroup "taint"
     56         [ bench "intra-small" $
     57             nf (checkCFG rt "bench") smallCFG
     58         , bench "intra-large" $
     59             nf (checkCFG rt "bench") largeCFG
     60         , bench "inter-small" $
     61             nf (checkCFGInterProc rt "bench") smallCFG
     62         , bench "inter-large" $
     63             nf (checkCFGInterProc rt "bench") largeCFG
     64         ]
     65     ]
     66 
     67 loadFixture :: FilePath -> IO Text
     68 loadFixture path = decodeUtf8 <$> BS.readFile path