server.hpp 3.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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 const Curvepoint elGamalGenerator;
  23. static const Scalar scalarN;
  24. static const Scalar defaultTally;
  25. static const 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. void export_updates(std::vector<TwistBipoint>& otherPreviousVoteTally, std::vector<Curvepoint>& otherCurrentPseudonyms, std::vector<std::vector<CurveBipoint>>& otherVoteMatrix) const;
  43. void import_updates(const Proof& pi, const std::vector<TwistBipoint>& otherPreviousVoteTally, const std::vector<Curvepoint>& otherCurrentPseudonyms, const std::vector<std::vector<CurveBipoint>>& otherVoteMatrix);
  44. void epoch_part_one(Proof& pi, Curvepoint& nextGenerator, std::vector<Scalar>& decryptedTallies);
  45. void epoch_part_two(Proof& pi, std::vector<EGCiphertext>& encryptedTallies);
  46. std::vector<size_t> order_data();
  47. void rerandomize_vote_matrix();
  48. size_t binary_search(const Curvepoint& index) const;
  49. struct SortingType {
  50. Curvepoint pseudonym;
  51. size_t index;
  52. bool operator<( const SortingType& rhs ) const
  53. { return pseudonym < rhs.pseudonym; }
  54. };
  55. bool verify_valid_key_proof(const Proof& pi, const Curvepoint& shortTermPublicKey) const;
  56. bool verify_vote_proof(const Proof& pi, const std::vector<CurveBipoint>& votes, const Curvepoint& shortTermPublicKey) const;
  57. 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;
  58. Proof generate_valid_fresh_generator_proof(const Proof& pi) const;
  59. Proof generate_votes_valid_proof(const std::vector<CurveBipoint>& votes, const Curvepoint& voter) const;
  60. Proof generate_proof_of_added_user(const Curvepoint& shortTermPublicKey) const;
  61. Proof generate_score_proof(const EGCiphertext& score) const;
  62. Proof generate_proof_of_correct_tally(const std::vector<Quadripoint>& BGNEncryptedTallies, const std::vector<Scalar>& decryptedTallies) const;
  63. Proof generate_proof_of_shuffle(const std::vector<size_t>& shuffle_order) const;
  64. };
  65. #endif