blob: cd510cd1356b4132dcc0b36de500b5377f5207e6 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
module Shard where
import Types
import qualified Crypto.SecretSharing as SS
import qualified Data.ByteString.Lazy as BL
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 =
map (StorableObject . encode) <$> SS.encode
(neededObjects ps) (totalObjects ps) (BL.fromStrict esk)
|