base.hpp 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  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. static Twistpoint EL_GAMAL_GENERATOR;
  13. // SETUP FUNCTIONS
  14. static void init();
  15. static void set_server_malicious();
  16. static void set_client_malicious();
  17. // CONST GETTERS
  18. static size_t get_max_allowed_vote();
  19. Twistpoint get_blinding_generator() const;
  20. Twistpoint get_blinding_generator(std::vector<Proof>& pi) const;
  21. // BINARY SEARCH
  22. size_t binary_search(
  23. const std::vector<Twistpoint> list, const Twistpoint& index) const;
  24. protected:
  25. // Essentially constants, true for both servers and clients
  26. static Scalar SCALAR_N;
  27. static Scalar DEFAULT_TALLY;
  28. static Scalar DEFAULT_VOTE;
  29. static bool SERVER_IS_MALICIOUS;
  30. static bool CLIENT_IS_MALICIOUS;
  31. std::vector<Proof> elGamalBlindGeneratorProof;
  32. Twistpoint elGamalBlindGenerator;
  33. // PRIVATE ELEMENT SETTER
  34. bool set_EG_blind_generator(
  35. const std::vector<Proof>& pi,
  36. const Twistpoint& currGenerator,
  37. size_t numServers);
  38. // SCHNORR PROOFS
  39. Proof schnorr_generation(
  40. const Twistpoint& generator,
  41. const Twistpoint& commitment,
  42. const Scalar& log
  43. ) const;
  44. bool schnorr_verification(
  45. const Twistpoint& generator,
  46. const Twistpoint& commitment,
  47. const Scalar& c,
  48. const Scalar& z
  49. ) const;
  50. // OWNERSHIP PROOFS
  51. Proof generate_ownership_proof(
  52. const Twistpoint& generator,
  53. const Twistpoint& commitment,
  54. const Scalar& log
  55. ) const;
  56. bool verify_ownership_proof(
  57. const Proof& pi,
  58. const Twistpoint& generator,
  59. const Twistpoint& commitment
  60. ) const;
  61. // ITERATED SCHNORR PROOFS
  62. Proof add_to_generator_proof(
  63. const Twistpoint& currGenerator,
  64. const Scalar& seed
  65. ) const;
  66. bool verify_generator_proof(
  67. const std::vector<Proof>& pi,
  68. const Twistpoint& 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 Twistpoint& generator,
  83. const Twistpoint& 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 TwistBipoint& g,
  91. const TwistBipoint& h,
  92. const std::vector<bool>& replaces,
  93. const std::vector<TwistBipoint>& oldEncryptedVotes,
  94. const std::vector<TwistBipoint>& newEncryptedVotes,
  95. const std::vector<Scalar>& seeds,
  96. const std::vector<Scalar>& votes
  97. ) const;
  98. bool verify_vote_proof(
  99. const TwistBipoint& g,
  100. const TwistBipoint& h,
  101. const std::vector<Proof>& pi,
  102. const std::vector<TwistBipoint>& oldEncryptedVotes,
  103. const std::vector<TwistBipoint>& newEncryptedVotes,
  104. const Twistpoint& freshGenerator,
  105. const Twistpoint& 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 Twistpoint& currentFreshGenerator,
  117. const Twistpoint& shortTermPublicKey,
  118. const TwistBipoint& curveG,
  119. const TwistBipoint& curveH,
  120. const CurveBipoint& twistG,
  121. const CurveBipoint& twistH,
  122. size_t selfIndex,
  123. const EGCiphertext& userEncryptedScore,
  124. const CurveBipoint& serverEncryptedScore,
  125. const std::vector<std::vector<TwistBipoint>> 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<Twistpoint>>& commits
  132. ) const;
  133. bool verify_valid_permutation_proof(
  134. const std::vector<Proof>& pi,
  135. const std::vector<std::vector<Twistpoint>>& 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<Twistpoint>& oldValues,
  143. const std::vector<std::vector<Twistpoint>>& permutationCommits,
  144. const std::vector<std::vector<Twistpoint>>& productCommits,
  145. const std::vector<std::vector<Twistpoint>>& seedCommits
  146. ) const;
  147. bool verify_proof_of_reordering_plus_power(
  148. const std::vector<Proof>& pi,
  149. const std::vector<Twistpoint>& oldValues,
  150. const std::vector<std::vector<Twistpoint>>& permutationCommits,
  151. const std::vector<std::vector<Twistpoint>>& productCommits,
  152. const std::vector<std::vector<Twistpoint>>& seedCommits
  153. ) const;
  154. std::vector<Proof> generate_user_tally_proofs(
  155. const std::vector<std::vector<Scalar>>& permutations,
  156. const Scalar& power,
  157. const Twistpoint& nextGenerator,
  158. const std::vector<std::vector<Scalar>>& permutationSeeds,
  159. const std::vector<std::vector<Scalar>>& userTallySeeds,
  160. const std::vector<Twistpoint>& currPseudonyms,
  161. const std::vector<Twistpoint>& userTallyMasks,
  162. const std::vector<Twistpoint>& userTallyMessages,
  163. const std::vector<std::vector<Twistpoint>>& permutationCommits,
  164. const std::vector<std::vector<Twistpoint>>& userTallyMaskCommits,
  165. const std::vector<std::vector<Twistpoint>>& userTallyMessageCommits,
  166. const std::vector<std::vector<Twistpoint>>& userTallySeedCommits
  167. ) const;
  168. bool verify_user_tally_proofs(
  169. const std::vector<Proof>& pi,
  170. const Twistpoint& nextGenerator,
  171. const std::vector<Twistpoint>& currPseudonyms,
  172. const std::vector<Twistpoint>& userTallyMasks,
  173. const std::vector<Twistpoint>& userTallyMessages,
  174. const std::vector<std::vector<Twistpoint>>& permutationCommits,
  175. const std::vector<std::vector<Twistpoint>>& userTallyMaskCommits,
  176. const std::vector<std::vector<Twistpoint>>& userTallyMessageCommits,
  177. const std::vector<std::vector<Twistpoint>>& userTallySeedCommits
  178. ) const;
  179. template <typename T>
  180. std::vector<Proof> generate_proof_of_reordering(
  181. const std::vector<std::vector<Scalar>>& permutations,
  182. const std::vector<std::vector<Scalar>>& permutationSeeds,
  183. const std::vector<std::vector<Scalar>>& productSeeds,
  184. const std::vector<T>& oldValues,
  185. const std::vector<std::vector<Twistpoint>>& permutationCommits,
  186. const std::vector<std::vector<T>>& productCommits,
  187. const T& otherG,
  188. const T& otherH
  189. ) const;
  190. template <typename T>
  191. bool verify_proof_of_reordering(
  192. const std::vector<Proof>& pi,
  193. const std::vector<T>& oldValues,
  194. const std::vector<std::vector<Twistpoint>>& permutationCommits,
  195. const std::vector<std::vector<T>>& productCommits,
  196. const T& otherG,
  197. const T& otherH
  198. ) const;
  199. // SERVER AGREEMENT PROOFS
  200. Proof generate_valid_vote_row_proof(
  201. const std::vector<TwistBipoint>& commitment) const;
  202. Proof generate_valid_vote_matrix_proof(
  203. const std::vector<std::vector<TwistBipoint>>& commitment) const;
  204. Proof generate_valid_user_tally_proof(
  205. const EGCiphertext& commitment) const;
  206. Proof generate_valid_server_tally_proof(
  207. const CurveBipoint& commitment) const;
  208. Proof generate_valid_pseudonyms_proof(
  209. const std::vector<Twistpoint>& commitment) const;
  210. bool verify_valid_vote_row_proof(
  211. const std::vector<Proof>& pi,
  212. const std::vector<TwistBipoint>& commitment
  213. ) const;
  214. bool verify_valid_vote_matrix_proof(
  215. const std::vector<Proof>& pi,
  216. const std::vector<std::vector<TwistBipoint>>& commitment
  217. ) const;
  218. bool verify_valid_user_tally_proof(
  219. const std::vector<Proof>& pi,
  220. const EGCiphertext& commitment
  221. ) const;
  222. bool verify_valid_server_tally_proof(
  223. const std::vector<Proof>& pi,
  224. const CurveBipoint& commitment
  225. ) const;
  226. bool verify_valid_pseudonyms_proof(
  227. const std::vector<Proof>& pi,
  228. const std::vector<Twistpoint>& commitment
  229. ) const;
  230. };
  231. #endif