hjugement-protocol-0.0.8.20191027: A cryptographic protocol for the Majority Judgment.

Safe HaskellNone
LanguageHaskell2010

Voting.Protocol.Election

Contents

Synopsis

Type Encryption

data Encryption crypto v c Source #

ElGamal-like encryption. Its security relies on the Discrete Logarithm problem.

Because (groupGen ^encNonce ^secKey == groupGen ^secKey ^encNonce), knowing secKey, one can divide encryption_vault by (encryption_nonce ^secKey) to decipher (groupGen ^clear), then the clear text must be small to be decryptable, because it is encrypted as a power of groupGen (hence the "-like" in "ElGamal-like") to enable the additive homomorphism.

NOTE: Since (encryption_vault * encryption_nonce == encryption_nonce ^ (secKey + clear)), then: (logBase encryption_nonce (encryption_vault * encryption_nonce) == secKey + clear).

Constructors

Encryption 

Fields

Instances
Eq (FieldElement crypto c) => Eq (Encryption crypto v c) Source # 
Instance details

Defined in Voting.Protocol.Election

Methods

(==) :: Encryption crypto v c -> Encryption crypto v c -> Bool #

(/=) :: Encryption crypto v c -> Encryption crypto v c -> Bool #

(Show (FieldElement crypto c), Show (G crypto c)) => Show (Encryption crypto v c) Source # 
Instance details

Defined in Voting.Protocol.Election

Methods

showsPrec :: Int -> Encryption crypto v c -> ShowS #

show :: Encryption crypto v c -> String #

showList :: [Encryption crypto v c] -> ShowS #

Generic (Encryption crypto v c) Source # 
Instance details

Defined in Voting.Protocol.Election

Associated Types

type Rep (Encryption crypto v c) :: Type -> Type #

Methods

from :: Encryption crypto v c -> Rep (Encryption crypto v c) x #

to :: Rep (Encryption crypto v c) x -> Encryption crypto v c #

(Reifies v Version, Reifies c crypto, ToJSON (FieldElement crypto c)) => ToJSON (Encryption crypto v c) Source # 
Instance details

Defined in Voting.Protocol.Election

Methods

toJSON :: Encryption crypto v c -> Value #

toEncoding :: Encryption crypto v c -> Encoding #

toJSONList :: [Encryption crypto v c] -> Value #

toEncodingList :: [Encryption crypto v c] -> Encoding #

(Reifies v Version, Reifies c crypto, FromJSON (G crypto c)) => FromJSON (Encryption crypto v c) Source # 
Instance details

Defined in Voting.Protocol.Election

Methods

parseJSON :: Value -> Parser (Encryption crypto v c) #

parseJSONList :: Value -> Parser [Encryption crypto v c] #

NFData (FieldElement crypto c) => NFData (Encryption crypto v c) Source # 
Instance details

Defined in Voting.Protocol.Election

Methods

rnf :: Encryption crypto v c -> () #

(Reifies c crypto, Multiplicative (FieldElement crypto c)) => Additive (Encryption crypto v c) Source #

Additive homomorphism. Using the fact that: groupGen ^x * groupGen ^y == groupGen ^(x+y).

Instance details

Defined in Voting.Protocol.Election

Methods

zero :: Encryption crypto v c Source #

(+) :: Encryption crypto v c -> Encryption crypto v c -> Encryption crypto v c Source #

sum :: Foldable f => f (Encryption crypto v c) -> Encryption crypto v c Source #

type Rep (Encryption crypto v c) Source # 
Instance details

Defined in Voting.Protocol.Election

type Rep (Encryption crypto v c) = D1 (MetaData "Encryption" "Voting.Protocol.Election" "hjugement-protocol-0.0.8.20191027-9HiW8HrEuPGHgxG7ahMSfc" False) (C1 (MetaCons "Encryption" PrefixI True) (S1 (MetaSel (Just "encryption_nonce") NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 (G crypto c)) :*: S1 (MetaSel (Just "encryption_vault") NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 (G crypto c))))

Type EncryptionNonce

encrypt :: Reifies v Version => Reifies c crypto => Group crypto => Multiplicative (FieldElement crypto c) => Monad m => RandomGen r => PublicKey crypto c -> E crypto c -> StateT r m (EncryptionNonce crypto c, Encryption crypto v c) Source #

(encrypt pubKey clear) returns an ElGamal-like Encryption.

WARNING: the secret encryption nonce (encNonce) is returned alongside the Encryption in order to prove the validity of the encrypted clear text in proveEncryption, but this secret encNonce MUST be forgotten after that, as it may be used to decipher the Encryption without the SecretKey associated with pubKey.

Type Proof

data Proof crypto v c Source #

Non-Interactive Zero-Knowledge Proof of knowledge of a discrete logarithm: (secret == logBase base (base^secret)).

Constructors

Proof 

Fields

Instances
Eq (Proof crypto v c) Source # 
Instance details

Defined in Voting.Protocol.Election

Methods

(==) :: Proof crypto v c -> Proof crypto v c -> Bool #

(/=) :: Proof crypto v c -> Proof crypto v c -> Bool #

Show (Proof crypto v c) Source # 
Instance details

Defined in Voting.Protocol.Election

Methods

showsPrec :: Int -> Proof crypto v c -> ShowS #

show :: Proof crypto v c -> String #

showList :: [Proof crypto v c] -> ShowS #

Generic (Proof crypto v c) Source # 
Instance details

Defined in Voting.Protocol.Election

Associated Types

type Rep (Proof crypto v c) :: Type -> Type #

Methods

from :: Proof crypto v c -> Rep (Proof crypto v c) x #

to :: Rep (Proof crypto v c) x -> Proof crypto v c #

Group crypto => ToJSON (Proof crypto v c) Source # 
Instance details

Defined in Voting.Protocol.Election

Methods

toJSON :: Proof crypto v c -> Value #

toEncoding :: Proof crypto v c -> Encoding #

toJSONList :: [Proof crypto v c] -> Value #

toEncodingList :: [Proof crypto v c] -> Encoding #

(Reifies c crypto, Group crypto) => FromJSON (Proof crypto v c) Source # 
Instance details

Defined in Voting.Protocol.Election

Methods

parseJSON :: Value -> Parser (Proof crypto v c) #

parseJSONList :: Value -> Parser [Proof crypto v c] #

NFData (Proof crypto v c) Source # 
Instance details

Defined in Voting.Protocol.Election

Methods

rnf :: Proof crypto v c -> () #

type Rep (Proof crypto v c) Source # 
Instance details

Defined in Voting.Protocol.Election

type Rep (Proof crypto v c) = D1 (MetaData "Proof" "Voting.Protocol.Election" "hjugement-protocol-0.0.8.20191027-9HiW8HrEuPGHgxG7ahMSfc" False) (C1 (MetaCons "Proof" PrefixI True) (S1 (MetaSel (Just "proof_challenge") NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 (Challenge crypto c)) :*: S1 (MetaSel (Just "proof_response") NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 (E crypto c))))

Type ZKP

newtype ZKP Source #

Zero-knowledge proof.

A protocol is zero-knowledge if the verifier learns nothing from the protocol except that the prover knows the secret.

DOC: Mihir Bellare and Phillip Rogaway. Random oracles are practical: A paradigm for designing efficient protocols. In ACM-CCS’93, 1993.

Constructors

ZKP ByteString 

Type Challenge

Type Oracle

type Oracle list crypto c = list (Commitment crypto c) -> Challenge crypto c Source #

prove :: forall crypto v c list m r. Reifies c crypto => Reifies v Version => Group crypto => Multiplicative (FieldElement crypto c) => Monad m => RandomGen r => Functor list => E crypto c -> list (G crypto c) -> Oracle list crypto c -> StateT r m (Proof crypto v c) Source #

(prove sec commitmentBases oracle) returns a Proof that sec is known (by proving the knowledge of its discrete logarithm).

The Oracle is given Commitments equal to the commitmentBases raised to the power of the secret nonce of the Proof, as those are the Commitments that the verifier will obtain when composing the proof_challenge and proof_response together (with commit).

WARNING: for prove to be a so-called strong Fiat-Shamir transformation (not a weak): the statement must be included in the hash (along with the commitments).

NOTE: a random nonce is used to ensure each prove does not reveal any information regarding the secret sec, because two Proofs using the same Commitment can be used to deduce sec (using the special-soundness).

proveQuicker :: Reifies c crypto => Reifies v Version => Group crypto => Multiplicative (FieldElement crypto c) => Monad m => RandomGen r => Functor list => E crypto c -> list (G crypto c) -> Oracle list crypto c -> StateT r m (Proof crypto v c) Source #

Like prove but quicker. It chould replace prove entirely when Helios-C specifications will be fixed.

fakeProof :: Reifies c crypto => Group crypto => Monad m => RandomGen r => StateT r m (Proof crypto v c) Source #

(fakeProof) returns a Proof whose proof_challenge and proof_response are uniformly chosen at random, instead of (proof_challenge == hash statement commitments) and (proof_response == nonce + sec * proof_challenge) as a Proof returned by prove.

Used in proveEncryption to fill the returned DisjProof with fake Proofs for all Disjunctions but the encrypted one.

Type Commitment

type Commitment = G Source #

A commitment from the prover to the verifier. It's a power of groupGen chosen randomly by the prover when making a Proof with prove.

commit :: forall crypto v c. Reifies v Version => Reifies c crypto => Group crypto => Multiplicative (FieldElement crypto c) => Proof crypto v c -> G crypto c -> G crypto c -> Commitment crypto c Source #

(commit proof base basePowSec) returns a Commitment from the given Proof with the knowledge of the verifier.

commitQuicker :: Reifies c crypto => Multiplicative (FieldElement crypto c) => Proof crypto v c -> G crypto c -> G crypto c -> Commitment crypto c Source #

Like commit but quicker. It chould replace commit entirely when Helios-C specifications will be fixed.

Type Disjunction

type Disjunction = G Source #

A Disjunction is an inversed (groupGen ^opinion) it's used in proveEncryption to generate a Proof that an encryption_vault contains a given (groupGen ^opinion),

booleanDisjunctions :: forall crypto c. Reifies c crypto => Group crypto => Multiplicative (FieldElement crypto c) => [Disjunction crypto c] Source #

intervalDisjunctions :: forall crypto c. Reifies c crypto => Group crypto => Multiplicative (FieldElement crypto c) => Natural -> Natural -> [Disjunction crypto c] Source #

Type Opinion

type Opinion = E Source #

Index of a Disjunction within a list of them. It is encrypted as a GroupExponent by encrypt.

Type DisjProof

newtype DisjProof crypto v c Source #

A list of Proofs to prove that the Opinion within an Encryption is indexing a Disjunction within a list of them, without revealing which Opinion it is.

Constructors

DisjProof [Proof crypto v c] 
Instances
Eq (DisjProof crypto v c) Source # 
Instance details

Defined in Voting.Protocol.Election

Methods

(==) :: DisjProof crypto v c -> DisjProof crypto v c -> Bool #

(/=) :: DisjProof crypto v c -> DisjProof crypto v c -> Bool #

Show (DisjProof crypto v c) Source # 
Instance details

Defined in Voting.Protocol.Election

Methods

showsPrec :: Int -> DisjProof crypto v c -> ShowS #

show :: DisjProof crypto v c -> String #

showList :: [DisjProof crypto v c] -> ShowS #

Generic (DisjProof crypto v c) Source # 
Instance details

Defined in Voting.Protocol.Election

Associated Types

type Rep (DisjProof crypto v c) :: Type -> Type #

Methods

from :: DisjProof crypto v c -> Rep (DisjProof crypto v c) x #

to :: Rep (DisjProof crypto v c) x -> DisjProof crypto v c #

Group crypto => ToJSON (DisjProof crypto v c) Source # 
Instance details

Defined in Voting.Protocol.Election

Methods

toJSON :: DisjProof crypto v c -> Value #

toEncoding :: DisjProof crypto v c -> Encoding #

toJSONList :: [DisjProof crypto v c] -> Value #

toEncodingList :: [DisjProof crypto v c] -> Encoding #

(Reifies c crypto, Group crypto) => FromJSON (DisjProof crypto v c) Source # 
Instance details

Defined in Voting.Protocol.Election

Methods

parseJSON :: Value -> Parser (DisjProof crypto v c) #

parseJSONList :: Value -> Parser [DisjProof crypto v c] #

NFData (DisjProof crypto v c) Source # 
Instance details

Defined in Voting.Protocol.Election

Methods

rnf :: DisjProof crypto v c -> () #

type Rep (DisjProof crypto v c) Source # 
Instance details

Defined in Voting.Protocol.Election

type Rep (DisjProof crypto v c) = D1 (MetaData "DisjProof" "Voting.Protocol.Election" "hjugement-protocol-0.0.8.20191027-9HiW8HrEuPGHgxG7ahMSfc" True) (C1 (MetaCons "DisjProof" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 [Proof crypto v c])))

proveEncryption :: Reifies v Version => Reifies c crypto => Group crypto => ToNatural (FieldElement crypto c) => Multiplicative (FieldElement crypto c) => Monad m => RandomGen r => PublicKey crypto c -> ZKP -> ([Disjunction crypto c], [Disjunction crypto c]) -> (EncryptionNonce crypto c, Encryption crypto v c) -> StateT r m (DisjProof crypto v c) Source #

(proveEncryption elecPubKey voterZKP (prevDisjs,nextDisjs) (encNonce,enc)) returns a DisjProof that enc encrypts the Disjunction d between prevDisjs and nextDisjs.

The prover proves that it knows an encNonce, such that: (enc == Encryption{encryption_nonce=groupGen ^encNonce, encryption_vault=elecPubKey^encNonce * groupGen^d})

A NIZK Disjunctive Chaum Pedersen Logarithm Equality is used.

DOC: Pierrick Gaudry. Some ZK security proofs for Belenios, 2017.

verifyEncryption :: Reifies v Version => Reifies c crypto => Group crypto => ToNatural (FieldElement crypto c) => Multiplicative (FieldElement crypto c) => Monad m => PublicKey crypto c -> ZKP -> [Disjunction crypto c] -> (Encryption crypto v c, DisjProof crypto v c) -> ExceptT ErrorVerifyEncryption m Bool Source #

Hashing

encryptionStatement :: Reifies c crypto => ToNatural (FieldElement crypto c) => ZKP -> Encryption crypto v c -> ByteString Source #

encryptionCommitments :: Reifies v Version => Reifies c crypto => Group crypto => Multiplicative (FieldElement crypto c) => PublicKey crypto c -> Encryption crypto v c -> Disjunction crypto c -> Proof crypto v c -> [G crypto c] Source #

(encryptionCommitments elecPubKey enc disj proof) returns the Commitments with only the knowledge of the verifier.

For the prover the Proof comes from fakeProof, and for the verifier the Proof comes from the prover.

Type ErrorVerifyEncryption

Type Question

data Question v Source #

Instances
Eq (Question v) Source # 
Instance details

Defined in Voting.Protocol.Election

Methods

(==) :: Question v -> Question v -> Bool #

(/=) :: Question v -> Question v -> Bool #

Show (Question v) Source # 
Instance details

Defined in Voting.Protocol.Election

Methods

showsPrec :: Int -> Question v -> ShowS #

show :: Question v -> String #

showList :: [Question v] -> ShowS #

Generic (Question v) Source # 
Instance details

Defined in Voting.Protocol.Election

Associated Types

type Rep (Question v) :: Type -> Type #

Methods

from :: Question v -> Rep (Question v) x #

to :: Rep (Question v) x -> Question v #

Reifies v Version => ToJSON (Question v) Source # 
Instance details

Defined in Voting.Protocol.Election

Reifies v Version => FromJSON (Question v) Source # 
Instance details

Defined in Voting.Protocol.Election

NFData (Question v) Source # 
Instance details

Defined in Voting.Protocol.Election

Methods

rnf :: Question v -> () #

type Rep (Question v) Source # 
Instance details

Defined in Voting.Protocol.Election

type Rep (Question v) = D1 (MetaData "Question" "Voting.Protocol.Election" "hjugement-protocol-0.0.8.20191027-9HiW8HrEuPGHgxG7ahMSfc" False) (C1 (MetaCons "Question" PrefixI True) ((S1 (MetaSel (Just "question_text") NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 Text) :*: S1 (MetaSel (Just "question_choices") NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 [Text])) :*: (S1 (MetaSel (Just "question_mini") NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 Natural) :*: S1 (MetaSel (Just "question_maxi") NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 Natural))))

Type Answer

data Answer crypto v c Source #

Constructors

Answer 

Fields

Instances
Eq (FieldElement crypto c) => Eq (Answer crypto v c) Source # 
Instance details

Defined in Voting.Protocol.Election

Methods

(==) :: Answer crypto v c -> Answer crypto v c -> Bool #

(/=) :: Answer crypto v c -> Answer crypto v c -> Bool #

(Show (FieldElement crypto c), Show (G crypto c)) => Show (Answer crypto v c) Source # 
Instance details

Defined in Voting.Protocol.Election

Methods

showsPrec :: Int -> Answer crypto v c -> ShowS #

show :: Answer crypto v c -> String #

showList :: [Answer crypto v c] -> ShowS #

Generic (Answer crypto v c) Source # 
Instance details

Defined in Voting.Protocol.Election

Associated Types

type Rep (Answer crypto v c) :: Type -> Type #

Methods

from :: Answer crypto v c -> Rep (Answer crypto v c) x #

to :: Rep (Answer crypto v c) x -> Answer crypto v c #

(Reifies v Version, Reifies c crypto, ToJSON (FieldElement crypto c), Group crypto) => ToJSON (Answer crypto v c) Source # 
Instance details

Defined in Voting.Protocol.Election

Methods

toJSON :: Answer crypto v c -> Value #

toEncoding :: Answer crypto v c -> Encoding #

toJSONList :: [Answer crypto v c] -> Value #

toEncodingList :: [Answer crypto v c] -> Encoding #

(Reifies v Version, Reifies c crypto, FromJSON (G crypto c), Group crypto) => FromJSON (Answer crypto v c) Source # 
Instance details

Defined in Voting.Protocol.Election

Methods

parseJSON :: Value -> Parser (Answer crypto v c) #

parseJSONList :: Value -> Parser [Answer crypto v c] #

NFData (FieldElement crypto c) => NFData (Answer crypto v c) Source # 
Instance details

Defined in Voting.Protocol.Election

Methods

rnf :: Answer crypto v c -> () #

type Rep (Answer crypto v c) Source # 
Instance details

Defined in Voting.Protocol.Election

type Rep (Answer crypto v c) = D1 (MetaData "Answer" "Voting.Protocol.Election" "hjugement-protocol-0.0.8.20191027-9HiW8HrEuPGHgxG7ahMSfc" False) (C1 (MetaCons "Answer" PrefixI True) (S1 (MetaSel (Just "answer_opinions") NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 [(Encryption crypto v c, DisjProof crypto v c)]) :*: S1 (MetaSel (Just "answer_sumProof") NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 (DisjProof crypto v c))))

encryptAnswer :: Reifies v Version => Reifies c crypto => Group crypto => Multiplicative (FieldElement crypto c) => ToNatural (FieldElement crypto c) => Monad m => RandomGen r => PublicKey crypto c -> ZKP -> Question v -> [Bool] -> StateT r (ExceptT ErrorAnswer m) (Answer crypto v c) Source #

(encryptAnswer elecPubKey zkp quest opinions) returns an Answer validable by verifyAnswer, unless an ErrorAnswer is returned.

verifyAnswer :: Reifies v Version => Reifies c crypto => Group crypto => Multiplicative (FieldElement crypto c) => ToNatural (FieldElement crypto c) => PublicKey crypto c -> ZKP -> Question v -> Answer crypto v c -> Bool Source #

Type ErrorAnswer

data ErrorAnswer Source #

Error raised by encryptAnswer.

Constructors

ErrorAnswer_WrongNumberOfOpinions Natural Natural

When the number of opinions is different than the number of choices (question_choices).

ErrorAnswer_WrongSumOfOpinions Natural Natural Natural

When the sum of opinions is not within the bounds of question_mini and question_maxi.

Instances
Eq ErrorAnswer Source # 
Instance details

Defined in Voting.Protocol.Election

Show ErrorAnswer Source # 
Instance details

Defined in Voting.Protocol.Election

Generic ErrorAnswer Source # 
Instance details

Defined in Voting.Protocol.Election

Associated Types

type Rep ErrorAnswer :: Type -> Type #

NFData ErrorAnswer Source # 
Instance details

Defined in Voting.Protocol.Election

Methods

rnf :: ErrorAnswer -> () #

type Rep ErrorAnswer Source # 
Instance details

Defined in Voting.Protocol.Election

Type Election

data Election crypto v c Source #

Instances
(Eq crypto, Eq (FieldElement crypto c)) => Eq (Election crypto v c) Source # 
Instance details

Defined in Voting.Protocol.Election

Methods

(==) :: Election crypto v c -> Election crypto v c -> Bool #

(/=) :: Election crypto v c -> Election crypto v c -> Bool #

(Show crypto, Show (FieldElement crypto c)) => Show (Election crypto v c) Source # 
Instance details

Defined in Voting.Protocol.Election

Methods

showsPrec :: Int -> Election crypto v c -> ShowS #

show :: Election crypto v c -> String #

showList :: [Election crypto v c] -> ShowS #

Generic (Election crypto v c) Source # 
Instance details

Defined in Voting.Protocol.Election

Associated Types

type Rep (Election crypto v c) :: Type -> Type #

Methods

from :: Election crypto v c -> Rep (Election crypto v c) x #

to :: Rep (Election crypto v c) x -> Election crypto v c #

(ToJSON crypto, ToJSON (FieldElement crypto c), Reifies v Version, Reifies c crypto) => ToJSON (Election crypto v c) Source # 
Instance details

Defined in Voting.Protocol.Election

Methods

toJSON :: Election crypto v c -> Value #

toEncoding :: Election crypto v c -> Encoding #

toJSONList :: [Election crypto v c] -> Value #

toEncodingList :: [Election crypto v c] -> Encoding #

(NFData crypto, NFData (FieldElement crypto c)) => NFData (Election crypto v c) Source # 
Instance details

Defined in Voting.Protocol.Election

Methods

rnf :: Election crypto v c -> () #

type Rep (Election crypto v c) Source # 
Instance details

Defined in Voting.Protocol.Election

type Rep (Election crypto v c) = D1 (MetaData "Election" "Voting.Protocol.Election" "hjugement-protocol-0.0.8.20191027-9HiW8HrEuPGHgxG7ahMSfc" False) (C1 (MetaCons "Election" PrefixI True) (((S1 (MetaSel (Just "election_name") NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 Text) :*: S1 (MetaSel (Just "election_description") NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 Text)) :*: (S1 (MetaSel (Just "election_questions") NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 [Question v]) :*: S1 (MetaSel (Just "election_uuid") NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 UUID))) :*: ((S1 (MetaSel (Just "election_hash") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 Base64SHA256) :*: S1 (MetaSel (Just "election_crypto") NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 crypto)) :*: (S1 (MetaSel (Just "election_version") NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 (Maybe Version)) :*: S1 (MetaSel (Just "election_public_key") NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 (PublicKey crypto c))))))

readElection :: ReifyCrypto crypto => FromJSON crypto => FilePath -> (forall v c. Reifies v Version => Reifies c crypto => FieldElementConstraints crypto c => Election crypto v c -> r) -> ExceptT String IO r Source #

hashElection :: ToJSON crypto => Reifies c crypto => Reifies v Version => ToJSON (FieldElement crypto c) => Election crypto v c -> Base64SHA256 Source #

Class ReifyCrypto

class (Group crypto, Key crypto, Show crypto, NFData crypto, ToJSON crypto, FromJSON crypto) => ReifyCrypto crypto where Source #

(reifyCrypto crypto k) is like (reify crypto k) but gives to (k) more constraints than just (Reifies c crypto), which is used when defining classes on (crypto) where (c) (the type variable guarantying the same cryptographic parameters are used throughout) is not yet in scope and thus where one cannot add those constraints requiring to have (c) in scope. See for instance the QuickcheckElection class, in the tests.

For convenience, the ReifyCrypto class also implies the pervasive constraint Group.

Methods

reifyCrypto :: crypto -> (forall c. Reifies c crypto => FieldElementConstraints crypto c => Proxy c -> r) -> r Source #

Instances
ReifyCrypto FFC Source # 
Instance details

Defined in Voting.Protocol.Election

Methods

reifyCrypto :: FFC -> (forall c. (Reifies c FFC, FieldElementConstraints FFC c) => Proxy c -> r) -> r Source #

Class FieldElementConstraints

type FieldElementConstraints crypto c = (Multiplicative (FieldElement crypto c), FromNatural (FieldElement crypto c), ToNatural (FieldElement crypto c), Eq (FieldElement crypto c), Ord (FieldElement crypto c), Show (FieldElement crypto c), NFData (FieldElement crypto c), FromJSON (FieldElement crypto c), ToJSON (FieldElement crypto c), FromJSON (G crypto c), ToJSON (G crypto c)) Source #

List the Constraints on the element of the field when the (crypto) has not been instantiated to a specific type yet. It concerns only Constraints whose method act on (a), not (x c) (eg. Group).

Type Ballot

data Ballot crypto v c Source #

Constructors

Ballot 
Instances
Generic (Ballot crypto v c) Source # 
Instance details

Defined in Voting.Protocol.Election

Associated Types

type Rep (Ballot crypto v c) :: Type -> Type #

Methods

from :: Ballot crypto v c -> Rep (Ballot crypto v c) x #

to :: Rep (Ballot crypto v c) x -> Ballot crypto v c #

(Reifies v Version, Reifies c crypto, Group crypto, ToJSON (FieldElement crypto c)) => ToJSON (Ballot crypto v c) Source # 
Instance details

Defined in Voting.Protocol.Election

Methods

toJSON :: Ballot crypto v c -> Value #

toEncoding :: Ballot crypto v c -> Encoding #

toJSONList :: [Ballot crypto v c] -> Value #

toEncodingList :: [Ballot crypto v c] -> Encoding #

(Reifies v Version, Reifies c crypto, Group crypto, FromJSON (G crypto c)) => FromJSON (Ballot crypto v c) Source # 
Instance details

Defined in Voting.Protocol.Election

Methods

parseJSON :: Value -> Parser (Ballot crypto v c) #

parseJSONList :: Value -> Parser [Ballot crypto v c] #

(NFData (FieldElement crypto c), NFData crypto) => NFData (Ballot crypto v c) Source # 
Instance details

Defined in Voting.Protocol.Election

Methods

rnf :: Ballot crypto v c -> () #

type Rep (Ballot crypto v c) Source # 
Instance details

Defined in Voting.Protocol.Election

type Rep (Ballot crypto v c) = D1 (MetaData "Ballot" "Voting.Protocol.Election" "hjugement-protocol-0.0.8.20191027-9HiW8HrEuPGHgxG7ahMSfc" False) (C1 (MetaCons "Ballot" PrefixI True) ((S1 (MetaSel (Just "ballot_answers") NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 [Answer crypto v c]) :*: S1 (MetaSel (Just "ballot_signature") NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 (Maybe (Signature crypto v c)))) :*: (S1 (MetaSel (Just "ballot_election_uuid") NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 UUID) :*: S1 (MetaSel (Just "ballot_election_hash") NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 Base64SHA256))))

encryptBallot :: forall crypto m v c r. Reifies c crypto => Reifies v Version => Group crypto => Key crypto => Multiplicative (FieldElement crypto c) => ToNatural (FieldElement crypto c) => Monad m => RandomGen r => Election crypto v c -> Maybe (SecretKey crypto c) -> [[Bool]] -> StateT r (ExceptT ErrorBallot m) (Ballot crypto v c) Source #

(encryptBallot c (Just ballotSecKey) opinionsByQuest) returns a Ballot signed by secKey (the voter's secret key) where opinionsByQuest is a list of Opinions on each question_choices of each election_questions.

verifyBallot :: forall crypto v c. Reifies v Version => Reifies c crypto => Group crypto => Multiplicative (FieldElement crypto c) => ToNatural (FieldElement crypto c) => ToNatural (PublicKey crypto c) => Election crypto v c -> Ballot crypto v c -> Bool Source #

Type Signature

data Signature crypto v c Source #

Schnorr-like signature.

Used by each voter to sign his/her encrypted Ballot using his/her Credential, in order to avoid ballot stuffing.

Constructors

Signature 

Fields

Instances
Generic (Signature crypto v c) Source # 
Instance details

Defined in Voting.Protocol.Election

Associated Types

type Rep (Signature crypto v c) :: Type -> Type #

Methods

from :: Signature crypto v c -> Rep (Signature crypto v c) x #

to :: Rep (Signature crypto v c) x -> Signature crypto v c #

(Reifies c crypto, Reifies v Version, ToJSON (FieldElement crypto c)) => ToJSON (Signature crypto v c) Source # 
Instance details

Defined in Voting.Protocol.Election

Methods

toJSON :: Signature crypto v c -> Value #

toEncoding :: Signature crypto v c -> Encoding #

toJSONList :: [Signature crypto v c] -> Value #

toEncodingList :: [Signature crypto v c] -> Encoding #

(Reifies c crypto, Reifies v Version, Group crypto, FromJSON (PublicKey crypto c)) => FromJSON (Signature crypto v c) Source # 
Instance details

Defined in Voting.Protocol.Election

Methods

parseJSON :: Value -> Parser (Signature crypto v c) #

parseJSONList :: Value -> Parser [Signature crypto v c] #

(NFData crypto, NFData (FieldElement crypto c)) => NFData (Signature crypto v c) Source # 
Instance details

Defined in Voting.Protocol.Election

Methods

rnf :: Signature crypto v c -> () #

type Rep (Signature crypto v c) Source # 
Instance details

Defined in Voting.Protocol.Election

type Rep (Signature crypto v c) = D1 (MetaData "Signature" "Voting.Protocol.Election" "hjugement-protocol-0.0.8.20191027-9HiW8HrEuPGHgxG7ahMSfc" False) (C1 (MetaCons "Signature" PrefixI True) (S1 (MetaSel (Just "signature_publicKey") NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 (PublicKey crypto c)) :*: S1 (MetaSel (Just "signature_proof") NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 (Proof crypto v c))))

Hashing

signatureStatement :: Reifies c crypto => Foldable f => f (Answer crypto v c) -> [G crypto c] Source #

(signatureStatement answers) returns the encrypted material to be signed: all the encryption_nonces and encryption_vaults of the given answers.

signatureCommitments :: Reifies c crypto => ToNatural (FieldElement crypto c) => ZKP -> Commitment crypto c -> ByteString Source #

(signatureCommitments voterZKP commitment)

Type ErrorBallot

data ErrorBallot Source #

Error raised by encryptBallot.

Constructors

ErrorBallot_WrongNumberOfAnswers Natural Natural

When the number of answers is different than the number of questions.

ErrorBallot_Answer ErrorAnswer

When encryptAnswer raised an ErrorAnswer.

ErrorBallot_Wrong

TODO: to be more precise.

Instances
Eq ErrorBallot Source # 
Instance details

Defined in Voting.Protocol.Election

Show ErrorBallot Source # 
Instance details

Defined in Voting.Protocol.Election

Generic ErrorBallot Source # 
Instance details

Defined in Voting.Protocol.Election

Associated Types

type Rep ErrorBallot :: Type -> Type #

NFData ErrorBallot Source # 
Instance details

Defined in Voting.Protocol.Election

Methods

rnf :: ErrorBallot -> () #

type Rep ErrorBallot Source # 
Instance details

Defined in Voting.Protocol.Election

type Rep ErrorBallot = D1 (MetaData "ErrorBallot" "Voting.Protocol.Election" "hjugement-protocol-0.0.8.20191027-9HiW8HrEuPGHgxG7ahMSfc" False) (C1 (MetaCons "ErrorBallot_WrongNumberOfAnswers" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 Natural) :*: S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 Natural)) :+: (C1 (MetaCons "ErrorBallot_Answer" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 ErrorAnswer)) :+: C1 (MetaCons "ErrorBallot_Wrong" PrefixI False) (U1 :: Type -> Type)))

Type Version

data Version Source #

Version of the Helios-C protocol.

Constructors

Version 
Instances
Eq Version Source # 
Instance details

Defined in Voting.Protocol.Election

Methods

(==) :: Version -> Version -> Bool #

(/=) :: Version -> Version -> Bool #

Ord Version Source # 
Instance details

Defined in Voting.Protocol.Election

Show Version Source # 
Instance details

Defined in Voting.Protocol.Election

IsString Version Source # 
Instance details

Defined in Voting.Protocol.Election

Methods

fromString :: String -> Version #

Generic Version Source # 
Instance details

Defined in Voting.Protocol.Election

Associated Types

type Rep Version :: Type -> Type #

Methods

from :: Version -> Rep Version x #

to :: Rep Version x -> Version #

ToJSON Version Source # 
Instance details

Defined in Voting.Protocol.Election

FromJSON Version Source # 
Instance details

Defined in Voting.Protocol.Election

NFData Version Source # 
Instance details

Defined in Voting.Protocol.Election

Methods

rnf :: Version -> () #

type Rep Version Source # 
Instance details

Defined in Voting.Protocol.Election

type Rep Version = D1 (MetaData "Version" "Voting.Protocol.Election" "hjugement-protocol-0.0.8.20191027-9HiW8HrEuPGHgxG7ahMSfc" False) (C1 (MetaCons "Version" PrefixI True) (S1 (MetaSel (Just "version_branch") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 [Natural]) :*: S1 (MetaSel (Just "version_tags") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 [(Text, Natural)])))