#ifndef __PRSONA_SERVER_HPP #define __PRSONA_SERVER_HPP #include #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& pi, const Curvepoint& currGenerator) const; Curvepoint add_next_seed_to_generator( std::vector& pi, const Curvepoint& currGenerator) const; // ENCRYPTED DATA GETTERS std::vector get_current_votes_by( Proof& pi, const Curvepoint& shortTermPublicKey) const; std::vector> 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 get_current_pseudonyms(Proof& pi) const; // CLIENT INTERACTIONS void add_new_client( std::vector& proofOfValidAddition, const Proof& proofOfValidKey, const Curvepoint& shortTermPublicKey); bool receive_vote( const std::vector& pi, const std::vector& newVotes, const Curvepoint& shortTermPublicKey); 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 previousVoteTallies; std::vector currentPseudonyms; std::vector currentUserEncryptedTallies; std::vector> voteMatrix; /** * NOTE: voteMatrix structure: * Each element represents a vote by applied to . * 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& pi, const Curvepoint& firstGenerator); Curvepoint add_rand_seed_to_generator( std::vector& pi, const Curvepoint& currGenerator) const; bool set_EG_blind_generator( const std::vector& pi, const Curvepoint& currGenerator); // SCORE TALLYING std::vector tally_scores(); 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& otherPreviousVoteTally, const std::vector& otherCurrentPseudonyms, const std::vector& otherCurrentUserEncryptedTallies, const std::vector>& otherVoteMatrix ); void export_updates( std::vector& otherPreviousVoteTally, std::vector& otherCurrentPseudonyms, std::vector& otherCurrentUserEncryptedTallies, std::vector>& otherVoteMatrix ) const; // DATA SAFEKEEPING void rerandomize_data(); std::vector 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; // VALID VOTE PROOFS bool verify_vote_proof( const std::vector& pi, const std::vector& oldVotes, const std::vector& newVotes, const Curvepoint& shortTermPublicKey ) const; }; #endif