client.hpp 3.1 KB

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