client.hpp 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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 PrsonaServerEntity *servers);
  19. // SETUP FUNCTIONS
  20. static void init(const Curvepoint& elGamalBlindGenerator);
  21. static void set_server_malicious();
  22. static void set_client_malicious();
  23. // BASIC PUBLIC SYSTEM INFO GETTERS
  24. Curvepoint get_short_term_public_key(Proof &pi) const;
  25. // SERVER INTERACTIONS
  26. std::vector<CurveBipoint> make_votes(
  27. Proof& pi,
  28. const std::vector<CurveBipoint>& currentEncryptedVotes,
  29. const std::vector<Scalar>& vote,
  30. const std::vector<bool>& replace);
  31. void receive_fresh_generator(const Curvepoint& freshGenerator);
  32. void receive_vote_tally(const Proof& pi, const EGCiphertext& score);
  33. // REPUTATION PROOFS
  34. std::vector<Proof> generate_reputation_proof(
  35. const Scalar& threshold) const;
  36. bool verify_reputation_proof(
  37. const std::vector<Proof>& pi,
  38. const Curvepoint& shortTermPublicKey,
  39. const Scalar& threshold) const;
  40. Scalar get_score() const;
  41. private:
  42. // Constants for clients
  43. static Curvepoint EL_GAMAL_GENERATOR;
  44. static Curvepoint EL_GAMAL_BLIND_GENERATOR;
  45. static bool SERVER_IS_MALICIOUS;
  46. static bool CLIENT_IS_MALICIOUS;
  47. // Things bound to the servers permanently
  48. const BGNPublicKey serverPublicKey;
  49. const PrsonaServerEntity *servers;
  50. // Things bound to the servers (but change regularly)
  51. Curvepoint currentFreshGenerator;
  52. // Things bound to this user permanently
  53. Scalar longTermPrivateKey;
  54. Scalar inversePrivateKey;
  55. // Things bound to this user (but change regularly)
  56. EGCiphertext currentEncryptedScore;
  57. Scalar currentScore;
  58. // Things related to making decryption more efficient
  59. std::unordered_map<Curvepoint, Scalar, CurvepointHash>
  60. decryption_memoizer;
  61. Scalar max_checked;
  62. // SCORE DECRYPTION
  63. void decrypt_score(const EGCiphertext& score);
  64. // OWNERSHIP OF STPK PROOFS
  65. Proof generate_ownership_proof() const;
  66. bool verify_ownership_proof(
  67. const Proof& pi, const Curvepoint& shortTermPublicKey) const;
  68. // PROOF VERIFICATION
  69. bool verify_score_proof(const Proof& pi) const;
  70. bool verify_generator_proof(
  71. const Proof& pi, const Curvepoint& generator) const;
  72. bool verify_default_tally_proof(
  73. const Proof& pi, const EGCiphertext& generator) const;
  74. bool verify_valid_tally_proof(
  75. const Proof& pi, const EGCiphertext& score) const;
  76. bool verify_default_votes_proof(
  77. const Proof& pi, const std::vector<CurveBipoint>& votes) const;
  78. bool verify_valid_votes_proof(
  79. const Proof& pi, const std::vector<CurveBipoint>& votes) const;
  80. // PROOF GENERATION
  81. Proof generate_vote_proof(
  82. const std::vector<CurveBipoint>& encryptedVotes,
  83. const std::vector<Scalar>& vote) const;
  84. };
  85. #endif