server.hpp 4.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. PrsonaServer();
  12. PrsonaServer(const BGN& other_bgn, const Curvepoint& other_blind_gen);
  13. static void set_malicious_server();
  14. static void set_malicious_client();
  15. BGNPublicKey get_bgn_public_key() const;
  16. Curvepoint get_blinding_generator() const;
  17. Curvepoint add_seed_to_generator(Proof& pi, const Curvepoint& currGenerator) const;
  18. std::vector<CurveBipoint> get_current_votes_by(Proof& pi, const Curvepoint& shortTermPublicKey) const;
  19. void add_new_client(const Proof& proofOfValidKey, Proof& proofOfValidAddition, const Curvepoint& shortTermPublicKey);
  20. void receive_vote(const Proof& pi, const std::vector<CurveBipoint>& votes, const Curvepoint& shortTermPublicKey);
  21. private:
  22. static Curvepoint elGamalGenerator;
  23. static Scalar scalarN;
  24. static Scalar defaultTally;
  25. static Scalar defaultVote;
  26. static bool malicious_server;
  27. static bool malicious_client;
  28. BGN bgn_system;
  29. Curvepoint elGamalBlindGenerator;
  30. Scalar currentSeed;
  31. Scalar nextSeed;
  32. std::vector<TwistBipoint> previousVoteTally;
  33. std::vector<Curvepoint> currentPseudonyms;
  34. /* each element represents a vote by <rowID>
  35. * applied to <colID>. The outer std::vector is a std::vector of rows
  36. * and the inner std::vector is a std::vector of curvepoints. */
  37. std::vector<std::vector<CurveBipoint>> voteMatrix;
  38. friend class PrsonaServerEntity;
  39. const BGN& get_bgn_details() const;
  40. Curvepoint add_next_seed_to_generator(Proof& pi, const Curvepoint& currGenerator) const;
  41. std::vector<Scalar> tally_scores(Proof& pi);
  42. Scalar get_max_possible_score(Proof& pi);
  43. void export_updates(std::vector<TwistBipoint>& otherPreviousVoteTally, std::vector<Curvepoint>& otherCurrentPseudonyms, std::vector<std::vector<CurveBipoint>>& otherVoteMatrix) const;
  44. void import_updates(const Proof& pi, const std::vector<TwistBipoint>& otherPreviousVoteTally, const std::vector<Curvepoint>& otherCurrentPseudonyms, const std::vector<std::vector<CurveBipoint>>& otherVoteMatrix);
  45. void epoch_part_one(Proof& pi, Curvepoint& nextGenerator, std::vector<Scalar>& decryptedTallies, std::vector<Scalar>& encryptedTallyMasks);
  46. void epoch_part_two(Proof& pi, const Curvepoint& nextGenerator, std::vector<EGCiphertext>& encryptedTallies, std::vector<Scalar>& encryptedTallyMasks);
  47. std::vector<size_t> order_data();
  48. void rerandomize_vote_matrix();
  49. size_t binary_search(const Curvepoint& index) const;
  50. struct SortingType {
  51. Curvepoint pseudonym;
  52. size_t index;
  53. bool operator<( const SortingType& rhs ) const
  54. { return pseudonym < rhs.pseudonym; }
  55. };
  56. bool verify_valid_key_proof(const Proof& pi, const Curvepoint& shortTermPublicKey) const;
  57. bool verify_vote_proof(const Proof& pi, const std::vector<CurveBipoint>& votes, const Curvepoint& shortTermPublicKey) const;
  58. bool verify_update_proof(const Proof& pi, const std::vector<TwistBipoint>& otherPreviousVoteTally, const std::vector<Curvepoint>& otherCurrentPseudonyms, const std::vector<std::vector<CurveBipoint>>& otherVoteMatrix) const;
  59. Proof generate_valid_fresh_generator_proof(const Proof& pi) const;
  60. Proof generate_votes_valid_proof(const std::vector<CurveBipoint>& votes, const Curvepoint& voter) const;
  61. Proof generate_proof_of_added_user(const Curvepoint& shortTermPublicKey) const;
  62. Proof generate_score_proof(const EGCiphertext& score) const;
  63. Proof generate_proof_of_correct_tally(const std::vector<Quadripoint>& BGNEncryptedTallies, const std::vector<Scalar>& decryptedTallies) const;
  64. Proof generate_proof_of_correct_sum(const TwistBipoint& BGNEncryptedSum, const Scalar& decryptedSum) const;
  65. Proof generate_proof_of_shuffle(const std::vector<size_t>& shuffle_order) const;
  66. };
  67. #endif