server.hpp 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. #ifndef __PRSONA_SERVER_HPP
  2. #define __PRSONA_SERVER_HPP
  3. #include <vector>
  4. #include "BGN.hpp"
  5. #include "Curvepoint.hpp"
  6. #include "Bipoint.hpp"
  7. #include "base.hpp"
  8. #include "EGCiphertext.hpp"
  9. #include "proof.hpp"
  10. class PrsonaServer : public PrsonaBase {
  11. public:
  12. // CONSTRUCTORS
  13. PrsonaServer(size_t numServers);
  14. PrsonaServer(size_t numServers, const BGN& other_bgn);
  15. // BASIC PUBLIC SYSTEM INFO GETTERS
  16. BGNPublicKey get_bgn_public_key() const;
  17. size_t get_num_clients() const;
  18. size_t get_num_servers() const;
  19. // FRESH GENERATOR CALCULATION
  20. Curvepoint add_curr_seed_to_generator(
  21. std::vector<Proof>& pi,
  22. const Curvepoint& currGenerator) const;
  23. Curvepoint add_next_seed_to_generator(
  24. std::vector<Proof>& pi,
  25. const Curvepoint& currGenerator) const;
  26. // ENCRYPTED DATA GETTERS
  27. std::vector<CurveBipoint> get_current_votes_by(
  28. Proof& pi, const Curvepoint& shortTermPublicKey) const;
  29. std::vector<std::vector<CurveBipoint>> get_all_current_votes(
  30. Proof& pi) const;
  31. EGCiphertext get_current_user_encrypted_tally(
  32. Proof& pi, const Curvepoint& shortTermPublicKey) const;
  33. TwistBipoint get_current_server_encrypted_tally(
  34. Proof& pi, const Curvepoint& shortTermPublicKey) const;
  35. std::vector<Curvepoint> get_current_pseudonyms(Proof& pi) const;
  36. // PROOF COMMITMENT GETTERS
  37. Proof get_vote_row_commitment(const Curvepoint& request) const;
  38. Proof get_vote_matrix_commitment() const;
  39. Proof get_user_tally_commitment(const Curvepoint& request) const;
  40. Proof get_server_tally_commitment(const Curvepoint& request) const;
  41. Proof get_pseudonyms_commitment() const;
  42. // CLIENT INTERACTIONS
  43. void add_new_client(
  44. std::vector<Proof>& proofOfValidAddition,
  45. const Proof& proofOfValidKey,
  46. const Curvepoint& shortTermPublicKey);
  47. bool receive_vote(
  48. const std::vector<Proof>& pi,
  49. const std::vector<CurveBipoint>& newVotes,
  50. const Curvepoint& shortTermPublicKey);
  51. private:
  52. // constants for servers
  53. const size_t numServers;
  54. // Identical between all servers (but collaboratively constructed)
  55. BGN bgnSystem;
  56. // Private; different for each server
  57. Scalar currentSeed;
  58. Scalar nextSeed;
  59. // The actual data, which is collaboratively updated by all servers
  60. Curvepoint currentFreshGenerator;
  61. std::vector<TwistBipoint> previousVoteTallies;
  62. std::vector<Curvepoint> currentPseudonyms;
  63. std::vector<EGCiphertext> currentUserEncryptedTallies;
  64. std::vector<std::vector<CurveBipoint>> voteMatrix;
  65. /**
  66. * NOTE: voteMatrix structure:
  67. * Each element represents a vote by <rowID> applied to <colID>.
  68. * The outer vector is a vector of rows and the inner vector is
  69. * a vector of encrypted votes.
  70. */
  71. // An imaginary class; it's just used right now to coordinate servers
  72. // in memory instead of via network action.
  73. friend class PrsonaServerEntity;
  74. // CONSTRUCTOR HELPERS
  75. const BGN& get_bgn_details() const;
  76. bool initialize_fresh_generator(
  77. const std::vector<Proof>& pi,
  78. const Curvepoint& firstGenerator);
  79. Curvepoint add_rand_seed_to_generator(
  80. std::vector<Proof>& pi,
  81. const Curvepoint& currGenerator) const;
  82. bool set_EG_blind_generator(
  83. const std::vector<Proof>& pi,
  84. const Curvepoint& currGenerator);
  85. // SCORE TALLYING
  86. std::vector<Scalar> tally_scores();
  87. Scalar get_max_possible_score(Proof& pi);
  88. // EPOCH ROUNDS
  89. void build_up_midway_pseudonyms(
  90. Proof& pi, Curvepoint& nextGenerator);
  91. void break_down_midway_pseudonyms(
  92. Proof& pi, const Curvepoint& nextGenerator);
  93. // DATA MAINTENANCE
  94. bool import_new_user_update(
  95. const std::vector<Proof>& pi,
  96. const std::vector<TwistBipoint>& otherPreviousVoteTallies,
  97. const std::vector<Curvepoint>& otherCurrentPseudonyms,
  98. const std::vector<EGCiphertext>& otherCurrentUserEncryptedTallies,
  99. const std::vector<std::vector<CurveBipoint>>& otherVoteMatrix
  100. );
  101. void import_updates(
  102. const Proof& pi,
  103. const std::vector<TwistBipoint>& otherPreviousVoteTallies,
  104. const std::vector<Curvepoint>& otherCurrentPseudonyms,
  105. const std::vector<EGCiphertext>& otherCurrentUserEncryptedTallies,
  106. const std::vector<std::vector<CurveBipoint>>& otherVoteMatrix
  107. );
  108. void export_updates(
  109. std::vector<TwistBipoint>& otherPreviousVoteTally,
  110. std::vector<Curvepoint>& otherCurrentPseudonyms,
  111. std::vector<EGCiphertext>& otherCurrentUserEncryptedTallies,
  112. std::vector<std::vector<CurveBipoint>>& otherVoteMatrix
  113. ) const;
  114. // DATA SAFEKEEPING
  115. void rerandomize_data();
  116. std::vector<size_t> order_data(Proof& pi);
  117. // A helper class for "ordering" data and for binary search
  118. struct SortingType {
  119. Curvepoint pseudonym;
  120. size_t index;
  121. bool operator<( const SortingType& rhs ) const
  122. { return pseudonym < rhs.pseudonym; }
  123. };
  124. // BINARY SEARCH
  125. size_t binary_search(const Curvepoint& index) const;
  126. // VALID VOTE PROOFS
  127. bool verify_vote_proof(
  128. const std::vector<Proof>& pi,
  129. const std::vector<CurveBipoint>& oldVotes,
  130. const std::vector<CurveBipoint>& newVotes,
  131. const Curvepoint& shortTermPublicKey
  132. ) const;
  133. };
  134. #endif