123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183 |
- #ifndef __PRSONA_SERVER_HPP
- #define __PRSONA_SERVER_HPP
- #include <vector>
- #include "BGN.hpp"
- #include "Curvepoint.hpp"
- #include "Bipoint.hpp"
- #include "EGCiphertext.hpp"
- #include "proof.hpp"
- class PrsonaServer {
- public:
- // CONSTRUCTORS
- PrsonaServer();
- PrsonaServer(const BGN& other_bgn);
- // SETUP FUNCTIONS
- static void init();
- static void set_server_malicious();
- static void set_client_malicious();
- // BASIC PUBLIC SYSTEM INFO GETTERS
- Curvepoint get_blinding_generator() const;
- BGNPublicKey get_bgn_public_key() const;
-
- // FRESH GENERATOR CALCULATION
- Curvepoint add_curr_seed_to_generator(
- const Curvepoint& currGenerator) const;
- Curvepoint add_next_seed_to_generator(
- const Curvepoint& currGenerator) const;
- // ENCRYPTED DATA GETTERS
- std::vector<CurveBipoint> get_current_votes_by(
- Proof& pi, const Curvepoint& shortTermPublicKey) const;
- EGCiphertext get_current_tally(
- Proof& pi, const Curvepoint& shortTermPublicKey) const;
- // CLIENT INTERACTIONS
- void add_new_client(
- const Proof& proofOfValidKey,
- Proof& proofOfValidAddition,
- const Curvepoint& shortTermPublicKey);
- bool receive_vote(
- const std::vector<Proof>& pi,
- const std::vector<CurveBipoint>& newVotes,
- const Curvepoint& shortTermPublicKey);
- private:
- // Constants for servers
- static Curvepoint EL_GAMAL_GENERATOR;
- static Scalar SCALAR_N;
- static Scalar DEFAULT_TALLY;
- static Scalar DEFAULT_VOTE;
- static bool SERVER_IS_MALICIOUS;
- static bool CLIENT_IS_MALICIOUS;
- // Identical between all servers (but collaboratively constructed)
- BGN bgn_system;
- Curvepoint elGamalBlindGenerator;
- // 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<Proof> currentTallyProofs;
- 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;
- void initialize_fresh_generator(const Curvepoint& firstGenerator);
- Curvepoint add_rand_seed_to_generator(
- const Curvepoint& currGenerator) const;
- void set_EG_blind_generator(const Curvepoint& currGenerator);
-
- // SCORE TALLYING
- std::vector<Scalar> tally_scores(std::vector<Proof>& tallyProofs);
- Scalar get_max_possible_score(Proof& pi);
-
- // EPOCH ROUNDS
- void build_up_midway_pseudonyms(
- Proof& pi, Curvepoint& nextGenerator);
- void break_down_midway_pseudonyms(
- Proof& pi, const Curvepoint& nextGenerator);
- // DATA MAINTENANCE
- void import_updates(
- const Proof& pi,
- const std::vector<TwistBipoint>& otherPreviousVoteTally,
- const std::vector<Curvepoint>& otherCurrentPseudonyms,
- const std::vector<EGCiphertext>& otherCurrentUserEncryptedTallies,
- const std::vector<Proof>& otherCurrentTallyProofs,
- const std::vector<std::vector<CurveBipoint>>& otherVoteMatrix
- );
- void export_updates(
- std::vector<TwistBipoint>& otherPreviousVoteTally,
- std::vector<Curvepoint>& otherCurrentPseudonyms,
- std::vector<EGCiphertext>& otherCurrentUserEncryptedTallies,
- std::vector<Proof>& otherCurrentTallyProofs,
- std::vector<std::vector<CurveBipoint>>& otherVoteMatrix
- ) const;
- // DATA SAFEKEEPING
- void rerandomize_data();
- std::vector<size_t> order_data(Proof& pi);
- // 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; }
- };
-
- // BINARY SEARCH
- size_t binary_search(const Curvepoint& index) const;
- // CLIENT PROOF VERIFICATION
- bool verify_ownership_proof(
- const Proof& pi,
- const Curvepoint& shortTermPublicKey
- ) const;
- bool verify_vote_proof(
- const std::vector<Proof>& pi,
- const std::vector<CurveBipoint>& oldVotes,
- const std::vector<CurveBipoint>& newVotes,
- const Curvepoint& shortTermPublicKey
- ) const;
- // SERVER PROOF VERIFICATION
- bool verify_update_proof(
- const Proof& pi
- ) const;
- // PROOF GENERATION
- Proof generate_valid_default_tally_proof(
- const EGCiphertext& newUserEncryptedTally,
- const Scalar& mask
- ) const;
- Proof generate_valid_fresh_generator_proof(
- const Proof& pi
- ) const;
- Proof generate_votes_valid_proof(
- const std::vector<CurveBipoint>& votes,
- const Curvepoint& voter
- ) const;
- Proof generate_proof_of_added_user(
- const Curvepoint& shortTermPublicKey
- ) const;
- Proof generate_score_proof(
- const EGCiphertext& score
- ) const;
- Proof generate_proof_of_correct_tally(
- const Quadripoint& BGNEncryptedTally,
- const Scalar& decryptedTally
- ) const;
- Proof generate_proof_of_correct_sum(
- const TwistBipoint& BGNEncryptedSum,
- const Scalar& decryptedSum
- ) const;
- Proof generate_proof_of_shuffle(
- const std::vector<size_t>& shuffle_order
- ) const;
- };
- #endif
|