client.hpp 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. #ifndef __PRSONA_CLIENT_HPP
  2. #define __PRSONA_CLIENT_HPP
  3. #include <unordered_map>
  4. #include <vector>
  5. #include "Curvepoint.hpp"
  6. #include "Scalar.hpp"
  7. #include "BGN.hpp"
  8. #include "base.hpp"
  9. #include "EGCiphertext.hpp"
  10. #include "proof.hpp"
  11. // Forward declaration to be able to make a pointer to the servers,
  12. // which is needed in some proofs
  13. class PrsonaServerEntity;
  14. class PrsonaClient : public PrsonaBase {
  15. public:
  16. // CONSTRUCTORS
  17. PrsonaClient(
  18. const BGNPublicKey& serverPublicKey,
  19. const std::vector<Proof>& generatorProof,
  20. const Curvepoint& elGamalBlindGenerator,
  21. const PrsonaServerEntity* servers);
  22. // BASIC PUBLIC SYSTEM INFO GETTERS
  23. Curvepoint get_short_term_public_key(Proof &pi) const;
  24. // SERVER INTERACTIONS
  25. std::vector<CurveBipoint> make_votes(
  26. std::vector<Proof>& validVoteProof,
  27. const Proof& serverProof,
  28. const std::vector<CurveBipoint>& oldEncryptedVotes,
  29. const std::vector<Scalar>& votes,
  30. const std::vector<bool>& replaces
  31. ) const;
  32. bool receive_fresh_generator(
  33. const std::vector<Proof>& pi, const Curvepoint& freshGenerator);
  34. void receive_vote_tally(const Proof& pi, const EGCiphertext& score);
  35. // REPUTATION PROOFS
  36. std::vector<Proof> generate_reputation_proof(
  37. const Scalar& threshold
  38. ) const;
  39. bool verify_reputation_proof(
  40. const std::vector<Proof>& pi,
  41. const Curvepoint& shortTermPublicKey,
  42. const Scalar& threshold
  43. ) const;
  44. // NEEDED FOR TESTING PROOFS
  45. Scalar get_score() const;
  46. protected:
  47. // REQUIRED BY BASE CLASS
  48. EGCiphertext get_current_tally(
  49. Proof& pi, const Curvepoint& shortTermPublicKey) const;
  50. private:
  51. // Constants for clients
  52. static bool SERVER_IS_MALICIOUS;
  53. static bool CLIENT_IS_MALICIOUS;
  54. // Things bound to the servers permanently
  55. const BGNPublicKey serverPublicKey;
  56. const PrsonaServerEntity *servers;
  57. // Things bound to the servers (but change regularly)
  58. Curvepoint currentFreshGenerator;
  59. // Things bound to this user permanently
  60. Scalar longTermPrivateKey;
  61. Scalar inversePrivateKey;
  62. // Things bound to this user (but change regularly)
  63. EGCiphertext currentEncryptedScore;
  64. Scalar currentScore;
  65. // Things related to making decryption more efficient
  66. std::unordered_map<Curvepoint, Scalar, CurvepointHash>
  67. decryption_memoizer;
  68. Scalar max_checked;
  69. // SCORE DECRYPTION
  70. void decrypt_score(const EGCiphertext& score);
  71. // OWNERSHIP OF STPK PROOFS
  72. Proof generate_ownership_proof() const;
  73. // VALID VOTE PROOFS
  74. std::vector<Proof> generate_vote_proof(
  75. const std::vector<bool>& replaces,
  76. const std::vector<CurveBipoint>& oldEncryptedVotes,
  77. const std::vector<CurveBipoint>& newEncryptedVotes,
  78. const std::vector<Scalar>& seeds,
  79. const std::vector<Scalar>& votes
  80. ) const;
  81. };
  82. #endif