From 3229b02f0aa6bb23e351d00ade1263851a2f1826 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Tue, 16 Aug 2016 13:07:43 -0400 Subject: add --benchmark --- CmdLine.hs | 8 ++++++-- ExpensiveHash.hs | 4 ++-- INSTALL | 4 ++-- Tunables.hs | 2 +- Types.hs | 2 +- keysafe.hs | 10 ++++++---- 6 files changed, 18 insertions(+), 12 deletions(-) diff --git a/CmdLine.hs b/CmdLine.hs index b47d609..8e3040a 100644 --- a/CmdLine.hs +++ b/CmdLine.hs @@ -17,12 +17,12 @@ data CmdLine = CmdLine } deriving (Show) -data Mode = Backup | Restore +data Mode = Backup | Restore | Benchmark deriving (Show) parse :: Parser CmdLine parse = CmdLine - <$> (backup <|> restore) + <$> (backup <|> restore <|> benchmark) <*> keytypeopt <*> testmodeswitch <*> guiswitch @@ -35,6 +35,10 @@ parse = CmdLine ( long "restore" <> help "Retrieve a secret key from keysafe." ) + benchmark = flag' Benchmark + ( long "benchmark" + <> help "Benchmark speed of keysafe's cryptographic primitives." + ) keytypeopt = KeyType . BU8.fromString <$> strOption ( long "type" <> help "Type of key (eg, \"gpg\")." diff --git a/ExpensiveHash.hs b/ExpensiveHash.hs index 3d832fb..0e33604 100644 --- a/ExpensiveHash.hs +++ b/ExpensiveHash.hs @@ -42,7 +42,7 @@ expensiveHash (UseArgon2 cost opts) (Salt s) b = ExpensiveHash cost $ let sb = toByteString s in sb <> B.replicate (8 - B.length sb ) 32 -benchmarkExpensiveHash :: Int -> ExpensiveHashTunable -> Cost op -> IO (Benchmark (Cost op)) +benchmarkExpensiveHash :: Int -> ExpensiveHashTunable -> Cost op -> IO (BenchmarkResult (Cost op)) benchmarkExpensiveHash rounds tunables expected = do start <- getCurrentTime forM_ [1..rounds] $ \_ -> do @@ -53,7 +53,7 @@ benchmarkExpensiveHash rounds tunables expected = do end <- getCurrentTime let diff = floor $ end `diffUTCTime` start let actual = CPUCost $ Seconds diff - return $ Benchmark + return $ BenchmarkResult { expectedBenchmark = expected , actualBenchmark = actual } diff --git a/INSTALL b/INSTALL index 6707ab3..2c06466 100644 --- a/INSTALL +++ b/INSTALL @@ -1,5 +1,5 @@ -You should first install stack, the readline and argon2 libraries, -and zenity. For example, on a Debian system: +You should first install Haskell's stack tool, the readline and argon2 +libraries, and zenity. For example, on a Debian system: sudo apt-get install haskell-stack libreadline-dev libargon2-0-dev zenity diff --git a/Tunables.hs b/Tunables.hs index 49e6cd4..bd1d4b0 100644 --- a/Tunables.hs +++ b/Tunables.hs @@ -91,7 +91,7 @@ defaultTunables = Tunables { nameGenerationHash = argon2 10000 (CPUCost (Seconds (2*600))) } , keyEncryptionKeyTunable = KeyEncryptionKeyTunable - { keyEncryptionKeyHash = argon2 100 (CPUCost (Seconds 0)) + { keyEncryptionKeyHash = argon2 110 (CPUCost (Seconds 0)) , randomSaltBytes = 1 -- The keyEncryptionKeyHash is run 256 times per -- random salt byte to brute-force, and its parameters diff --git a/Types.hs b/Types.hs index 1b32286..799e76e 100644 --- a/Types.hs +++ b/Types.hs @@ -59,5 +59,5 @@ gpgKey = KeyType "gpg" data KeyId = KeyId KeyType B.ByteString deriving (Show) -data Benchmark t = Benchmark { expectedBenchmark :: t, actualBenchmark :: t } +data BenchmarkResult t = BenchmarkResult { expectedBenchmark :: t, actualBenchmark :: t } deriving (Show) diff --git a/keysafe.hs b/keysafe.hs index 4058487..7de3079 100644 --- a/keysafe.hs +++ b/keysafe.hs @@ -13,6 +13,7 @@ import qualified CmdLine import UI import Encryption import Entropy +import ExpensiveHash import Cost import Shard import Storage @@ -30,12 +31,13 @@ main = do -- TODO determine gpg key id by examining secret key, -- or retrieving public key from keyserver and examining it. let keyid = KeyId keytype "dummy key id" + let tunables = if CmdLine.testMode cmdline + then testModeTunables + else defaultTunables case CmdLine.mode cmdline of - CmdLine.Backup -> storedemo ui keyid $ - if CmdLine.testMode cmdline - then testModeTunables - else defaultTunables + CmdLine.Backup -> storedemo ui keyid tunables CmdLine.Restore -> retrievedemo ui keyid + CmdLine.Benchmark -> benchmarkTunables tunables storedemo :: UI -> KeyId -> Tunables -> IO () storedemo ui keyid tunables = do -- cgit v1.2.3