auditor

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

Weight.hs (2219B)


      1 {-# LANGUAGE OverloadedStrings #-}
      2 
      3 -- |
      4 -- Module: Main
      5 -- Copyright: (c) 2025 Jared Tobin
      6 -- License: MIT
      7 -- Maintainer: jared@ppad.tech
      8 --
      9 -- Weigh benchmarks for allocation tracking.
     10 
     11 module Main where
     12 
     13 import Audit.AArch64.CFG (buildCFG, CFG)
     14 import Audit.AArch64.Check
     15   (checkCFG, checkCFGInterProc)
     16 import Audit.AArch64.Parser (parseAsm)
     17 import Audit.AArch64.Runtime (RuntimeConfig)
     18 import Audit.AArch64.Runtime.GHC (ghcRuntime)
     19 import Audit.AArch64.Types (Line)
     20 import qualified Data.ByteString as BS
     21 import Data.Text (Text)
     22 import Data.Text.Encoding (decodeUtf8)
     23 import System.IO.Unsafe (unsafePerformIO)
     24 import Weigh
     25 
     26 rt :: RuntimeConfig
     27 rt = ghcRuntime
     28 
     29 main :: IO ()
     30 main = mainWith $ do
     31   setColumns [Case, Allocated, GCs]
     32 
     33   -- Parse benchmarks
     34   wgroup "parse" $ do
     35     func "small (CurveNCG)" parseAsm smallSrc
     36     func "large (secp256k1NCG)" parseAsm largeSrc
     37 
     38   -- CFG benchmarks
     39   wgroup "cfg" $ do
     40     func "small (CurveNCG)" (buildCFG rt) smallLines
     41     func "large (secp256k1NCG)"
     42       (buildCFG rt) largeLines
     43 
     44   -- Taint benchmarks
     45   wgroup "taint-intra" $ do
     46     func "small (CurveNCG)"
     47       (checkCFG rt "bench") smallCFG
     48     func "large (secp256k1NCG)"
     49       (checkCFG rt "bench") largeCFG
     50 
     51   wgroup "taint-inter" $ do
     52     func "small (CurveNCG)"
     53       (checkCFGInterProc rt "bench") smallCFG
     54     func "large (secp256k1NCG)"
     55       (checkCFGInterProc rt "bench") largeCFG
     56 
     57 -- Fixtures loaded at top-level (evaluated once)
     58 {-# NOINLINE smallSrc #-}
     59 smallSrc :: Text
     60 smallSrc = unsafePerformIO $
     61   loadFixture "etc/CurveNCG.s"
     62 
     63 {-# NOINLINE largeSrc #-}
     64 largeSrc :: Text
     65 largeSrc = unsafePerformIO $
     66   loadFixture "etc/secp256k1NCG.s"
     67 
     68 {-# NOINLINE smallLines #-}
     69 smallLines :: [Line]
     70 smallLines = case parseAsm smallSrc of
     71   Right lns -> lns
     72   Left _ -> error "failed to parse small fixture"
     73 
     74 {-# NOINLINE largeLines #-}
     75 largeLines :: [Line]
     76 largeLines = case parseAsm largeSrc of
     77   Right lns -> lns
     78   Left _ -> error "failed to parse large fixture"
     79 
     80 {-# NOINLINE smallCFG #-}
     81 smallCFG :: CFG
     82 smallCFG = buildCFG rt smallLines
     83 
     84 {-# NOINLINE largeCFG #-}
     85 largeCFG :: CFG
     86 largeCFG = buildCFG rt largeLines
     87 
     88 loadFixture :: FilePath -> IO Text
     89 loadFixture path = decodeUtf8 <$> BS.readFile path