summaryrefslogtreecommitdiffhomepage
path: root/Shard.hs
blob: 14ebbf5bf52dafcb39d3371e7d9411186976e171 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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

genShards :: EncryptedSecretKey -> ShardParams -> IO [StorableObject]
genShards esk ps = 
	map (StorableObject . encode) <$> SS.encode
		(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