server.hpp 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  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 Curvepoint init();
  16. static void set_server_malicious();
  17. static void set_client_malicious();
  18. // BASIC PUBLIC SYSTEM INFO GETTERS
  19. static Curvepoint get_blinding_generator();
  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. void receive_vote(
  37. const Proof& pi,
  38. const std::vector<CurveBipoint>& votes,
  39. const Curvepoint& shortTermPublicKey);
  40. private:
  41. // Constants for servers
  42. static Curvepoint EL_GAMAL_GENERATOR;
  43. static Curvepoint EL_GAMAL_BLIND_GENERATOR;
  44. static Scalar SCALAR_N;
  45. static Scalar DEFAULT_TALLY;
  46. static Scalar DEFAULT_VOTE;
  47. static bool SERVER_IS_MALICIOUS;
  48. static bool CLIENT_IS_MALICIOUS;
  49. // Identical between all servers
  50. BGN bgn_system;
  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. // SCORE TALLYING
  74. std::vector<Scalar> tally_scores(std::vector<Proof>& tallyProofs);
  75. Scalar get_max_possible_score(Proof& pi);
  76. // EPOCH ROUNDS
  77. void build_up_midway_pseudonyms(
  78. Proof& pi, Curvepoint& nextGenerator);
  79. void break_down_midway_pseudonyms(
  80. Proof& pi, const Curvepoint& nextGenerator);
  81. // DATA MAINTENANCE
  82. void import_updates(
  83. const Proof& pi,
  84. const std::vector<TwistBipoint>& otherPreviousVoteTally,
  85. const std::vector<Curvepoint>& otherCurrentPseudonyms,
  86. const std::vector<EGCiphertext>& otherCurrentUserEncryptedTallies,
  87. const std::vector<Proof>& otherCurrentTallyProofs,
  88. const std::vector<std::vector<CurveBipoint>>& otherVoteMatrix
  89. );
  90. void export_updates(
  91. std::vector<TwistBipoint>& otherPreviousVoteTally,
  92. std::vector<Curvepoint>& otherCurrentPseudonyms,
  93. std::vector<EGCiphertext>& otherCurrentUserEncryptedTallies,
  94. std::vector<Proof>& otherCurrentTallyProofs,
  95. std::vector<std::vector<CurveBipoint>>& otherVoteMatrix
  96. ) const;
  97. // DATA SAFEKEEPING
  98. void rerandomize_data();
  99. std::vector<size_t> order_data(Proof& pi);
  100. // A helper class for "ordering" data and for binary search
  101. struct SortingType {
  102. Curvepoint pseudonym;
  103. size_t index;
  104. bool operator<( const SortingType& rhs ) const
  105. { return pseudonym < rhs.pseudonym; }
  106. };
  107. // BINARY SEARCH
  108. size_t binary_search(const Curvepoint& index) const;
  109. // PROOF VERIFICATION
  110. bool verify_valid_key_proof(
  111. const Proof& pi,
  112. const Curvepoint& shortTermPublicKey
  113. ) const;
  114. bool verify_vote_proof(
  115. const Proof& pi,
  116. const std::vector<CurveBipoint>& votes,
  117. const Curvepoint& shortTermPublicKey
  118. ) const;
  119. bool verify_update_proof(
  120. const Proof& pi
  121. ) const;
  122. // PROOF GENERATION
  123. Proof generate_valid_default_tally_proof(
  124. const EGCiphertext& newUserEncryptedTally,
  125. const Scalar& mask
  126. ) const;
  127. Proof generate_valid_fresh_generator_proof(
  128. const Proof& pi
  129. ) const;
  130. Proof generate_votes_valid_proof(
  131. const std::vector<CurveBipoint>& votes,
  132. const Curvepoint& voter
  133. ) const;
  134. Proof generate_proof_of_added_user(
  135. const Curvepoint& shortTermPublicKey
  136. ) const;
  137. Proof generate_score_proof(
  138. const EGCiphertext& score
  139. ) const;
  140. Proof generate_proof_of_correct_tally(
  141. const Quadripoint& BGNEncryptedTally,
  142. const Scalar& decryptedTally
  143. ) const;
  144. Proof generate_proof_of_correct_sum(
  145. const TwistBipoint& BGNEncryptedSum,
  146. const Scalar& decryptedSum
  147. ) const;
  148. Proof generate_proof_of_shuffle(
  149. const std::vector<size_t>& shuffle_order
  150. ) const;
  151. };
  152. #endif