From c273ac0173c9b277b2ba08a086e3091ba32d4319 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Tue, 30 Aug 2016 14:42:06 -0400 Subject: Improve time estimates, taking into account the number of cores. This only affects time estimates while keysafe is generating hashes; it does not affect cost estimates to brute-force. --- keysafe.hs | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) (limited to 'keysafe.hs') diff --git a/keysafe.hs b/keysafe.hs index f724b97..0f32ac1 100644 --- a/keysafe.hs +++ b/keysafe.hs @@ -79,6 +79,7 @@ backup storagelocations ui tunables secretkeysource secretkey = do go theirname where go theirname = do + cores <- fromMaybe 1 <$> getNumCores Name othername <- fromMaybe (error "aborting on no othername") <$> promptName ui "Enter other name" othernamedesc Nothing validateName @@ -87,7 +88,7 @@ backup storagelocations ui tunables secretkeysource secretkey = do let sis = shareIdents tunables name secretkeysource let cost = getCreationCost kek <> getCreationCost sis r <- withProgressIncremental ui "Encrypting and storing data" - (encryptdesc cost) $ \addpercent -> do + (encryptdesc cost cores) $ \addpercent -> do let esk = encrypt tunables kek secretkey shares <- genShares esk tunables _ <- esk `deepseq` addpercent 25 @@ -161,8 +162,8 @@ backup storagelocations ui tunables secretkeysource secretkey = do crackdesc crackcost thisyear = unlines $ "Rough estimate of the cost to crack your password: " : costOverTimeTable crackcost thisyear - encryptdesc cost = unlines - [ "This will probably take around " ++ showCostMinutes cost + encryptdesc cost cores = unlines + [ "This will probably take around " ++ showCostMinutes cores cost , "" , "(It's a feature that this takes a while; it makes it hard" , "for anyone to find your data, or crack your password.)" @@ -181,6 +182,7 @@ otherNameSuggestions = unlines $ map (" * " ++) restore :: StorageLocations -> UI -> [Tunables] -> SecretKeySource -> IO () restore storagelocations ui possibletunables secretkeydest = do + cores <- fromMaybe 1 <$> getNumCores username <- userName Name theirname <- fromMaybe (error "Aborting on no username") <$> promptName ui "Enter your name" @@ -204,7 +206,7 @@ restore storagelocations ui possibletunables secretkeydest = do Left e -> showError ui e Right esk -> do final <- withProgress ui "Decrypting" - (decryptdesc cost) $ \setpercent -> + (decryptdesc cost cores) $ \setpercent -> go tunables [shares] sis setpercent $ tryDecrypt candidatekeys esk final @@ -242,8 +244,8 @@ restore storagelocations ui possibletunables secretkeydest = do passworddesc = unlines [ "Enter the password to unlock your secret key." ] - decryptdesc cost = unlines - [ "This will probably take around " ++ showCostMinutes cost + decryptdesc cost cores = unlines + [ "This will probably take around " ++ showCostMinutes cores cost , "" , "(It's a feature that this takes so long; it prevents cracking your password.)" , "" @@ -259,8 +261,9 @@ downloadInitialShares -> (Tunables -> ShareIdents) -> [Tunables] -> IO (Maybe (Tunables, S.Set Share, ShareIdents)) -downloadInitialShares storagelocations ui mksis possibletunables = - withProgressIncremental ui "Downloading encrypted data" message $ \addpercent -> do +downloadInitialShares storagelocations ui mksis possibletunables = do + cores <- fromMaybe 1 <$> getNumCores + withProgressIncremental ui "Downloading encrypted data" (message cores) $ \addpercent -> do go possibletunables addpercent where go [] _ = return Nothing @@ -277,9 +280,9 @@ downloadInitialShares storagelocations ui mksis possibletunables = else return $ Just (tunables, shares, sis') possiblesis = map mksis possibletunables - message = unlines + message cores = unlines [ "This will probably take around " - ++ showCostMinutes (mconcat $ map getCreationCost possiblesis) + ++ showCostMinutes cores (mconcat $ map getCreationCost possiblesis) , "" , "(It's a feature that this takes a while; it makes it hard" , "for anyone else to find your data.)" -- cgit v1.2.3