summaryrefslogtreecommitdiffhomepage
path: root/Cost.hs
diff options
context:
space:
mode:
authorJoey Hess <joeyh@joeyh.name>2016-08-07 16:25:12 -0400
committerJoey Hess <joeyh@joeyh.name>2016-08-07 16:25:12 -0400
commit39707fda6289740729bef8cb214a2bf3f555b86e (patch)
tree98fa699a499b2ef679f88785d65aaee445c748c4 /Cost.hs
parent460edfad8ed45412050822dfdf84f2d54015fb04 (diff)
downloadkeysafe-39707fda6289740729bef8cb214a2bf3f555b86e.tar.gz
finish AES decryption puzzle implementation
Diffstat (limited to 'Cost.hs')
-rw-r--r--Cost.hs34
1 files changed, 22 insertions, 12 deletions
diff --git a/Cost.hs b/Cost.hs
index c31c4f8..38b6e28 100644
--- a/Cost.hs
+++ b/Cost.hs
@@ -88,7 +88,7 @@ bruteForceLinearSearch :: Cost step -> CostCalc BruteForceOp t
bruteForceLinearSearch stepcost e =
castCost stepcost `raiseCostPower` reduceEntropy e 1
--- | Things that can be brute-forced expose a CostCalc.
+-- | Things that can be brute-forced track their CostCalc.
class Bruteforceable t a where
getBruteCostCalc :: t -> CostCalc BruteForceOp a
@@ -96,22 +96,32 @@ class Bruteforceable t a where
estimateBruteforceOf :: Bruteforceable t a => t -> Entropy a -> Cost BruteForceOp
estimateBruteforceOf t e = getBruteCostCalc t e
--- | Estimate of cost of brute force attack using AWS Spot instances,
--- in US dollars.
---
+data DataCenterPrice = DataCenterPrice
+ { instanceCpuCores :: Integer
+ , instanceCostPerHour :: Cents
+ }
+
-- August 2016 spot pricing: 36 CPU core c4.8xlarge at 33c/hour
+spotAWS :: DataCenterPrice
+spotAWS = DataCenterPrice
+ { instanceCpuCores = 36
+ , instanceCostPerHour = Cents 33
+ }
+
+-- | Estimate of cost of brute force attack using a datacenter.
--
--- Note that less GPU time is available on these instances;
--- there are not 36 GPU cores. But for simplicity we assume there are
--- that many GPU cores. So, this underestimates the price to brute
--- force such operations.
-estimateAWSSpotAttack :: Cost BruteForceOp -> Dollars
-estimateAWSSpotAttack opcost = centsToDollars $ costcents
+-- Note that this assumes that CPU cores and GPU cores are of equal number,
+-- which is unlikely to be the case; typically there will be many more
+-- cores than GPUs. So, this underestimates the price to brute force
+-- operations which run faster on GPUs.
+estimateAttack :: DataCenterPrice -> Cost BruteForceOp -> Dollars
+estimateAttack dc opcost = centsToDollars $ costcents
where
(Seconds cpuseconds) = fst (totalCost opcost)
cpuyears = cpuseconds `div` (60*60*24*365)
- cpucores = 36
- costpercpuyear = Cents (33*24*365 `div` cpucores)
+ costpercpuyear = Cents $
+ fromIntegral (instanceCostPerHour dc) * 24 * 365
+ `div` instanceCpuCores dc
costcents = Cents cpuyears * costpercpuyear
newtype Cents = Cents Integer