base.hpp 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  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 CurveBipoint& curveG,
  119. const CurveBipoint& curveH,
  120. const TwistBipoint& twistG,
  121. const TwistBipoint& twistH,
  122. size_t selfIndex,
  123. const EGCiphertext& userEncryptedScore,
  124. const TwistBipoint& serverEncryptedScore,
  125. const std::vector<std::vector<CurveBipoint>> encryptedVoteMatrix
  126. ) const;
  127. // EPOCH PROOFS
  128. std::vector<Proof> generate_valid_permutation_proof(
  129. const std::vector<std::vector<Scalar>>& permutations,
  130. const std::vector<std::vector<Scalar>>& seeds,
  131. const std::vector<std::vector<Curvepoint>>& commits
  132. ) const;
  133. bool verify_valid_permutation_proof(
  134. const std::vector<Proof>& pi,
  135. const std::vector<std::vector<Curvepoint>>& commits
  136. ) const;
  137. std::vector<Proof> generate_proof_of_reordering_plus_power(
  138. const std::vector<std::vector<Scalar>>& permutations,
  139. const Scalar& power,
  140. const std::vector<std::vector<Scalar>>& permutationSeeds,
  141. const std::vector<std::vector<Scalar>>& productSeeds,
  142. const std::vector<Curvepoint>& oldValues,
  143. const std::vector<std::vector<Curvepoint>>& permutationCommits,
  144. const std::vector<std::vector<Curvepoint>>& productCommits,
  145. const std::vector<std::vector<Curvepoint>>& seedCommits
  146. ) const;
  147. bool verify_proof_of_reordering_plus_power(
  148. const std::vector<Proof>& pi,
  149. const std::vector<Curvepoint>& oldValues,
  150. const std::vector<std::vector<Curvepoint>>& permutationCommits,
  151. const std::vector<std::vector<Curvepoint>>& productCommits,
  152. const std::vector<std::vector<Curvepoint>>& seedCommits
  153. ) const;
  154. template <typename T>
  155. std::vector<Proof> generate_proof_of_reordering(
  156. const std::vector<std::vector<Scalar>>& permutations,
  157. const std::vector<std::vector<Scalar>>& permutationSeeds,
  158. const std::vector<std::vector<Scalar>>& productSeeds,
  159. const std::vector<T>& oldValues,
  160. const std::vector<std::vector<Curvepoint>>& permutationCommits,
  161. const std::vector<std::vector<T>>& productCommits,
  162. const T& otherG,
  163. const T& otherH,
  164. bool inverted
  165. ) const;
  166. template <typename T>
  167. bool verify_proof_of_reordering(
  168. const std::vector<Proof>& pi,
  169. const std::vector<T>& oldValues,
  170. const std::vector<std::vector<Curvepoint>>& permutationCommits,
  171. const std::vector<std::vector<T>>& productCommits,
  172. const T& otherG,
  173. const T& otherH,
  174. bool inverted
  175. ) const;
  176. // SERVER AGREEMENT PROOFS
  177. Proof generate_valid_vote_row_proof(
  178. const std::vector<CurveBipoint>& commitment) const;
  179. Proof generate_valid_vote_matrix_proof(
  180. const std::vector<std::vector<CurveBipoint>>& commitment) const;
  181. Proof generate_valid_user_tally_proof(
  182. const EGCiphertext& commitment) const;
  183. Proof generate_valid_server_tally_proof(
  184. const TwistBipoint& commitment) const;
  185. Proof generate_valid_pseudonyms_proof(
  186. const std::vector<Curvepoint>& commitment) const;
  187. bool verify_valid_vote_row_proof(
  188. const std::vector<Proof>& pi,
  189. const std::vector<CurveBipoint>& commitment
  190. ) const;
  191. bool verify_valid_vote_matrix_proof(
  192. const std::vector<Proof>& pi,
  193. const std::vector<std::vector<CurveBipoint>>& commitment
  194. ) const;
  195. bool verify_valid_user_tally_proof(
  196. const std::vector<Proof>& pi,
  197. const EGCiphertext& commitment
  198. ) const;
  199. bool verify_valid_server_tally_proof(
  200. const std::vector<Proof>& pi,
  201. const TwistBipoint& commitment
  202. ) const;
  203. bool verify_valid_pseudonyms_proof(
  204. const std::vector<Proof>& pi,
  205. const std::vector<Curvepoint>& commitment
  206. ) const;
  207. };
  208. #endif