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

Safe HaskellNone
LanguageHaskell2010

Protocol.Election

Contents

Synopsis

Type Encryption

data Encryption q 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 clear must be small to be decryptable, because it is encrypted as a power of groupGen to enable the additive homomorphism.

Constructors

Encryption 

Fields

Instances
Eq (Encryption q) Source # 
Instance details

Defined in Protocol.Election

Methods

(==) :: Encryption q -> Encryption q -> Bool #

(/=) :: Encryption q -> Encryption q -> Bool #

Show (Encryption q) Source # 
Instance details

Defined in Protocol.Election

SubGroup q => Additive (Encryption q) Source #

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

Instance details

Defined in Protocol.Election

Type EncryptionNonce

encrypt :: Monad m => RandomGen r => SubGroup q => PublicKey q -> E q -> StateT r m (EncryptionNonce q, Encryption q) 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 in prove, but this secret encNonce MUST be forgotten after that, as it may be used to decipher the Encryption without the secret key associated with pubKey.

Type Proof

data Proof q Source #

Proof of knowledge of a discrete logarithm: secret == logBase base (base^secret).

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

Constructors

Proof 

Fields

Instances
Eq (Proof q) Source # 
Instance details

Defined in Protocol.Election

Methods

(==) :: Proof q -> Proof q -> Bool #

(/=) :: Proof q -> Proof q -> Bool #

Show (Proof q) Source # 
Instance details

Defined in Protocol.Election

Methods

showsPrec :: Int -> Proof q -> ShowS #

show :: Proof q -> String #

showList :: [Proof q] -> ShowS #

Type Challenge

Type Oracle

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

prove :: Monad m => RandomGen r => SubGroup q => Functor list => E q -> list (Commitment q) -> Oracle list q -> StateT r m (Proof q) Source #

(prove sec commitments oracle) returns a Proof that sec is known.

The Oracle is given the commitments 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 (in encryptionCommitments).

NOTE: sec is secKey in signature_proof or encNonce in proveEncryption.

NOTE: The commitments are [groupGen] in signature_proof or [groupGen, pubKey] in proveEncryption.

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

NOTE: a random nonce is used to ensure each prove does not reveal any information regarding the secret sec.

Type Commitment

commit :: SubGroup q => Proof q -> G q -> G q -> Commitment q Source #

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

NOTE: Contrary to Helios-C specifications, (*) is used instead of (/) to avoid the performance cost of a modular exponentiation (^ (groupOrder - one)), this is compensated by using (-) instead of (+) in prove.

Type Opinion

type Opinion = E Source #

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

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),

Type DisjProof

newtype DisjProof q Source #

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

Constructors

DisjProof [Proof q] 
Instances
Eq (DisjProof q) Source # 
Instance details

Defined in Protocol.Election

Methods

(==) :: DisjProof q -> DisjProof q -> Bool #

(/=) :: DisjProof q -> DisjProof q -> Bool #

Show (DisjProof q) Source # 
Instance details

Defined in Protocol.Election

proveEncryption :: forall m r q. Monad m => RandomGen r => SubGroup q => PublicKey q -> ZKP -> [Disjunction q] -> Opinion q -> (EncryptionNonce q, Encryption q) -> StateT r (ExceptT ErrorProove m) (DisjProof q) Source #

(proveEncryption pubKey zkp disjs opin (encNonce, enc)) returns a DisjProof that enc encrypts one of the Disjunctions within disjs, without revealing which one it is.

A NIZK Disjunctive Chaum Pedersen Logarithm Equality is used.

encryptionCommitments :: SubGroup q => PublicKey q -> Encryption q -> (Disjunction q, Proof q) -> [G q] Source #

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

The Proof comes from prove of fakeProof in proveEncryption.

Type ZKP

newtype ZKP Source #

Zero-knowledge proof

Constructors

ZKP ByteString 

Type ErrorProove

data ErrorProove Source #

Error raised by proveEncryption.

Constructors

ErrorProove_InvalidOpinion Natural Natural

When the opinion is not within the number of Disjunctions.

Instances
Eq ErrorProove Source # 
Instance details

Defined in Protocol.Election

Show ErrorProove Source # 
Instance details

Defined in Protocol.Election

Type ErrorValidateEncryption

Type Question

data Question q Source #

Instances
Eq (Question q) Source # 
Instance details

Defined in Protocol.Election

Methods

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

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

Show (Question q) Source # 
Instance details

Defined in Protocol.Election

Methods

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

show :: Question q -> String #

showList :: [Question q] -> ShowS #

Type Answer

data Answer q Source #

Constructors

Answer 

Fields

Instances
Eq (Answer q) Source # 
Instance details

Defined in Protocol.Election

Methods

(==) :: Answer q -> Answer q -> Bool #

(/=) :: Answer q -> Answer q -> Bool #

Show (Answer q) Source # 
Instance details

Defined in Protocol.Election

Methods

showsPrec :: Int -> Answer q -> ShowS #

show :: Answer q -> String #

showList :: [Answer q] -> ShowS #

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 Protocol.Election

Show ErrorAnswer Source # 
Instance details

Defined in Protocol.Election

encryptAnswer :: Monad m => RandomGen r => SubGroup q => PublicKey q -> ZKP -> Question q -> [Bool] -> StateT r (ExceptT ErrorAnswer m) (Answer q) Source #

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

Type Election

data Election q Source #

Instances
Eq (Election q) Source # 
Instance details

Defined in Protocol.Election

Methods

(==) :: Election q -> Election q -> Bool #

(/=) :: Election q -> Election q -> Bool #

Show (Election q) Source # 
Instance details

Defined in Protocol.Election

Methods

showsPrec :: Int -> Election q -> ShowS #

show :: Election q -> String #

showList :: [Election q] -> ShowS #

Type Hash

newtype Hash Source #

Constructors

Hash Text 
Instances
Eq Hash Source # 
Instance details

Defined in Protocol.Election

Methods

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

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

Ord Hash Source # 
Instance details

Defined in Protocol.Election

Methods

compare :: Hash -> Hash -> Ordering #

(<) :: Hash -> Hash -> Bool #

(<=) :: Hash -> Hash -> Bool #

(>) :: Hash -> Hash -> Bool #

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

max :: Hash -> Hash -> Hash #

min :: Hash -> Hash -> Hash #

Show Hash Source # 
Instance details

Defined in Protocol.Election

Methods

showsPrec :: Int -> Hash -> ShowS #

show :: Hash -> String #

showList :: [Hash] -> ShowS #

Type Ballot

encryptBallot :: Monad m => RandomGen r => SubGroup q => Election q -> Maybe (SecretKey q) -> [[Bool]] -> StateT r (ExceptT ErrorBallot m) (Ballot q) Source #

(encryptBallot elec (Just secKey) 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.

Type Signature

data Signature q Source #

Schnorr-like signature.

Used to avoid Ballot stuffing.

signatureStatement :: Foldable f => SubGroup q => f (Answer q) -> [G q] Source #

(signatureStatement answers) returns all the encryption_nonces and encryption_vaults of the given answers.

signatureCommitments :: SubGroup q => ZKP -> Commitment q -> ByteString Source #

(signatureCommitments zkp commitment) returns the hashable content from the knowledge of the verifier.

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.

Instances
Eq ErrorBallot Source # 
Instance details

Defined in Protocol.Election

Show ErrorBallot Source # 
Instance details

Defined in Protocol.Election