import Control.DeepSeq (NFData)
import Control.Monad (Monad(..), foldM, unless)
import Control.Monad.Trans.Except (ExceptT(..), throwE)
-import Data.Aeson (ToJSON(..),FromJSON(..),(.:),(.=))
+import Data.Aeson (ToJSON(..), FromJSON(..), (.:), (.=))
import Data.Eq (Eq(..))
import Data.Function (($))
import Data.Functor ((<$>))
import qualified Data.List as List
import Voting.Protocol.Utils
-import Voting.Protocol.Arith
+import Voting.Protocol.Arithmetic
+import Voting.Protocol.Version
+import Voting.Protocol.Cryptography
import Voting.Protocol.Credential
-import Voting.Protocol.Election
import Voting.Protocol.Tally
-- * Type 'TrusteePublicKey'
deriving instance (Show (G crypto c), Show (PublicKey crypto c)) => Show (TrusteePublicKey crypto v c)
deriving instance NFData (G crypto c) => NFData (TrusteePublicKey crypto v c)
instance
- ( Group crypto
+ ( Reifies v Version
, ToJSON (G crypto c)
) => ToJSON (TrusteePublicKey crypto v c) where
toJSON TrusteePublicKey{..} =
<> "public_key" .= trustee_PublicKey
)
instance
- ( Reifies c crypto
- , Group crypto
- , FromJSON (PublicKey crypto c)
+ ( Reifies v Version
+ , CryptoParams crypto c
) => FromJSON (TrusteePublicKey crypto v c) where
parseJSON = JSON.withObject "TrusteePublicKey" $ \o -> do
trustee_PublicKey <- o .: "public_key"
-- and a 'Proof' of its knowledge.
proveIndispensableTrusteePublicKey ::
Reifies v Version =>
- Reifies c crypto =>
- Group crypto =>
+ CryptoParams crypto c =>
Key crypto =>
- Multiplicative (G crypto c) =>
- Invertible (G crypto c) =>
- ToNatural (G crypto c) =>
Monad m => RandomGen r =>
SecretKey crypto c -> S.StateT r m (TrusteePublicKey crypto v c)
proveIndispensableTrusteePublicKey trustSecKey = do
-- the given 'trustee_PublicKey' is known by the trustee.
verifyIndispensableTrusteePublicKey ::
Reifies v Version =>
- Reifies c crypto =>
- Group crypto =>
- Multiplicative (G crypto c) =>
- Invertible (G crypto c) =>
- ToNatural (G crypto c) =>
+ CryptoParams crypto c =>
Monad m =>
TrusteePublicKey crypto v c ->
ExceptT ErrorTrusteePublicKey m ()
-- ** Hashing
indispensableTrusteePublicKeyStatement ::
- Reifies c crypto =>
- ToNatural (G crypto c) =>
+ CryptoParams crypto c =>
PublicKey crypto c -> BS.ByteString
indispensableTrusteePublicKeyStatement trustPubKey =
"pok|"<>bytesNat trustPubKey<>"|"
-- ** Generating an 'Election''s 'PublicKey' from multiple 'TrusteePublicKey's.
combineIndispensableTrusteePublicKeys ::
- Reifies c crypto =>
- Multiplicative (G crypto c) =>
- Invertible (G crypto c) =>
- ToNatural (G crypto c) =>
+ CryptoParams crypto c =>
[TrusteePublicKey crypto v c] -> PublicKey crypto c
combineIndispensableTrusteePublicKeys =
List.foldr (\TrusteePublicKey{..} -> (trustee_PublicKey *)) one
verifyIndispensableDecryptionShareByTrustee ::
Reifies v Version =>
- Reifies c crypto =>
- Group crypto =>
- Multiplicative (G crypto c) =>
- Invertible (G crypto c) =>
- ToNatural (G crypto c) =>
+ CryptoParams crypto c =>
Monad m =>
EncryptedTally crypto v c -> [PublicKey crypto c] -> [DecryptionShare crypto v c] ->
ExceptT ErrorTally m ()
-- returns the 'DecryptionFactor's by choice by 'Question'
combineIndispensableDecryptionShares ::
Reifies v Version =>
- Reifies c crypto =>
- Group crypto =>
- Multiplicative (G crypto c) =>
- Invertible (G crypto c) =>
- ToNatural (G crypto c) =>
+ CryptoParams crypto c =>
[PublicKey crypto c] -> DecryptionShareCombinator crypto v c
combineIndispensableDecryptionShares
pubKeyByTrustee