summaryrefslogtreecommitdiffhomepage
path: root/Shard.hs
diff options
context:
space:
mode:
Diffstat (limited to 'Shard.hs')
-rw-r--r--Shard.hs22
1 files changed, 13 insertions, 9 deletions
diff --git a/Shard.hs b/Shard.hs
index cd510cd..14ebbf5 100644
--- a/Shard.hs
+++ b/Shard.hs
@@ -1,18 +1,22 @@
module Shard where
import Types
+import Serialization
+import Cost
import qualified Crypto.SecretSharing as SS
import qualified Data.ByteString.Lazy as BL
+import Raaz.Core.Encode (toByteString, fromByteString)
import Data.Binary
--- | Parameters for sharding. The secret is split into
--- N objects, such that only M are needed to reconstruct it.
-data ShardParams = ShardParams
- { totalObjects :: Int -- ^ N
- , neededObjects :: Int -- ^ M
- }
-
genShards :: EncryptedSecretKey -> ShardParams -> IO [StorableObject]
-genShards (EncryptedSecretKey esk _) ps =
+genShards esk ps =
map (StorableObject . encode) <$> SS.encode
- (neededObjects ps) (totalObjects ps) (BL.fromStrict esk)
+ (neededObjects ps)
+ (totalObjects ps)
+ (BL.fromStrict (toByteString esk))
+
+-- Throws AssertionFailed if the number of shares is too small.
+combineShards :: [StorableObject] -> Maybe EncryptedSecretKey
+combineShards = fromByteString . BL.toStrict . SS.decode . map conv
+ where
+ conv = decode . fromStorableObject