summaryrefslogtreecommitdiffhomepage
path: root/Tunables.hs
diff options
context:
space:
mode:
authorJoey Hess <joeyh@joeyh.name>2016-08-28 12:48:24 -0400
committerJoey Hess <joeyh@joeyh.name>2016-08-28 12:48:24 -0400
commitb0aa14ea3b12ab0559793bfb46df4625d7792bd4 (patch)
tree5abac8706a3c440c0598a57d4c4de8d677a44af1 /Tunables.hs
parentbb9d3ea8598a0b48e9d773df24ff58856cbb9aa0 (diff)
downloadkeysafe-b0aa14ea3b12ab0559793bfb46df4625d7792bd4.tar.gz
http: refuse to store object of unexpected size
Diffstat (limited to 'Tunables.hs')
-rw-r--r--Tunables.hs17
1 files changed, 15 insertions, 2 deletions
diff --git a/Tunables.hs b/Tunables.hs
index ce7aa6e..3fa700a 100644
--- a/Tunables.hs
+++ b/Tunables.hs
@@ -7,8 +7,10 @@
module Tunables where
+import Types
import Cost
import qualified Crypto.Argon2 as Argon2
+import qualified Data.ByteString as B
-- | To determine the tunables used for a key name the expensive hash of the
-- name is calculated, using a particular configuration, and if the
@@ -38,6 +40,8 @@ data Tunables = Tunables
-- ^ a StorableObject is exactly this many bytes in size
-- (must be a multiple of AES block size 16, and cannot be smaller
-- than 256 bytes)
+ , shareOverhead :: Int
+ -- ^ Share encoding overhead as a multiple of the objectSize
, nameGenerationTunable :: NameGenerationTunable
, keyEncryptionKeyTunable :: KeyEncryptionKeyTunable
, encryptionTunable :: EncryptionTunable
@@ -82,7 +86,8 @@ data EncryptionTunable = UseAES256
defaultTunables :: Tunables
defaultTunables = Tunables
{ shareParams = ShareParams { totalObjects = 3, neededObjects = 2 }
- , objectSize = 1024*64 -- 64 kb
+ , objectSize = 1024*32 -- 32 kb
+ , shareOverhead = 2
-- The nameGenerationHash was benchmarked at 661 seconds CPU time
-- on a 2 core Intel(R) Core(TM) i5-4210Y CPU @ 1.50GHz.
-- Since cost is measured per core, we double that.
@@ -114,7 +119,8 @@ defaultTunables = Tunables
testModeTunables :: Tunables
testModeTunables = Tunables
{ shareParams = ShareParams { totalObjects = 3, neededObjects = 2 }
- , objectSize = 1024*64
+ , objectSize = 1024*32
+ , shareOverhead = 2
, nameGenerationTunable = NameGenerationTunable
{ nameGenerationHash = weakargon2 (CPUCost (Seconds (2*600)))
}
@@ -127,3 +133,10 @@ testModeTunables = Tunables
}
where
weakargon2 c = UseArgon2 c Argon2.defaultHashOptions
+
+validObjectsize :: StorableObject -> Bool
+validObjectsize o = any (sz ==) knownsizes
+ where
+ sz = B.length (fromStorableObject o)
+ knownsizes = map (\t -> objectSize t * shareOverhead t)
+ (map snd knownTunings)