server.hpp 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  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 "EGCiphertext.hpp"
  8. #include "proof.hpp"
  9. class PrsonaServer {
  10. public:
  11. // CONSTRUCTORS
  12. PrsonaServer();
  13. PrsonaServer(const BGN& other_bgn);
  14. // SETUP FUNCTIONS
  15. static void init();
  16. static void set_server_malicious();
  17. static void set_client_malicious();
  18. // BASIC PUBLIC SYSTEM INFO GETTERS
  19. Curvepoint get_blinding_generator() const;
  20. BGNPublicKey get_bgn_public_key() const;
  21. // FRESH GENERATOR CALCULATION
  22. Curvepoint add_curr_seed_to_generator(
  23. const Curvepoint& currGenerator) const;
  24. Curvepoint add_next_seed_to_generator(
  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. EGCiphertext get_current_tally(
  30. Proof& pi, const Curvepoint& shortTermPublicKey) const;
  31. // CLIENT INTERACTIONS
  32. void add_new_client(
  33. const Proof& proofOfValidKey,
  34. Proof& proofOfValidAddition,
  35. const Curvepoint& shortTermPublicKey);
  36. bool receive_vote(
  37. const std::vector<Proof>& pi,
  38. const std::vector<CurveBipoint>& newVotes,
  39. const Curvepoint& shortTermPublicKey);
  40. private:
  41. // Constants for servers
  42. static Curvepoint EL_GAMAL_GENERATOR;
  43. static Scalar SCALAR_N;
  44. static Scalar DEFAULT_TALLY;
  45. static Scalar DEFAULT_VOTE;
  46. static bool SERVER_IS_MALICIOUS;
  47. static bool CLIENT_IS_MALICIOUS;
  48. // Identical between all servers (but collaboratively constructed)
  49. BGN bgn_system;
  50. Curvepoint elGamalBlindGenerator;
  51. // Private; different for each server
  52. Scalar currentSeed;
  53. Scalar nextSeed;
  54. // The actual data, which is collaboratively updated by all servers
  55. Curvepoint currentFreshGenerator;
  56. std::vector<TwistBipoint> previousVoteTallies;
  57. std::vector<Curvepoint> currentPseudonyms;
  58. std::vector<EGCiphertext> currentUserEncryptedTallies;
  59. std::vector<Proof> currentTallyProofs;
  60. std::vector<std::vector<CurveBipoint>> voteMatrix;
  61. /**
  62. * NOTE: voteMatrix structure:
  63. * Each element represents a vote by <rowID> applied to <colID>.
  64. * The outer vector is a vector of rows and the inner vector is
  65. * a vector of encrypted votes.
  66. */
  67. // An imaginary class; it's just used right now to coordinate servers
  68. // in memory instead of via network action.
  69. friend class PrsonaServerEntity;
  70. // CONSTRUCTOR HELPERS
  71. const BGN& get_bgn_details() const;
  72. void initialize_fresh_generator(const Curvepoint& firstGenerator);
  73. Curvepoint add_rand_seed_to_generator(
  74. const Curvepoint& currGenerator) const;
  75. void set_EG_blind_generator(const Curvepoint& currGenerator);
  76. // SCORE TALLYING
  77. std::vector<Scalar> tally_scores(std::vector<Proof>& tallyProofs);
  78. Scalar get_max_possible_score(Proof& pi);
  79. // EPOCH ROUNDS
  80. void build_up_midway_pseudonyms(
  81. Proof& pi, Curvepoint& nextGenerator);
  82. void break_down_midway_pseudonyms(
  83. Proof& pi, const Curvepoint& nextGenerator);
  84. // DATA MAINTENANCE
  85. void import_updates(
  86. const Proof& pi,
  87. const std::vector<TwistBipoint>& otherPreviousVoteTally,
  88. const std::vector<Curvepoint>& otherCurrentPseudonyms,
  89. const std::vector<EGCiphertext>& otherCurrentUserEncryptedTallies,
  90. const std::vector<Proof>& otherCurrentTallyProofs,
  91. const std::vector<std::vector<CurveBipoint>>& otherVoteMatrix
  92. );
  93. void export_updates(
  94. std::vector<TwistBipoint>& otherPreviousVoteTally,
  95. std::vector<Curvepoint>& otherCurrentPseudonyms,
  96. std::vector<EGCiphertext>& otherCurrentUserEncryptedTallies,
  97. std::vector<Proof>& otherCurrentTallyProofs,
  98. std::vector<std::vector<CurveBipoint>>& otherVoteMatrix
  99. ) const;
  100. // DATA SAFEKEEPING
  101. void rerandomize_data();
  102. std::vector<size_t> order_data(Proof& pi);
  103. // A helper class for "ordering" data and for binary search
  104. struct SortingType {
  105. Curvepoint pseudonym;
  106. size_t index;
  107. bool operator<( const SortingType& rhs ) const
  108. { return pseudonym < rhs.pseudonym; }
  109. };
  110. // BINARY SEARCH
  111. size_t binary_search(const Curvepoint& index) const;
  112. // CLIENT PROOF VERIFICATION
  113. bool verify_ownership_proof(
  114. const Proof& pi,
  115. const Curvepoint& shortTermPublicKey
  116. ) const;
  117. bool verify_vote_proof(
  118. const std::vector<Proof>& pi,
  119. const std::vector<CurveBipoint>& oldVotes,
  120. const std::vector<CurveBipoint>& newVotes,
  121. const Curvepoint& shortTermPublicKey
  122. ) const;
  123. // SERVER PROOF VERIFICATION
  124. bool verify_update_proof(
  125. const Proof& pi
  126. ) const;
  127. // PROOF GENERATION
  128. Proof generate_valid_default_tally_proof(
  129. const EGCiphertext& newUserEncryptedTally,
  130. const Scalar& mask
  131. ) const;
  132. Proof generate_valid_fresh_generator_proof(
  133. const Proof& pi
  134. ) const;
  135. Proof generate_votes_valid_proof(
  136. const std::vector<CurveBipoint>& votes,
  137. const Curvepoint& voter
  138. ) const;
  139. Proof generate_proof_of_added_user(
  140. const Curvepoint& shortTermPublicKey
  141. ) const;
  142. Proof generate_score_proof(
  143. const EGCiphertext& score
  144. ) const;
  145. Proof generate_proof_of_correct_tally(
  146. const Quadripoint& BGNEncryptedTally,
  147. const Scalar& decryptedTally
  148. ) const;
  149. Proof generate_proof_of_correct_sum(
  150. const TwistBipoint& BGNEncryptedSum,
  151. const Scalar& decryptedSum
  152. ) const;
  153. Proof generate_proof_of_shuffle(
  154. const std::vector<size_t>& shuffle_order
  155. ) const;
  156. };
  157. #endif