client.hpp 3.6 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<Scalar>& vote,
  29. const std::vector<bool>& replace);
  30. void receive_fresh_generator(const Curvepoint& freshGenerator);
  31. void receive_vote_tally(const Proof& pi, const EGCiphertext& score);
  32. void receive_encrypted_votes(
  33. const Proof& pi, const std::vector<CurveBipoint>& votes);
  34. // REPUTATION PROOFS
  35. std::vector<Proof> generate_reputation_proof(
  36. const Scalar& threshold) const;
  37. bool verify_reputation_proof(
  38. const std::vector<Proof>& pi,
  39. const Curvepoint& shortTermPublicKey,
  40. const Scalar& threshold) 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. std::vector<CurveBipoint> currentEncryptedVotes;
  59. // Things related to making decryption more efficient
  60. std::unordered_map<Curvepoint, Scalar, CurvepointHash>
  61. decryption_memoizer;
  62. Scalar max_checked;
  63. // SCORE DECRYPTION
  64. void decrypt_score(const EGCiphertext& score);
  65. // OWNERSHIP OF STPK PROOFS
  66. Proof generate_ownership_proof() const;
  67. bool verify_ownership_proof(
  68. const Proof& pi, const Curvepoint& shortTermPublicKey) const;
  69. // PROOF VERIFICATION
  70. bool verify_score_proof(const Proof& pi) const;
  71. bool verify_generator_proof(
  72. const Proof& pi, const Curvepoint& generator) const;
  73. bool verify_default_tally_proof(
  74. const Proof& pi, const EGCiphertext& generator) const;
  75. bool verify_valid_tally_proof(
  76. const Proof& pi, const EGCiphertext& score) const;
  77. bool verify_default_votes_proof(
  78. const Proof& pi, const std::vector<CurveBipoint>& votes) const;
  79. bool verify_valid_votes_proof(
  80. const Proof& pi, const std::vector<CurveBipoint>& votes) const;
  81. // PROOF GENERATION
  82. Proof generate_vote_proof(
  83. const std::vector<CurveBipoint>& encryptedVotes,
  84. const std::vector<Scalar>& vote) const;
  85. };
  86. #endif