123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291 |
- #ifndef __PRSONA_SERVER_HPP
- #define __PRSONA_SERVER_HPP
- #include <vector>
- #include "BGN.hpp"
- #include "Curvepoint.hpp"
- #include "Bipoint.hpp"
- #include "base.hpp"
- #include "EGCiphertext.hpp"
- #include "proof.hpp"
- class PrsonaServer : public PrsonaBase {
- public:
- // CONSTRUCTORS
- PrsonaServer(size_t numServers);
- PrsonaServer(size_t numServers, const BGN& other_bgn);
- // BASIC PUBLIC SYSTEM INFO GETTERS
- BGNPublicKey get_bgn_public_key() const;
- size_t get_num_clients() const;
- size_t get_num_servers() const;
-
- // FRESH GENERATOR CALCULATION
- Curvepoint add_curr_seed_to_generator(
- std::vector<Proof>& pi,
- const Curvepoint& currGenerator) const;
- Curvepoint add_next_seed_to_generator(
- std::vector<Proof>& pi,
- const Curvepoint& currGenerator) const;
- // ENCRYPTED DATA GETTERS
- std::vector<CurveBipoint> get_current_votes_by(
- Proof& pi, const Curvepoint& shortTermPublicKey) const;
- std::vector<std::vector<CurveBipoint>> get_all_current_votes(
- Proof& pi) const;
- EGCiphertext get_current_user_encrypted_tally(
- Proof& pi, const Curvepoint& shortTermPublicKey) const;
- TwistBipoint get_current_server_encrypted_tally(
- Proof& pi, const Curvepoint& shortTermPublicKey) const;
- std::vector<Curvepoint> get_current_pseudonyms(Proof& pi) const;
- // PROOF COMMITMENT GETTERS
- Proof get_vote_row_commitment(const Curvepoint& request) const;
- Proof get_vote_matrix_commitment() const;
- Proof get_user_tally_commitment(const Curvepoint& request) const;
- Proof get_server_tally_commitment(const Curvepoint& request) const;
- Proof get_pseudonyms_commitment() const;
- // CLIENT INTERACTIONS
- void add_new_client(
- std::vector<Proof>& proofOfValidAddition,
- const Proof& proofOfValidKey,
- const Curvepoint& shortTermPublicKey);
- bool receive_vote(
- const std::vector<Proof>& pi,
- const std::vector<CurveBipoint>& newVotes,
- const Curvepoint& shortTermPublicKey);
- void print_scores(const std::vector<TwistBipoint>& scores);
- private:
- // constants for servers
- const size_t numServers;
- // Identical between all servers (but collaboratively constructed)
- BGN bgnSystem;
- // Private; different for each server
- Scalar currentSeed;
- Scalar nextSeed;
- // The actual data, which is collaboratively updated by all servers
- Curvepoint currentFreshGenerator;
- std::vector<TwistBipoint> previousVoteTallies;
- std::vector<Curvepoint> currentPseudonyms;
- std::vector<EGCiphertext> currentUserEncryptedTallies;
- std::vector<std::vector<CurveBipoint>> voteMatrix;
- /**
- * NOTE: voteMatrix structure:
- * Each element represents a vote by <rowID> applied to <colID>.
- * The outer vector is a vector of rows and the inner vector is
- * a vector of encrypted votes.
- */
- // An imaginary class; it's just used right now to coordinate servers
- // in memory instead of via network action.
- friend class PrsonaServerEntity;
- // CONSTRUCTOR HELPERS
- const BGN& get_bgn_details() const;
- bool initialize_fresh_generator(
- const std::vector<Proof>& pi,
- const Curvepoint& firstGenerator);
- Curvepoint add_rand_seed_to_generator(
- std::vector<Proof>& pi,
- const Curvepoint& currGenerator) const;
- bool set_EG_blind_generator(
- const std::vector<Proof>& pi,
- const Curvepoint& currGenerator);
-
- // SCORE TALLYING
- std::vector<Scalar> tally_scores();
- Scalar get_max_possible_score();
-
- // EPOCH ROUNDS
- void build_up_midway_pseudonyms(
- std::vector<std::vector<std::vector<Proof>>>& pi,
- std::vector<std::vector<std::vector<Curvepoint>>>& permutationCommits,
- std::vector<std::vector<std::vector<Curvepoint>>>& freshPseudonymCommits,
- std::vector<std::vector<std::vector<Curvepoint>>>& freshPseudonymSeedCommits,
- std::vector<std::vector<std::vector<TwistBipoint>>>& serverTallyCommits,
- std::vector<std::vector<std::vector<std::vector<std::vector<CurveBipoint>>>>>& voteMatrixCommits,
- Curvepoint& nextGenerator);
- void break_down_midway_pseudonyms(
- std::vector<Proof>& generatorProof,
- std::vector<std::vector<std::vector<Proof>>>& pi,
- std::vector<std::vector<std::vector<Curvepoint>>>& permutationCommits,
- std::vector<std::vector<std::vector<Curvepoint>>>& freshPseudonymCommits,
- std::vector<std::vector<std::vector<Curvepoint>>>& freshPseudonymSeedCommits,
- std::vector<std::vector<std::vector<TwistBipoint>>>& serverTallyCommits,
- std::vector<std::vector<std::vector<std::vector<std::vector<CurveBipoint>>>>>& voteMatrixCommits,
- std::vector<std::vector<std::vector<std::vector<Curvepoint>>>>& userTallyCommits,
- std::vector<std::vector<std::vector<Curvepoint>>>& userTallyMaskSeedCommits,
- const Curvepoint& nextGenerator);
- // EPOCH HELPERS
- std::vector<std::vector<Proof>> epoch_calculations(
- std::vector<std::vector<Curvepoint>>& permutationCommits,
- std::vector<std::vector<Curvepoint>>& freshPseudonymCommits,
- std::vector<std::vector<Curvepoint>>& freshPseudonymSeedCommits,
- std::vector<std::vector<TwistBipoint>>& serverTallyCommits,
- std::vector<std::vector<std::vector<std::vector<CurveBipoint>>>>& voteMatrixCommits,
- std::vector<std::vector<std::vector<Curvepoint>>>& userTallyCommits,
- std::vector<std::vector<Curvepoint>> & userTallyMaskSeedCommits,
- const Scalar& power,
- bool doUserTallies);
- bool accept_epoch_updates(
- const std::vector<std::vector<Proof>>& pi,
- const std::vector<std::vector<Curvepoint>>& permutationCommits,
- const std::vector<std::vector<Curvepoint>>& freshPseudonymCommits,
- const std::vector<std::vector<Curvepoint>>& freshPseudonymSeedCommits,
- const std::vector<std::vector<TwistBipoint>>& serverTallyCommits,
- const std::vector<std::vector<std::vector<std::vector<CurveBipoint>>>>& voteMatrixCommits,
- const std::vector<std::vector<std::vector<Curvepoint>>>& userTallyCommits,
- const std::vector<std::vector<Curvepoint>>& userTallyMaskSeedCommits,
- bool doUserTallies);
- std::vector<std::vector<Scalar>> generate_permutation_matrix(
- const Scalar& reorderSeed
- ) const;
- std::vector<std::vector<Curvepoint>> generate_commitment_matrix(
- const std::vector<std::vector<Scalar>>& permutations,
- std::vector<std::vector<Scalar>>& seeds
- ) const;
- std::vector<std::vector<Curvepoint>> generate_pseudonym_matrix(
- const std::vector<std::vector<Scalar>>& permutations,
- const Scalar& power,
- std::vector<std::vector<Scalar>>& seeds,
- std::vector<std::vector<Curvepoint>>& seedCommits
- ) const;
- std::vector<std::vector<TwistBipoint>> generate_server_tally_matrix(
- const std::vector<std::vector<Scalar>>& permutations,
- std::vector<std::vector<Scalar>>& seeds
- ) const;
- std::vector<std::vector<std::vector<CurveBipoint>>> generate_vote_tensor(
- const std::vector<std::vector<Scalar>>& permutations,
- const std::vector<std::vector<CurveBipoint>>& currVoteMatrix,
- std::vector<std::vector<std::vector<Scalar>>>& seeds,
- bool inverted
- ) const;
- std::vector<std::vector<CurveBipoint>> calculate_next_vote_matrix(
- const std::vector<std::vector<std::vector<CurveBipoint>>>& voteTensor
- ) const;
- void generate_vote_tensor_proofs(
- std::vector<std::vector<Proof>>& pi,
- const std::vector<std::vector<Scalar>>& permutations,
- const std::vector<std::vector<Scalar>>& permutationSeeds,
- const std::vector<std::vector<std::vector<Scalar>>>& matrixSeeds,
- const std::vector<std::vector<CurveBipoint>>& currMatrix,
- const std::vector<std::vector<Curvepoint>>& permutationCommits,
- const std::vector<std::vector<std::vector<CurveBipoint>>>& matrixCommits,
- bool inverted
- ) const;
- bool verify_vote_tensor_proofs(
- const std::vector<std::vector<Proof>>& pi,
- size_t start_offset,
- const std::vector<std::vector<CurveBipoint>>& currMatrix,
- const std::vector<std::vector<Curvepoint>>& permutationCommits,
- const std::vector<std::vector<std::vector<CurveBipoint>>>& matrixCommits,
- bool inverted
- ) const;
- std::vector<std::vector<std::vector<Curvepoint>>> generate_user_tally_matrix(
- const std::vector<std::vector<Scalar>>& permutations,
- const Scalar& power,
- std::vector<Curvepoint>& masks,
- std::vector<Curvepoint>& messages,
- std::vector<std::vector<Scalar>>& maskSeeds,
- std::vector<std::vector<Curvepoint>>& maskSeedCommits,
- std::vector<std::vector<Scalar>>& messageSeeds
- ) const;
- template <typename T>
- std::vector<std::vector<T>> generate_reordered_plus_power_matrix(
- const std::vector<std::vector<Scalar>>& permutations,
- const Scalar& power,
- const std::vector<T>& oldValues,
- std::vector<std::vector<Scalar>>& seeds,
- std::vector<std::vector<Curvepoint>>& seedCommits,
- const T& h
- ) const;
- template <typename T>
- std::vector<std::vector<T>> generate_reordered_matrix(
- const std::vector<std::vector<Scalar>>& permutations,
- const std::vector<T>& oldValues,
- std::vector<std::vector<Scalar>>& seeds,
- const T& h,
- bool inverted,
- bool cancelOut
- ) const;
- template <typename T>
- std::vector<std::vector<T>> transpose_matrix(
- const std::vector<std::vector<T>>& input
- ) const;
- std::vector<size_t> sort_data(
- const std::vector<Curvepoint>& inputs
- ) const;
- // A helper class for "ordering" data and for binary search
- struct SortingType {
- Curvepoint pseudonym;
- size_t index;
- bool operator<( const SortingType& rhs ) const
- { return pseudonym < rhs.pseudonym; }
- };
- template <typename T>
- T encrypt(
- const T& g,
- const T& h,
- const Scalar& plaintext,
- const Scalar& lambda
- ) const;
- bool update_data(
- const std::vector<std::vector<Curvepoint>>& freshPseudonymCommits,
- const std::vector<std::vector<TwistBipoint>>& serverTallyCommits,
- const std::vector<std::vector<std::vector<CurveBipoint>>>& voteMatrixCommits,
- const std::vector<std::vector<std::vector<Curvepoint>>>& userTallyCommits);
- bool pseudonyms_sorted(
- const std::vector<Curvepoint> newPseudonyms
- ) const;
- // DATA MAINTENANCE
- bool import_new_user_update(
- const std::vector<Proof>& pi,
- const std::vector<TwistBipoint>& otherPreviousVoteTallies,
- const std::vector<Curvepoint>& otherCurrentPseudonyms,
- const std::vector<EGCiphertext>& otherCurrentUserEncryptedTallies,
- const std::vector<std::vector<CurveBipoint>>& otherVoteMatrix);
- // DATA SAFEKEEPING
- std::vector<size_t> order_data();
-
- // BINARY SEARCH
- size_t binary_search(const Curvepoint& index) const;
- // VALID VOTE PROOFS
- bool verify_vote_proof(
- const std::vector<Proof>& pi,
- const std::vector<CurveBipoint>& oldVotes,
- const std::vector<CurveBipoint>& newVotes,
- const Curvepoint& shortTermPublicKey
- ) const;
- };
- #endif
|