client.hpp 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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 "EGCiphertext.hpp"
  9. #include "proof.hpp"
  10. // Forward declaration to be able to make a pointer to the servers,
  11. // which is needed in some proofs
  12. class PrsonaServerEntity;
  13. class PrsonaClient {
  14. public:
  15. // CONSTRUCTORS
  16. PrsonaClient(
  17. const BGNPublicKey& serverPublicKey,
  18. const Curvepoint& elGamalBlindGenerator,
  19. const PrsonaServerEntity *servers);
  20. // SETUP FUNCTIONS
  21. static void init();
  22. static void set_server_malicious();
  23. static void set_client_malicious();
  24. // BASIC PUBLIC SYSTEM INFO GETTERS
  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. void receive_fresh_generator(const Curvepoint& freshGenerator);
  35. void receive_vote_tally(const Proof& pi, const EGCiphertext& score);
  36. // REPUTATION PROOFS
  37. std::vector<Proof> generate_reputation_proof(
  38. const Scalar& threshold) const;
  39. bool verify_reputation_proof(
  40. const std::vector<Proof>& pi,
  41. const Curvepoint& shortTermPublicKey,
  42. const Scalar& threshold) const;
  43. Scalar get_score() const;
  44. private:
  45. // Constants for clients
  46. static Curvepoint EL_GAMAL_GENERATOR;
  47. static bool SERVER_IS_MALICIOUS;
  48. static bool CLIENT_IS_MALICIOUS;
  49. // Things bound to the servers permanently
  50. const BGNPublicKey serverPublicKey;
  51. const Curvepoint elGamalBlindGenerator;
  52. const PrsonaServerEntity *servers;
  53. // Things bound to the servers (but change regularly)
  54. Curvepoint currentFreshGenerator;
  55. // Things bound to this user permanently
  56. Scalar longTermPrivateKey;
  57. Scalar inversePrivateKey;
  58. // Things bound to this user (but change regularly)
  59. EGCiphertext currentEncryptedScore;
  60. Scalar currentScore;
  61. // Things related to making decryption more efficient
  62. std::unordered_map<Curvepoint, Scalar, CurvepointHash>
  63. decryption_memoizer;
  64. Scalar max_checked;
  65. // SCORE DECRYPTION
  66. void decrypt_score(const EGCiphertext& score);
  67. // OWNERSHIP OF STPK PROOFS
  68. Proof generate_ownership_proof() const;
  69. bool verify_ownership_proof(
  70. const Proof& pi, const Curvepoint& shortTermPublicKey) const;
  71. // PROOF VERIFICATION
  72. bool verify_score_proof(const Proof& pi) const;
  73. bool verify_generator_proof(
  74. const Proof& pi, const Curvepoint& generator) const;
  75. bool verify_default_tally_proof(
  76. const Proof& pi, const EGCiphertext& generator) const;
  77. bool verify_valid_tally_proof(
  78. const Proof& pi, const EGCiphertext& score) const;
  79. bool verify_default_votes_proof(
  80. const Proof& pi, const std::vector<CurveBipoint>& votes) const;
  81. bool verify_valid_votes_proof(
  82. const Proof& pi, const std::vector<CurveBipoint>& votes) const;
  83. // PROOF GENERATION
  84. std::vector<Proof> generate_vote_proof(
  85. const std::vector<bool>& replaces,
  86. const std::vector<CurveBipoint>& oldEncryptedVotes,
  87. const std::vector<CurveBipoint>& newEncryptedVotes,
  88. const std::vector<Scalar>& seeds,
  89. const std::vector<Scalar>& votes
  90. ) const;
  91. };
  92. #endif