From 016877aa55764d14af3c16645d64fd95bf6a2da1 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Sun, 7 Aug 2016 11:44:23 -0400 Subject: aws spot instance attack cost estimate --- Cost.hs | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) (limited to 'Cost.hs') diff --git a/Cost.hs b/Cost.hs index 99baa33..de5a82d 100644 --- a/Cost.hs +++ b/Cost.hs @@ -6,7 +6,10 @@ import Utility.HumanTime import Data.Monoid -- | An estimated cost to perform an operation. -data Cost op = CPUCost Seconds | GPUCost Seconds | CombinedCost (Cost op) (Cost op) +data Cost op + = CPUCost Seconds + | GPUCost Seconds + | CombinedCost (Cost op) (Cost op) deriving (Show) newtype Seconds = Seconds Integer @@ -80,5 +83,33 @@ bruteForceLinearSearch stepcost e = class Bruteforceable t a where getBruteCostCalc :: t -> CostCalc BruteForceOp a +-- | Estimate of cost of a brute force attack. 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. +-- +-- August 2016 spot pricing: 36 CPU core c4.8xlarge at 33c/hour +-- +-- 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 + where + (Seconds cpuseconds) = fst (totalCost opcost) + cpuyears = cpuseconds `div` (60*60*24*365) + cpucores = 36 + costpercpuyear = Cents (33*24*365 `div` cpucores) + costcents = Cents cpuyears * costpercpuyear + +newtype Cents = Cents Integer + deriving (Num, Integral, Enum, Real, Ord, Eq, Show) + +newtype Dollars = Dollars Integer + deriving (Num, Integral, Enum, Real, Ord, Eq, Show) + +centsToDollars :: Cents -> Dollars +centsToDollars (Cents c) = Dollars (c `div` 100) -- cgit v1.2.3