server.hpp 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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. // CLIENT INTERACTIONS
  37. void add_new_client(
  38. std::vector<Proof>& proofOfValidAddition,
  39. const Proof& proofOfValidKey,
  40. const Curvepoint& shortTermPublicKey);
  41. bool receive_vote(
  42. const std::vector<Proof>& pi,
  43. const std::vector<CurveBipoint>& newVotes,
  44. const Curvepoint& shortTermPublicKey);
  45. private:
  46. // constants for servers
  47. const size_t numServers;
  48. // Identical between all servers (but collaboratively constructed)
  49. BGN bgnSystem;
  50. // Private; different for each server
  51. Scalar currentSeed;
  52. Scalar nextSeed;
  53. // The actual data, which is collaboratively updated by all servers
  54. Curvepoint currentFreshGenerator;
  55. std::vector<TwistBipoint> previousVoteTallies;
  56. std::vector<Curvepoint> currentPseudonyms;
  57. std::vector<EGCiphertext> currentUserEncryptedTallies;
  58. std::vector<std::vector<CurveBipoint>> voteMatrix;
  59. /**
  60. * NOTE: voteMatrix structure:
  61. * Each element represents a vote by <rowID> applied to <colID>.
  62. * The outer vector is a vector of rows and the inner vector is
  63. * a vector of encrypted votes.
  64. */
  65. // An imaginary class; it's just used right now to coordinate servers
  66. // in memory instead of via network action.
  67. friend class PrsonaServerEntity;
  68. // CONSTRUCTOR HELPERS
  69. const BGN& get_bgn_details() const;
  70. bool initialize_fresh_generator(
  71. const std::vector<Proof>& pi,
  72. const Curvepoint& firstGenerator);
  73. Curvepoint add_rand_seed_to_generator(
  74. std::vector<Proof>& pi,
  75. const Curvepoint& currGenerator) const;
  76. bool set_EG_blind_generator(
  77. const std::vector<Proof>& pi,
  78. const Curvepoint& currGenerator);
  79. // SCORE TALLYING
  80. std::vector<Scalar> tally_scores();
  81. Scalar get_max_possible_score(Proof& pi);
  82. // EPOCH ROUNDS
  83. void build_up_midway_pseudonyms(
  84. Proof& pi, Curvepoint& nextGenerator);
  85. void break_down_midway_pseudonyms(
  86. Proof& pi, const Curvepoint& nextGenerator);
  87. // DATA MAINTENANCE
  88. void import_updates(
  89. const Proof& pi,
  90. const std::vector<TwistBipoint>& otherPreviousVoteTally,
  91. const std::vector<Curvepoint>& otherCurrentPseudonyms,
  92. const std::vector<EGCiphertext>& otherCurrentUserEncryptedTallies,
  93. const std::vector<std::vector<CurveBipoint>>& otherVoteMatrix
  94. );
  95. void export_updates(
  96. std::vector<TwistBipoint>& otherPreviousVoteTally,
  97. std::vector<Curvepoint>& otherCurrentPseudonyms,
  98. std::vector<EGCiphertext>& otherCurrentUserEncryptedTallies,
  99. std::vector<std::vector<CurveBipoint>>& otherVoteMatrix
  100. ) const;
  101. // DATA SAFEKEEPING
  102. void rerandomize_data();
  103. std::vector<size_t> order_data(Proof& pi);
  104. // A helper class for "ordering" data and for binary search
  105. struct SortingType {
  106. Curvepoint pseudonym;
  107. size_t index;
  108. bool operator<( const SortingType& rhs ) const
  109. { return pseudonym < rhs.pseudonym; }
  110. };
  111. // BINARY SEARCH
  112. size_t binary_search(const Curvepoint& index) const;
  113. // VALID VOTE PROOFS
  114. bool verify_vote_proof(
  115. const std::vector<Proof>& pi,
  116. const std::vector<CurveBipoint>& oldVotes,
  117. const std::vector<CurveBipoint>& newVotes,
  118. const Curvepoint& shortTermPublicKey
  119. ) const;
  120. };
  121. #endif