summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorJoey Hess <joeyh@joeyh.name>2016-08-07 00:29:18 -0400
committerJoey Hess <joeyh@joeyh.name>2016-08-07 00:29:18 -0400
commit7890e78cc6e98fed07bc2ad471b527a2f1b1494f (patch)
tree7f61f981730f550475aa4235d04aac822077a6bc
parenta1de1fb890773d5909e9214496890d4dd0972820 (diff)
downloadkeysafe-7890e78cc6e98fed07bc2ad471b527a2f1b1494f.tar.gz
improve types
-rw-r--r--Cost.hs9
-rw-r--r--Encryption.hs5
2 files changed, 12 insertions, 2 deletions
diff --git a/Cost.hs b/Cost.hs
index 0425707..5fd003f 100644
--- a/Cost.hs
+++ b/Cost.hs
@@ -1,4 +1,4 @@
-{-# LANGUAGE GeneralizedNewtypeDeriving #-}
+{-# LANGUAGE GeneralizedNewtypeDeriving, MultiParamTypeClasses #-}
module Cost where
@@ -74,3 +74,10 @@ data UnknownPassword
bruteForceLinearSearch :: Cost step -> CostCalc BruteForceOp t
bruteForceLinearSearch stepcost e =
castCost stepcost `raiseCostPower` reduceEntropy e 1
+
+-- | Things that can be brute-forced expose a CostCalc.
+class Bruteforceable t a where
+ getBruteCostCalc :: t -> CostCalc BruteForceOp a
+
+estimateBruteforceOf :: Bruteforceable t a => t -> Entropy a -> Cost BruteForceOp
+estimateBruteforceOf t e = getBruteCostCalc t e
diff --git a/Encryption.hs b/Encryption.hs
index 98afdfd..23da288 100644
--- a/Encryption.hs
+++ b/Encryption.hs
@@ -1,4 +1,4 @@
-{-# LANGUAGE OverloadedStrings #-}
+{-# LANGUAGE OverloadedStrings, MultiParamTypeClasses #-}
module Encryption where
@@ -19,6 +19,9 @@ data KeyEncryptionKey = KeyEncryptionKey
(Cost DecryptionOp)
(CostCalc BruteForceOp UnknownPassword)
+instance Bruteforceable KeyEncryptionKey UnknownPassword where
+ getBruteCostCalc (KeyEncryptionKey _ _ c) = c
+
-- | The ExpensiveHash of the Password is combined with a
-- RandomObstacle to form the AES key. Combination method is logical OR.
genKeyEncryptionKey :: Tunables -> KeyIdent -> Password -> KeyEncryptionKey