From 39707fda6289740729bef8cb214a2bf3f555b86e Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Sun, 7 Aug 2016 16:25:12 -0400 Subject: finish AES decryption puzzle implementation --- Cost.hs | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-) (limited to 'Cost.hs') 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 -- cgit v1.2.3