#ifndef __PRSONA_SERVER_HPP #define __PRSONA_SERVER_HPP #include #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 Curvepoint init(); static void set_server_malicious(); static void set_client_malicious(); // BASIC PUBLIC SYSTEM INFO GETTERS static Curvepoint get_blinding_generator(); 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 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); void receive_vote( const Proof& pi, const std::vector& votes, const Curvepoint& shortTermPublicKey); private: // Constants for servers static Curvepoint EL_GAMAL_GENERATOR; static Curvepoint EL_GAMAL_BLIND_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 BGN bgn_system; // 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 currentTallyProofs; 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; void initialize_fresh_generator(const Curvepoint& firstGenerator); // SCORE TALLYING std::vector tally_scores(std::vector& 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& otherPreviousVoteTally, const std::vector& otherCurrentPseudonyms, const std::vector& otherCurrentUserEncryptedTallies, const std::vector& otherCurrentTallyProofs, const std::vector>& otherVoteMatrix ); void export_updates( std::vector& otherPreviousVoteTally, std::vector& otherCurrentPseudonyms, std::vector& otherCurrentUserEncryptedTallies, std::vector& otherCurrentTallyProofs, 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; // PROOF VERIFICATION bool verify_valid_key_proof( const Proof& pi, const Curvepoint& shortTermPublicKey ) const; bool verify_vote_proof( const Proof& pi, const std::vector& votes, const Curvepoint& shortTermPublicKey ) const; 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& 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& shuffle_order ) const; }; #endif