diff options
author | Joey Hess <joeyh@joeyh.name> | 2016-08-07 12:09:53 -0400 |
---|---|---|
committer | Joey Hess <joeyh@joeyh.name> | 2016-08-07 12:09:53 -0400 |
commit | 6205bbac7abc919371a5e7af9e4ba1a8d70de85e (patch) | |
tree | 668f3247182d01f025ce9122f6b495def240eb71 /Cost.hs | |
parent | 016877aa55764d14af3c16645d64fd95bf6a2da1 (diff) | |
download | keysafe-6205bbac7abc919371a5e7af9e4ba1a8d70de85e.tar.gz |
basic password entropy calculation
Diffstat (limited to 'Cost.hs')
-rw-r--r-- | Cost.hs | 16 |
1 files changed, 15 insertions, 1 deletions
@@ -2,9 +2,13 @@ module Cost where +import Types +import Entropy import Utility.HumanTime import Data.Monoid +import qualified Data.ByteString.UTF8 as B + -- | An estimated cost to perform an operation. data Cost op = CPUCost Seconds @@ -61,7 +65,7 @@ type CostCalc op t = Entropy t -> Cost op -- | Number of bits of entropy newtype Entropy t = Entropy Int - deriving (Num) + deriving (Num, Show) -- | Entropy can never go negative when subtracting bits from it. reduceEntropy :: Entropy t -> Int -> Entropy t @@ -70,6 +74,16 @@ reduceEntropy (Entropy a) b = Entropy (max 0 (a - b)) -- | Things that can have entropy data UnknownPassword +-- | Naive calculation of the entropy of a password. +-- Does not take common passowrds and password generation patterns into +-- account, so this is an overestimation of how hard a password +-- is to crack. +passwordEntropy :: Password -> Entropy UnknownPassword +passwordEntropy (Password p) = Entropy $ floor $ + entropy s * fromIntegral (length s) + where + s = B.toString p + -- | CostCalc for a brute force linear search through an entropy space -- in which each step entails paying a cost. -- |