summaryrefslogtreecommitdiffhomepage
path: root/keysafe.hs
diff options
context:
space:
mode:
authorJoey Hess <joeyh@joeyh.name>2016-08-30 14:42:06 -0400
committerJoey Hess <joeyh@joeyh.name>2016-08-30 14:42:06 -0400
commitc273ac0173c9b277b2ba08a086e3091ba32d4319 (patch)
tree3cb1d60625b537f38e6194c1c80a8b119a9b0aaf /keysafe.hs
parentfe975ad122c77b4936f3e28c868b056fdaf2f842 (diff)
downloadkeysafe-c273ac0173c9b277b2ba08a086e3091ba32d4319.tar.gz
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.
Diffstat (limited to 'keysafe.hs')
-rw-r--r--keysafe.hs23
1 files changed, 13 insertions, 10 deletions
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.)"