-- Hoogle documentation, generated by Haddock
-- See Hoogle, http://www.haskell.org/hoogle/

-- | Information-theoretic secure secret sharing
--   
--   Implementation of an (m,n)-threshold secret sharing
--   scheme. A given ByteString b (the secret) is split into
--   n shares, and any m shares are sufficient to
--   reconstruct b. The scheme preserves information-theoretic
--   perfect secrecy in the sense that the knowledge of up to m-1
--   shares does not reveal any information about the secret b.
--   
--   Example in GHCi: Suppose that you want to split the string "my
--   secret data" into n=5 shares such that at least m=3 shares are
--   necessary to reconstruct the secret.
--   
--   
--   > :m + Data.ByteString.Lazy.Char8 Crypto.SecretSharing
--   > let secret = pack "my secret message!"
--   > shares <- encode 3 5 secret
--   > mapM_ (Prelude.putStrLn . show) shares -- each share should be deposited at a different site.
--    (1,"\134\168\154\SUBV\248\CAN:\250y<\GS\EOT*\t\222_\140")
--    (2,"\225\206\241\136\SUBse\199r\169\162\131D4\179P\210x")
--    (3,"~\238%\192\174\206\\\f\214\173\162\148\&3\139_\183\193\235")
--    (4,"Z\b0\188\DC2\f\247\f,\136\&6S\209\&5\n\FS,\223")
--    (5,"x\EM\CAN\DELI*<\193q7d\192!/\183v\DC3T")
--   > let shares' = Prelude.drop 2 shares
--   > decode shares'
--    "my secret message!"
--   
--   
--   The mathematics behind the secret sharing scheme is described in:
--   "How to share a secret." by Adi Shamir. In Communications of
--   the ACM 22 (11): 612–613, 1979.
@package secret-sharing
@version 1.0.0.3

module Crypto.SecretSharing.Internal

-- | A share of an encoded byte.
data ByteShare
ByteShare :: !Int -> !Int -> !Int -> ByteShare

-- | the index of this share
[shareId] :: ByteShare -> !Int

-- | number of shares required for reconstruction
[reconstructionThreshold] :: ByteShare -> !Int

-- | the value of p(shareId) where p(x) is the generated (secret)
--   polynomial
[shareValue] :: ByteShare -> !Int

-- | A share of the encoded secret.
data Share
Share :: ![ByteShare] -> Share
[theShare] :: Share -> ![ByteShare]

-- | Encodes a ByteString as a list of n shares, m of which are
--   required for reconstruction. Lives in the IO to access a random
--   source.
encode :: Int -> Int -> ByteString -> IO [Share]

-- | Reconstructs a (secret) bytestring from a list of (at least
--   m) shares. Throws AssertionFailed if the number of
--   shares is too small.
decode :: [Share] -> ByteString
encodeByte :: Int -> Int -> Polyn -> FField -> Vector ByteShare
decodeByte :: [ByteShare] -> FField

-- | Groups a list into blocks of certain size. Running time: O(n)
groupInto :: Int -> [a] -> [[a]]

-- | A finite prime field. All computations are performed in this field.
newtype FField
FField :: (PrimeField (I (O (I (I (I (I (I (I (I (I Z))))))))))) -> FField
[number] :: FField -> (PrimeField (I (O (I (I (I (I (I (I (I (I Z)))))))))))

-- | The size of the finite field
prime :: Int

-- | A polynomial over the finite field given as a list of coefficients.
type Polyn = [FField]

-- | Evaluates the polynomial at a given point.
evalPolynomial :: Polyn -> FField -> FField
instance Data.FiniteField.Base.FiniteField Crypto.SecretSharing.Internal.FField
instance GHC.Generics.Generic Crypto.SecretSharing.Internal.FField
instance GHC.Real.Fractional Crypto.SecretSharing.Internal.FField
instance GHC.Num.Num Crypto.SecretSharing.Internal.FField
instance GHC.Classes.Eq Crypto.SecretSharing.Internal.FField
instance GHC.Classes.Ord Crypto.SecretSharing.Internal.FField
instance GHC.Read.Read Crypto.SecretSharing.Internal.FField
instance GHC.Show.Show Crypto.SecretSharing.Internal.FField
instance GHC.Generics.Generic Crypto.SecretSharing.Internal.Share
instance GHC.Classes.Eq Crypto.SecretSharing.Internal.Share
instance GHC.Generics.Generic Crypto.SecretSharing.Internal.ByteShare
instance GHC.Classes.Eq Crypto.SecretSharing.Internal.ByteShare
instance GHC.Show.Show Crypto.SecretSharing.Internal.ByteShare
instance GHC.Show.Show Crypto.SecretSharing.Internal.Share
instance Data.Binary.Class.Binary Crypto.SecretSharing.Internal.ByteShare
instance Data.Binary.Class.Binary Crypto.SecretSharing.Internal.Share

-- | Implementation of an (m,n)-threshold secret sharing
--   scheme. A given ByteString b (the secret) is split into
--   n shares, and any m shares are sufficient to
--   reconstruct b. The scheme preserves perfect secrecy in the
--   sense that the knowledge of up to m-1 shares does not reveal
--   any information about the secret b.
--   
--   Typically, there are n parties and we would like to give the
--   i-th party the i-share of each byte. For example, to
--   encode a bytestring secret as 10 shares, any
--   5 of which are sufficient for reconstruction we could write:
--   
--   
--   shares <- encode 5 10 secret
--   
--   
--   Note that each byte is encoded separately using a fresh set of random
--   coefficients.
--   
--   The mathematics behind the secret sharing scheme is described in: "How
--   to share a secret." by Shamir, Adi. In Communications of the ACM 22
--   (11): 612–613, 1979.
module Crypto.SecretSharing

-- | Encodes a ByteString as a list of n shares, m of which are
--   required for reconstruction. Lives in the IO to access a random
--   source.
encode :: Int -> Int -> ByteString -> IO [Share]

-- | Reconstructs a (secret) bytestring from a list of (at least
--   m) shares. Throws AssertionFailed if the number of
--   shares is too small.
decode :: [Share] -> ByteString

-- | A share of the encoded secret.
data Share
