Struct chain_vote::tally::EncryptedTally
source · pub struct EncryptedTally {
r: Vec<Ciphertext>,
fingerprint: ElectionFingerprint,
max_stake: u64,
}
Expand description
EncryptedTally
is formed by one ciphertext per existing option and a fingerprint that
identifies the election parameters used (crs and election public key)
Fields§
§r: Vec<Ciphertext>
§fingerprint: ElectionFingerprint
§max_stake: u64
Implementations§
source§impl EncryptedTally
impl EncryptedTally
const MAX_STAKE_BYTES_LEN: usize = 8usize
sourcepub fn new(options: usize, election_pk: ElectionPublicKey, crs: Crs) -> Self
pub fn new(options: usize, election_pk: ElectionPublicKey, crs: Crs) -> Self
Initialise a new tally with N different options. The EncryptedTally
is computed using
the additive homomorphic property of the elgamal Ciphertext
s, and is therefore initialised
with zero ciphertexts.
sourcepub fn add(&mut self, ballot: &Ballot, weight: u64)
pub fn add(&mut self, ballot: &Ballot, weight: u64)
Add a submitted ballot
, with a specific weight
to the tally.
Remember that a vote is only valid for a specific election (i.e. pair of
election public key and crs), and trying to add a ballot validated for a
different one will result in a panic.
Note that the encrypted vote needs to have the exact same number of options as the initialised tally, otherwise an assert will trigger.
sourcepub fn partial_decrypt<R: RngCore + CryptoRng>(
&self,
rng: &mut R,
secret_key: &OpeningVoteKey
) -> TallyDecryptShare
pub fn partial_decrypt<R: RngCore + CryptoRng>( &self, rng: &mut R, secret_key: &OpeningVoteKey ) -> TallyDecryptShare
Given a single committee member’s secret_key
, returns a partial decryption of
the EncryptedTally
sourcepub fn validate_partial_decryptions(
&self,
pks: &[MemberPublicKey],
decrypt_shares: &[TallyDecryptShare]
) -> Result<ValidatedTally, DecryptionError>
pub fn validate_partial_decryptions( &self, pks: &[MemberPublicKey], decrypt_shares: &[TallyDecryptShare] ) -> Result<ValidatedTally, DecryptionError>
Given the members pks
, and their corresponding decrypte_shares
, this function validates
the different shares, and returns a ValidatedTally
, or a DecryptionError
.
sourcepub fn to_bytes(&self) -> Vec<u8>
pub fn to_bytes(&self) -> Vec<u8>
Returns a byte array with every ciphertext in the EncryptedTally
sourcepub fn from_bytes(bytes: &[u8]) -> Option<Self>
pub fn from_bytes(bytes: &[u8]) -> Option<Self>
Tries to generate an EncryptedTally
out of an array of bytes. Returns None
if the
size of the byte array is not a multiply of Ciphertext::BYTES_LEN
.
Trait Implementations§
source§impl Add<EncryptedTally> for EncryptedTally
impl Add<EncryptedTally> for EncryptedTally
source§impl Clone for EncryptedTally
impl Clone for EncryptedTally
source§fn clone(&self) -> EncryptedTally
fn clone(&self) -> EncryptedTally
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl Debug for EncryptedTally
impl Debug for EncryptedTally
source§impl PartialEq<EncryptedTally> for EncryptedTally
impl PartialEq<EncryptedTally> for EncryptedTally
source§fn eq(&self, other: &EncryptedTally) -> bool
fn eq(&self, other: &EncryptedTally) -> bool
self
and other
values to be equal, and is used
by ==
.