base.hpp 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. #ifndef __PRSONA_BASE_HPP
  2. #define __PRSONA_BASE_HPP
  3. #include <vector>
  4. #include "Curvepoint.hpp"
  5. #include "Bipoint.hpp"
  6. #include "Scalar.hpp"
  7. #include "EGCiphertext.hpp"
  8. #include "proof.hpp"
  9. class PrsonaBase {
  10. public:
  11. static size_t MAX_ALLOWED_VOTE;
  12. // SETUP FUNCTIONS
  13. static void init();
  14. static void set_server_malicious();
  15. static void set_client_malicious();
  16. // CONST GETTERS
  17. static size_t get_max_allowed_vote();
  18. Curvepoint get_blinding_generator() const;
  19. Curvepoint get_blinding_generator(std::vector<Proof>& pi) const;
  20. protected:
  21. // Essentially constants, true for both servers and clients
  22. static Curvepoint EL_GAMAL_GENERATOR;
  23. static Scalar SCALAR_N;
  24. static Scalar DEFAULT_TALLY;
  25. static Scalar DEFAULT_VOTE;
  26. static bool SERVER_IS_MALICIOUS;
  27. static bool CLIENT_IS_MALICIOUS;
  28. std::vector<Proof> elGamalBlindGeneratorProof;
  29. Curvepoint elGamalBlindGenerator;
  30. // PRIVATE ELEMENT SETTER
  31. bool set_EG_blind_generator(
  32. const std::vector<Proof>& pi,
  33. const Curvepoint& currGenerator,
  34. size_t numServers);
  35. // BINARY SEARCH
  36. size_t binary_search(
  37. const std::vector<Curvepoint> list, const Curvepoint& index) const;
  38. // SCHNORR PROOFS
  39. Proof schnorr_generation(
  40. const Curvepoint& generator,
  41. const Curvepoint& commitment,
  42. const Scalar& log
  43. ) const;
  44. bool schnorr_verification(
  45. const Curvepoint& generator,
  46. const Curvepoint& commitment,
  47. const Scalar& c,
  48. const Scalar& z
  49. ) const;
  50. // OWNERSHIP PROOFS
  51. Proof generate_ownership_proof(
  52. const Curvepoint& generator,
  53. const Curvepoint& commitment,
  54. const Scalar& log
  55. ) const;
  56. bool verify_ownership_proof(
  57. const Proof& pi,
  58. const Curvepoint& generator,
  59. const Curvepoint& commitment
  60. ) const;
  61. // ITERATED SCHNORR PROOFS
  62. Proof add_to_generator_proof(
  63. const Curvepoint& currGenerator,
  64. const Scalar& seed
  65. ) const;
  66. bool verify_generator_proof(
  67. const std::vector<Proof>& pi,
  68. const Curvepoint& currGenerator,
  69. size_t numServers
  70. ) const;
  71. // REPUTATION PROOFS
  72. std::vector<Proof> generate_reputation_proof(
  73. const Proof& ownershipProof,
  74. const EGCiphertext& commitment,
  75. const Scalar& currentScore,
  76. const Scalar& threshold,
  77. const Scalar& inverseKey,
  78. size_t numClients
  79. ) const;
  80. bool verify_reputation_proof(
  81. const std::vector<Proof>& pi,
  82. const Curvepoint& generator,
  83. const Curvepoint& owner,
  84. const EGCiphertext& commitment,
  85. const Scalar& threshold
  86. ) const;
  87. // VALID VOTE PROOFS
  88. std::vector<Proof> generate_vote_proof(
  89. const Proof& ownershipProof,
  90. const CurveBipoint& g,
  91. const CurveBipoint& h,
  92. const std::vector<bool>& replaces,
  93. const std::vector<CurveBipoint>& oldEncryptedVotes,
  94. const std::vector<CurveBipoint>& newEncryptedVotes,
  95. const std::vector<Scalar>& seeds,
  96. const std::vector<Scalar>& votes
  97. ) const;
  98. bool verify_vote_proof(
  99. const CurveBipoint& g,
  100. const CurveBipoint& h,
  101. const std::vector<Proof>& pi,
  102. const std::vector<CurveBipoint>& oldEncryptedVotes,
  103. const std::vector<CurveBipoint>& newEncryptedVotes,
  104. const Curvepoint& freshGenerator,
  105. const Curvepoint& owner
  106. ) const;
  107. // NEW USER PROOFS
  108. std::vector<Proof> generate_proof_of_added_user(
  109. const Scalar& twistBipointSeed,
  110. const Scalar& EGCiphertextSeed,
  111. const std::vector<Scalar>& curveBipointSelfSeeds,
  112. const std::vector<Scalar>& curveBipointOtherSeeds
  113. ) const;
  114. bool verify_proof_of_added_user(
  115. const std::vector<Proof>& pi,
  116. const Curvepoint& currentFreshGenerator,
  117. const Curvepoint& shortTermPublicKey,
  118. const Curvepoint& elGamalBlindGenerator,
  119. const CurveBipoint& curveG,
  120. const CurveBipoint& curveH,
  121. const TwistBipoint& twistG,
  122. const TwistBipoint& twistH,
  123. size_t selfIndex,
  124. const EGCiphertext& userEncryptedScore,
  125. const TwistBipoint& serverEncryptedScore,
  126. const std::vector<std::vector<CurveBipoint>> encryptedVoteMatrix
  127. ) const;
  128. // EPOCH PROOFS
  129. Proof generate_proof_of_added_user() const;
  130. Proof generate_proof_of_correct_tally() const;
  131. Proof generate_proof_of_correct_sum() const;
  132. Proof generate_proof_of_shuffle() const;
  133. bool verify_update_proof(const Proof& pi) const;
  134. // SERVER AGREEMENT PROOFS
  135. Proof generate_valid_user_tally_proof() const;
  136. Proof generate_valid_server_tally_proof() const;
  137. Proof generate_valid_vote_row_proof() const;
  138. Proof generate_valid_vote_matrix_proof() const;
  139. Proof generate_valid_pseudonyms_proof() const;
  140. bool verify_valid_user_tally_proof(const Proof& pi) const;
  141. bool verify_valid_server_tally_proof(const Proof& pi) const;
  142. bool verify_valid_vote_row_proof(const Proof& pi) const;
  143. bool verify_valid_vote_matrix_proof(const Proof& pi) const;
  144. bool verify_valid_pseudonyms_proof(const Proof& pi) const;
  145. };
  146. #endif