client.hpp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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 std::vector<Proof>& generatorProof,
  19. const Curvepoint& elGamalBlindGenerator,
  20. const BGNPublicKey& serverPublicKey,
  21. const PrsonaServerEntity* servers);
  22. // BASIC PUBLIC SYSTEM INFO GETTERS
  23. Curvepoint get_short_term_public_key() const;
  24. Curvepoint get_short_term_public_key(Proof &pi) const;
  25. // SERVER INTERACTIONS
  26. std::vector<CurveBipoint> make_votes(
  27. std::vector<Proof>& validVoteProof,
  28. const Proof& serverProof,
  29. const std::vector<CurveBipoint>& oldEncryptedVotes,
  30. const std::vector<Scalar>& votes,
  31. const std::vector<bool>& replaces
  32. ) const;
  33. bool receive_fresh_generator(
  34. const std::vector<Proof>& pi, const Curvepoint& freshGenerator);
  35. bool receive_vote_tally();
  36. bool receive_new_user_data(const std::vector<Proof>& pi);
  37. // REPUTATION PROOFS
  38. std::vector<Proof> generate_reputation_proof(
  39. const Scalar& threshold
  40. ) const;
  41. bool verify_reputation_proof(
  42. const std::vector<Proof>& pi,
  43. const Curvepoint& shortTermPublicKey,
  44. const Scalar& threshold
  45. ) const;
  46. // NEEDED FOR TESTING PROOFS
  47. Scalar get_score() const;
  48. private:
  49. // Constants for clients
  50. static bool SERVER_IS_MALICIOUS;
  51. static bool CLIENT_IS_MALICIOUS;
  52. // Things bound to the servers permanently
  53. const BGNPublicKey serverPublicKey;
  54. const PrsonaServerEntity *servers;
  55. // Things bound to the servers (but change regularly)
  56. Curvepoint currentFreshGenerator;
  57. // Things bound to this user permanently
  58. Scalar longTermPrivateKey;
  59. Scalar inversePrivateKey;
  60. // Things bound to this user (but change regularly)
  61. EGCiphertext currentEncryptedScore;
  62. Scalar currentScore;
  63. // Things related to making decryption more efficient
  64. std::unordered_map<Curvepoint, Scalar, CurvepointHash>
  65. decryption_memoizer;
  66. Scalar max_checked;
  67. // SCORE DECRYPTION
  68. Scalar decrypt_score(const EGCiphertext& score);
  69. // OWNERSHIP OF STPK PROOFS
  70. Proof generate_ownership_proof() const;
  71. // VALID VOTE PROOFS
  72. std::vector<Proof> generate_vote_proof(
  73. const std::vector<bool>& replaces,
  74. const std::vector<CurveBipoint>& oldEncryptedVotes,
  75. const std::vector<CurveBipoint>& newEncryptedVotes,
  76. const std::vector<Scalar>& seeds,
  77. const std::vector<Scalar>& votes
  78. ) const;
  79. };
  80. #endif