Safe Haskell | None |
---|---|
Language | Haskell2010 |
Synopsis
- type PublicKey = G
- type SecretKey = E
- newtype Hash crypto c = Hash (E crypto c)
- hash :: CryptoParams crypto c => ByteString -> [G crypto c] -> E crypto c
- decodeBigEndian :: ByteString -> Natural
- newtype Base64SHA256 = Base64SHA256 Text
- base64SHA256 :: ByteString -> Base64SHA256
- newtype HexSHA256 = HexSHA256 Text
- hexSHA256 :: ByteString -> Text
- randomR :: Monad m => RandomGen r => Random i => Ring i => i -> StateT r m i
- random :: Monad m => RandomGen r => Random i => Bounded i => StateT r m i
- data Encryption crypto v c = Encryption {
- encryption_nonce :: !(G crypto c)
- encryption_vault :: !(G crypto c)
- type EncryptionNonce = E
- encrypt :: Reifies v Version => CryptoParams crypto c => Monad m => RandomGen r => PublicKey crypto c -> E crypto c -> StateT r m (EncryptionNonce crypto c, Encryption crypto v c)
- data Proof crypto v c = Proof {
- proof_challenge :: !(Challenge crypto c)
- proof_response :: !(E crypto c)
- newtype ZKP = ZKP ByteString
- type Challenge = E
- type Oracle list crypto c = list (Commitment crypto c) -> Challenge crypto c
- prove :: forall crypto v c list m r. Reifies v Version => CryptoParams 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)
- proveQuicker :: Reifies v Version => CryptoParams 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)
- fakeProof :: CryptoParams crypto c => Monad m => RandomGen r => StateT r m (Proof crypto v c)
- type Commitment = G
- commit :: forall crypto v c. Reifies v Version => CryptoParams crypto c => Proof crypto v c -> G crypto c -> G crypto c -> Commitment crypto c
- commitQuicker :: CryptoParams crypto c => Proof crypto v c -> G crypto c -> G crypto c -> Commitment crypto c
- type Disjunction = G
- booleanDisjunctions :: forall crypto c. CryptoParams crypto c => [Disjunction crypto c]
- intervalDisjunctions :: forall crypto c. CryptoParams crypto c => Natural -> Natural -> [Disjunction crypto c]
- newtype DisjProof crypto v c = DisjProof [Proof crypto v c]
- proveEncryption :: Reifies v Version => CryptoParams 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)
- verifyEncryption :: Reifies v Version => CryptoParams crypto c => Monad m => PublicKey crypto c -> ZKP -> [Disjunction crypto c] -> (Encryption crypto v c, DisjProof crypto v c) -> ExceptT ErrorVerifyEncryption m Bool
- encryptionStatement :: CryptoParams crypto c => ZKP -> Encryption crypto v c -> ByteString
- encryptionCommitments :: Reifies v Version => CryptoParams crypto c => PublicKey crypto c -> Encryption crypto v c -> Disjunction crypto c -> Proof crypto v c -> [G crypto c]
- data ErrorVerifyEncryption = ErrorVerifyEncryption_InvalidProofLength Natural Natural
- data Signature crypto v c = Signature {
- signature_publicKey :: !(PublicKey crypto c)
- signature_proof :: !(Proof crypto v c)
Type PublicKey
Type SecretKey
Type Hash
newtype Hash crypto c Source #
Instances
Eq (Hash crypto c) Source # | |
Ord (Hash crypto c) Source # | |
Defined in Voting.Protocol.Cryptography compare :: Hash crypto c -> Hash crypto c -> Ordering # (<) :: Hash crypto c -> Hash crypto c -> Bool # (<=) :: Hash crypto c -> Hash crypto c -> Bool # (>) :: Hash crypto c -> Hash crypto c -> Bool # (>=) :: Hash crypto c -> Hash crypto c -> Bool # | |
Show (Hash crypto c) Source # | |
NFData (Hash crypto c) Source # | |
Defined in Voting.Protocol.Cryptography |
hash :: CryptoParams crypto c => ByteString -> [G crypto c] -> E crypto c Source #
(
returns as a number in hash
bs gs)E
the SHA256
hash of the given ByteString
bs
prefixing the decimal representation of given subgroup elements gs
,
with a comma (",") intercalated between them.
NOTE: to avoid any collision when the hash
function is used in different contexts,
a message gs
is actually prefixed by a bs
indicating the context.
Used by proveEncryption
and verifyEncryption
,
where the bs
usually contains the statement
to be proven,
and the gs
contains the commitments
.
decodeBigEndian :: ByteString -> Natural Source #
(
interpret decodeBigEndian
bs)bs
as big-endian number.
Type Base64SHA256
newtype Base64SHA256 Source #
Instances
base64SHA256 :: ByteString -> Base64SHA256 Source #
(
returns the base64SHA256
bs)SHA256
hash
of the given ByteString
bs
,
as a Text
escaped in base64
encoding
(RFC 4648).
Type HexSHA256
Instances
Eq HexSHA256 Source # | |
Ord HexSHA256 Source # | |
Defined in Voting.Protocol.Cryptography | |
Show HexSHA256 Source # | |
Generic HexSHA256 Source # | |
ToJSON HexSHA256 Source # | |
Defined in Voting.Protocol.Cryptography | |
FromJSON HexSHA256 Source # | |
NFData HexSHA256 Source # | |
Defined in Voting.Protocol.Cryptography | |
type Rep HexSHA256 Source # | |
Defined in Voting.Protocol.Cryptography |
hexSHA256 :: ByteString -> Text Source #
(
returns the hexSHA256
bs)SHA256
hash
of the given ByteString
bs
, escaped in hexadecimal
into a Text
of 32 lowercase characters.
Used (in retro-dependencies of this library) to hash
the PublicKey
of a voter or a trustee.
Random
randomR :: Monad m => RandomGen r => Random i => Ring i => i -> StateT r m i Source #
(
returns a random integer in randomR
i)[0..i-1]
.
random :: Monad m => RandomGen r => Random i => Bounded i => StateT r m i Source #
(
returns a random integer
in the range determined by its type.random
)
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 (
to decipher encryption_nonce
^
secKey)(
, then the groupGen
^
clear)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 (
,
then: encryption_vault
*
encryption_nonce
==
encryption_nonce
^
(secKey +
clear))(logBase
.encryption_nonce
(encryption_vault
*
encryption_nonce
) ==
secKey +
clear)
Instances
Type EncryptionNonce
type EncryptionNonce = E Source #
encrypt :: Reifies v Version => CryptoParams crypto c => Monad m => RandomGen r => PublicKey crypto c -> E crypto c -> StateT r m (EncryptionNonce crypto c, Encryption crypto v c) Source #
(
returns an ElGamal-like encrypt
pubKey clear)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))
.
Proof | |
|
Instances
Eq (Proof crypto v c) Source # | |
Show (Proof crypto v c) Source # | |
Generic (Proof crypto v c) Source # | |
Reifies v Version => ToJSON (Proof crypto v c) Source # | |
Defined in Voting.Protocol.Cryptography | |
(CryptoParams crypto c, Reifies v Version) => FromJSON (Proof crypto v c) Source # | |
NFData (Proof crypto v c) Source # | |
Defined in Voting.Protocol.Cryptography | |
type Rep (Proof crypto v c) Source # | |
Defined in Voting.Protocol.Cryptography type Rep (Proof crypto v c) = D1 ('MetaData "Proof" "Voting.Protocol.Cryptography" "majurity-protocol-0.0.10.20191104-inplace" '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
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.
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 v Version => CryptoParams 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 #
(
returns a prove
sec commitmentBases oracle)Proof
that sec
is known
(by proving the knowledge of its discrete logarithm).
The Oracle
is given Commitment
s equal to the commitmentBases
raised to the power of the secret nonce of the Proof
,
as those are the Commitment
s 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 Proof
s using the same Commitment
can be used to deduce sec
(using the special-soundness).
proveQuicker :: Reifies v Version => CryptoParams 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 #
fakeProof :: CryptoParams crypto c => Monad m => RandomGen r => StateT r m (Proof crypto v c) Source #
(
returns a fakeProof
)Proof
whose proof_challenge
and proof_response
are uniformly chosen at random,
instead of (
and proof_challenge
==
hash
statement commitments)(
as a proof_response
==
nonce +
sec *
proof_challenge
)Proof
returned by prove
.
Used in proveEncryption
to fill the returned DisjProof
with fake Proof
s for all Disjunction
s but the encrypted one.
Type Commitment
type Commitment = G Source #
commit :: forall crypto v c. Reifies v Version => CryptoParams crypto c => Proof crypto v c -> G crypto c -> G crypto c -> Commitment crypto c Source #
(
returns a commit
proof base basePowSec)Commitment
from the given Proof
with the knowledge of the verifier.
commitQuicker :: CryptoParams crypto c => Proof crypto v c -> G crypto c -> G crypto c -> Commitment crypto c Source #
Type Disjunction
type Disjunction = G Source #
A Disjunction
is an inverse
d (
it's used in groupGen
^
opinion)proveEncryption
to generate a Proof
that an encryption_vault
contains a given (
,groupGen
^
opinion)
booleanDisjunctions :: forall crypto c. CryptoParams crypto c => [Disjunction crypto c] Source #
intervalDisjunctions :: forall crypto c. CryptoParams crypto c => Natural -> Natural -> [Disjunction crypto c] Source #
Type DisjProof
newtype DisjProof crypto v c Source #
A list of Proof
s to prove that the opinion within an Encryption
is indexing a Disjunction
within a list of them,
without revealing which opinion it is.
Instances
Eq (DisjProof crypto v c) Source # | |
Show (DisjProof crypto v c) Source # | |
Generic (DisjProof crypto v c) Source # | |
Reifies v Version => ToJSON (DisjProof crypto v c) Source # | |
Defined in Voting.Protocol.Cryptography | |
(Reifies v Version, CryptoParams crypto c) => FromJSON (DisjProof crypto v c) Source # | |
NFData (DisjProof crypto v c) Source # | |
Defined in Voting.Protocol.Cryptography | |
type Rep (DisjProof crypto v c) Source # | |
Defined in Voting.Protocol.Cryptography type Rep (DisjProof crypto v c) = D1 ('MetaData "DisjProof" "Voting.Protocol.Cryptography" "majurity-protocol-0.0.10.20191104-inplace" 'True) (C1 ('MetaCons "DisjProof" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 [Proof crypto v c]))) |
proveEncryption :: Reifies v Version => CryptoParams 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 #
(
returns a proveEncryption
elecPubKey voterZKP (prevDisjs,nextDisjs) (encNonce,enc))DisjProof
that enc
encrypt
s
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 => CryptoParams 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 :: CryptoParams crypto c => ZKP -> Encryption crypto v c -> ByteString Source #
encryptionCommitments :: Reifies v Version => CryptoParams crypto c => PublicKey crypto c -> Encryption crypto v c -> Disjunction crypto c -> Proof crypto v c -> [G crypto c] Source #
(
returns the encryptionCommitments
elecPubKey enc disj proof)Commitment
s 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
data ErrorVerifyEncryption Source #
Error raised by verifyEncryption
.
ErrorVerifyEncryption_InvalidProofLength Natural Natural | When the number of proofs is different than
the number of |
Instances
Eq ErrorVerifyEncryption Source # | |
Defined in Voting.Protocol.Cryptography (==) :: ErrorVerifyEncryption -> ErrorVerifyEncryption -> Bool # (/=) :: ErrorVerifyEncryption -> ErrorVerifyEncryption -> Bool # | |
Show ErrorVerifyEncryption Source # | |
Defined in Voting.Protocol.Cryptography showsPrec :: Int -> ErrorVerifyEncryption -> ShowS # show :: ErrorVerifyEncryption -> String # showList :: [ErrorVerifyEncryption] -> ShowS # |
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.
Signature | |
|
Instances
Generic (Signature crypto v c) Source # | |
(Reifies v Version, CryptoParams crypto c) => ToJSON (Signature crypto v c) Source # | |
Defined in Voting.Protocol.Cryptography | |
(Reifies v Version, CryptoParams crypto c) => FromJSON (Signature crypto v c) Source # | |
(NFData crypto, NFData (G crypto c)) => NFData (Signature crypto v c) Source # | |
Defined in Voting.Protocol.Cryptography | |
type Rep (Signature crypto v c) Source # | |
Defined in Voting.Protocol.Cryptography type Rep (Signature crypto v c) = D1 ('MetaData "Signature" "Voting.Protocol.Cryptography" "majurity-protocol-0.0.10.20191104-inplace" '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)))) |