base.hpp 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412
  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. static void set_lambda(size_t lambda);
  18. // CONST GETTERS
  19. static size_t get_max_allowed_vote();
  20. Twistpoint get_blinding_generator() const;
  21. Twistpoint get_blinding_generator(
  22. std::vector<Proof>& pi
  23. ) const;
  24. // BINARY SEARCH
  25. size_t binary_search(
  26. const std::vector<Twistpoint> list,
  27. const Twistpoint& index
  28. ) const;
  29. protected:
  30. // Essentially constants, true for both servers and clients
  31. static Scalar SCALAR_N;
  32. static Scalar DEFAULT_TALLY;
  33. static Scalar DEFAULT_VOTE;
  34. static bool SERVER_IS_MALICIOUS;
  35. static bool CLIENT_IS_MALICIOUS;
  36. static size_t LAMBDA;
  37. std::vector<Proof> elGamalBlindGeneratorProof;
  38. Twistpoint elGamalBlindGenerator;
  39. // PRIVATE ELEMENT SETTER
  40. bool set_EG_blind_generator(
  41. const std::vector<Proof>& pi,
  42. const Twistpoint& currGenerator,
  43. size_t numServers);
  44. // SCHNORR PROOFS
  45. Proof schnorr_generation(
  46. const Twistpoint& generator,
  47. const Twistpoint& commitment,
  48. const Scalar& log
  49. ) const;
  50. bool schnorr_verification(
  51. const Twistpoint& generator,
  52. const Twistpoint& commitment,
  53. const Scalar& c,
  54. const Scalar& z
  55. ) const;
  56. // OWNERSHIP PROOFS
  57. Proof generate_ownership_proof(
  58. const Twistpoint& generator,
  59. const Twistpoint& commitment,
  60. const Scalar& log
  61. ) const;
  62. bool verify_ownership_proof(
  63. const Proof& pi,
  64. const Twistpoint& generator,
  65. const Twistpoint& commitment
  66. ) const;
  67. // ITERATED SCHNORR PROOFS
  68. Proof add_to_generator_proof(
  69. const Twistpoint& currGenerator,
  70. const Scalar& seed
  71. ) const;
  72. bool verify_generator_proof(
  73. const std::vector<Proof>& pi,
  74. const Twistpoint& currGenerator,
  75. size_t numServers
  76. ) const;
  77. // REPUTATION PROOFS
  78. std::vector<Proof> generate_reputation_proof(
  79. const Proof& ownershipProof,
  80. const EGCiphertext& commitment,
  81. const Scalar& currentScore,
  82. const Scalar& threshold,
  83. const Scalar& inverseKey,
  84. size_t numClients
  85. ) const;
  86. bool verify_reputation_proof(
  87. const std::vector<Proof>& pi,
  88. const Twistpoint& generator,
  89. const Twistpoint& owner,
  90. const EGCiphertext& commitment,
  91. const Scalar& threshold
  92. ) const;
  93. // VALID VOTE PROOFS
  94. std::vector<Proof> generate_vote_proof(
  95. const Proof& ownershipProof,
  96. const TwistBipoint& g,
  97. const TwistBipoint& h,
  98. const std::vector<bool>& replaces,
  99. const std::vector<TwistBipoint>& oldEncryptedVotes,
  100. const std::vector<TwistBipoint>& newEncryptedVotes,
  101. const std::vector<Scalar>& seeds,
  102. const std::vector<Scalar>& votes
  103. ) const;
  104. bool verify_vote_proof(
  105. const TwistBipoint& g,
  106. const TwistBipoint& h,
  107. const std::vector<Proof>& pi,
  108. const std::vector<TwistBipoint>& oldEncryptedVotes,
  109. const std::vector<TwistBipoint>& newEncryptedVotes,
  110. const Twistpoint& freshGenerator,
  111. const Twistpoint& owner
  112. ) const;
  113. // NEW USER PROOFS
  114. std::vector<Proof> generate_proof_of_added_user(
  115. const Scalar& twistBipointSeed,
  116. const Scalar& EGCiphertextSeed,
  117. const std::vector<Scalar>& curveBipointSelfSeeds,
  118. const std::vector<Scalar>& curveBipointOtherSeeds
  119. ) const;
  120. bool verify_proof_of_added_user(
  121. const std::vector<Proof>& pi,
  122. const Twistpoint& currentFreshGenerator,
  123. const Twistpoint& shortTermPublicKey,
  124. const TwistBipoint& curveG,
  125. const TwistBipoint& curveH,
  126. const CurveBipoint& twistG,
  127. const CurveBipoint& twistH,
  128. size_t selfIndex,
  129. const EGCiphertext& userEncryptedScore,
  130. const CurveBipoint& serverEncryptedScore,
  131. const std::vector<std::vector<TwistBipoint>> encryptedVoteMatrix
  132. ) const;
  133. // EPOCH PROOFS
  134. std::vector<Proof> generate_valid_permutation_proof(
  135. const std::vector<std::vector<Scalar>>& permutations,
  136. const std::vector<std::vector<Scalar>>& seeds,
  137. const std::vector<std::vector<Twistpoint>>& commits
  138. ) const;
  139. bool verify_valid_permutation_proof(
  140. const std::vector<Proof>& pi,
  141. const std::vector<std::vector<Twistpoint>>& commits
  142. ) const;
  143. template <typename T>
  144. std::vector<Proof> generate_proof_of_reordering(
  145. const std::vector<std::vector<Scalar>>& permutations,
  146. const std::vector<std::vector<Scalar>>& permutationSeeds,
  147. const std::vector<std::vector<Scalar>>& productSeeds,
  148. const std::vector<T>& oldValues,
  149. const std::vector<std::vector<Twistpoint>>& permutationCommits,
  150. const std::vector<std::vector<T>>& productCommits,
  151. const T& otherG,
  152. const T& otherH
  153. ) const;
  154. template <typename T>
  155. bool verify_proof_of_reordering(
  156. const std::vector<Proof>& pi,
  157. const std::vector<T>& oldValues,
  158. const std::vector<std::vector<Twistpoint>>& permutationCommits,
  159. const std::vector<std::vector<T>>& productCommits,
  160. const T& otherG,
  161. const T& otherH
  162. ) const;
  163. template <typename T>
  164. std::vector<Proof> generate_unbatched_proof_of_reordering(
  165. const std::vector<std::vector<Scalar>>& permutations,
  166. const std::vector<std::vector<Scalar>>& permutationSeeds,
  167. const std::vector<std::vector<Scalar>>& productSeeds,
  168. const std::vector<T>& oldValues,
  169. const std::vector<std::vector<Twistpoint>>& permutationCommits,
  170. const std::vector<std::vector<T>>& productCommits,
  171. const T& otherG,
  172. const T& otherH
  173. ) const;
  174. template <typename T>
  175. bool verify_unbatched_proof_of_reordering(
  176. const std::vector<Proof>& pi,
  177. const std::vector<T>& oldValues,
  178. const std::vector<std::vector<Twistpoint>>& permutationCommits,
  179. const std::vector<std::vector<T>>& productCommits,
  180. const T& otherG,
  181. const T& otherH
  182. ) const;
  183. template <typename T>
  184. std::vector<Proof> generate_batched_proof_of_reordering(
  185. const std::vector<std::vector<Scalar>>& permutations,
  186. const std::vector<std::vector<Scalar>>& permutationSeeds,
  187. const std::vector<std::vector<Scalar>>& productSeeds,
  188. const std::vector<T>& oldValues,
  189. const std::vector<std::vector<Twistpoint>>& permutationCommits,
  190. const std::vector<std::vector<T>>& productCommits,
  191. const T& otherG,
  192. const T& otherH
  193. ) const;
  194. template <typename T>
  195. bool verify_batched_proof_of_reordering(
  196. const std::vector<Proof>& pi,
  197. const std::vector<T>& oldValues,
  198. const std::vector<std::vector<Twistpoint>>& permutationCommits,
  199. const std::vector<std::vector<T>>& productCommits,
  200. const T& otherG,
  201. const T& otherH
  202. ) const;
  203. std::vector<Proof> generate_proof_of_reordering_plus_power(
  204. const std::vector<std::vector<Scalar>>& permutations,
  205. const Scalar& power,
  206. const std::vector<std::vector<Scalar>>& permutationSeeds,
  207. const std::vector<std::vector<Scalar>>& productSeeds,
  208. const std::vector<Twistpoint>& oldValues,
  209. const std::vector<std::vector<Twistpoint>>& permutationCommits,
  210. const std::vector<std::vector<Twistpoint>>& productCommits,
  211. const std::vector<std::vector<Twistpoint>>& seedCommits
  212. ) const;
  213. bool verify_proof_of_reordering_plus_power(
  214. const std::vector<Proof>& pi,
  215. const std::vector<Twistpoint>& oldValues,
  216. const std::vector<std::vector<Twistpoint>>& permutationCommits,
  217. const std::vector<std::vector<Twistpoint>>& productCommits,
  218. const std::vector<std::vector<Twistpoint>>& seedCommits
  219. ) const;
  220. std::vector<Proof> generate_unbatched_proof_of_reordering_plus_power(
  221. const std::vector<std::vector<Scalar>>& permutations,
  222. const Scalar& power,
  223. const std::vector<std::vector<Scalar>>& permutationSeeds,
  224. const std::vector<std::vector<Scalar>>& productSeeds,
  225. const std::vector<Twistpoint>& oldValues,
  226. const std::vector<std::vector<Twistpoint>>& permutationCommits,
  227. const std::vector<std::vector<Twistpoint>>& productCommits,
  228. const std::vector<std::vector<Twistpoint>>& seedCommits
  229. ) const;
  230. bool verify_unbatched_proof_of_reordering_plus_power(
  231. const std::vector<Proof>& pi,
  232. const std::vector<Twistpoint>& oldValues,
  233. const std::vector<std::vector<Twistpoint>>& permutationCommits,
  234. const std::vector<std::vector<Twistpoint>>& productCommits,
  235. const std::vector<std::vector<Twistpoint>>& seedCommits
  236. ) const;
  237. std::vector<Proof> generate_batched_proof_of_reordering_plus_power(
  238. const std::vector<std::vector<Scalar>>& permutations,
  239. const Scalar& power,
  240. const std::vector<std::vector<Scalar>>& permutationSeeds,
  241. const std::vector<std::vector<Scalar>>& productSeeds,
  242. const std::vector<Twistpoint>& oldValues,
  243. const std::vector<std::vector<Twistpoint>>& permutationCommits,
  244. const std::vector<std::vector<Twistpoint>>& productCommits,
  245. const std::vector<std::vector<Twistpoint>>& seedCommits
  246. ) const;
  247. bool verify_batched_proof_of_reordering_plus_power(
  248. const std::vector<Proof>& pi,
  249. const std::vector<Twistpoint>& oldValues,
  250. const std::vector<std::vector<Twistpoint>>& permutationCommits,
  251. const std::vector<std::vector<Twistpoint>>& productCommits,
  252. const std::vector<std::vector<Twistpoint>>& seedCommits
  253. ) const;
  254. std::vector<Proof> generate_user_tally_proofs(
  255. const std::vector<std::vector<Scalar>>& permutations,
  256. const Scalar& power,
  257. const Twistpoint& nextGenerator,
  258. const std::vector<std::vector<Scalar>>& permutationSeeds,
  259. const std::vector<std::vector<Scalar>>& userTallySeeds,
  260. const std::vector<Twistpoint>& currPseudonyms,
  261. const std::vector<Twistpoint>& userTallyMasks,
  262. const std::vector<Twistpoint>& userTallyMessages,
  263. const std::vector<std::vector<Twistpoint>>& permutationCommits,
  264. const std::vector<std::vector<Twistpoint>>& userTallyMaskCommits,
  265. const std::vector<std::vector<Twistpoint>>& userTallyMessageCommits,
  266. const std::vector<std::vector<Twistpoint>>& userTallySeedCommits
  267. ) const;
  268. bool verify_user_tally_proofs(
  269. const std::vector<Proof>& pi,
  270. const Twistpoint& nextGenerator,
  271. const std::vector<Twistpoint>& currPseudonyms,
  272. const std::vector<Twistpoint>& userTallyMasks,
  273. const std::vector<Twistpoint>& userTallyMessages,
  274. const std::vector<std::vector<Twistpoint>>& permutationCommits,
  275. const std::vector<std::vector<Twistpoint>>& userTallyMaskCommits,
  276. const std::vector<std::vector<Twistpoint>>& userTallyMessageCommits,
  277. const std::vector<std::vector<Twistpoint>>& userTallySeedCommits
  278. ) const;
  279. std::vector<Proof> generate_unbatched_user_tally_proofs(
  280. const std::vector<std::vector<Scalar>>& permutations,
  281. const Scalar& power,
  282. const Twistpoint& nextGenerator,
  283. const std::vector<std::vector<Scalar>>& permutationSeeds,
  284. const std::vector<std::vector<Scalar>>& userTallySeeds,
  285. const std::vector<Twistpoint>& currPseudonyms,
  286. const std::vector<Twistpoint>& userTallyMasks,
  287. const std::vector<Twistpoint>& userTallyMessages,
  288. const std::vector<std::vector<Twistpoint>>& permutationCommits,
  289. const std::vector<std::vector<Twistpoint>>& userTallyMaskCommits,
  290. const std::vector<std::vector<Twistpoint>>& userTallyMessageCommits,
  291. const std::vector<std::vector<Twistpoint>>& userTallySeedCommits
  292. ) const;
  293. bool verify_unbatched_user_tally_proofs(
  294. const std::vector<Proof>& pi,
  295. const Twistpoint& nextGenerator,
  296. const std::vector<Twistpoint>& currPseudonyms,
  297. const std::vector<Twistpoint>& userTallyMasks,
  298. const std::vector<Twistpoint>& userTallyMessages,
  299. const std::vector<std::vector<Twistpoint>>& permutationCommits,
  300. const std::vector<std::vector<Twistpoint>>& userTallyMaskCommits,
  301. const std::vector<std::vector<Twistpoint>>& userTallyMessageCommits,
  302. const std::vector<std::vector<Twistpoint>>& userTallySeedCommits
  303. ) const;
  304. std::vector<Proof> generate_batched_user_tally_proofs(
  305. const std::vector<std::vector<Scalar>>& permutations,
  306. const Scalar& power,
  307. const Twistpoint& nextGenerator,
  308. const std::vector<std::vector<Scalar>>& permutationSeeds,
  309. const std::vector<std::vector<Scalar>>& userTallySeeds,
  310. const std::vector<Twistpoint>& currPseudonyms,
  311. const std::vector<Twistpoint>& userTallyMasks,
  312. const std::vector<Twistpoint>& userTallyMessages,
  313. const std::vector<std::vector<Twistpoint>>& permutationCommits,
  314. const std::vector<std::vector<Twistpoint>>& userTallyMaskCommits,
  315. const std::vector<std::vector<Twistpoint>>& userTallyMessageCommits,
  316. const std::vector<std::vector<Twistpoint>>& userTallySeedCommits
  317. ) const;
  318. bool verify_batched_user_tally_proofs(
  319. const std::vector<Proof>& pi,
  320. const Twistpoint& nextGenerator,
  321. const std::vector<Twistpoint>& currPseudonyms,
  322. const std::vector<Twistpoint>& userTallyMasks,
  323. const std::vector<Twistpoint>& userTallyMessages,
  324. const std::vector<std::vector<Twistpoint>>& permutationCommits,
  325. const std::vector<std::vector<Twistpoint>>& userTallyMaskCommits,
  326. const std::vector<std::vector<Twistpoint>>& userTallyMessageCommits,
  327. const std::vector<std::vector<Twistpoint>>& userTallySeedCommits
  328. ) const;
  329. // SERVER AGREEMENT PROOFS
  330. Proof generate_valid_vote_row_proof(
  331. const std::vector<TwistBipoint>& commitment
  332. ) const;
  333. Proof generate_valid_vote_matrix_proof(
  334. const std::vector<std::vector<TwistBipoint>>& commitment
  335. ) const;
  336. Proof generate_valid_user_tally_proof(
  337. const EGCiphertext& commitment
  338. ) const;
  339. Proof generate_valid_server_tally_proof(
  340. const CurveBipoint& commitment
  341. ) const;
  342. Proof generate_valid_pseudonyms_proof(
  343. const std::vector<Twistpoint>& commitment
  344. ) const;
  345. bool verify_valid_vote_row_proof(
  346. const std::vector<Proof>& pi,
  347. const std::vector<TwistBipoint>& commitment
  348. ) const;
  349. bool verify_valid_vote_matrix_proof(
  350. const std::vector<Proof>& pi,
  351. const std::vector<std::vector<TwistBipoint>>& commitment
  352. ) const;
  353. bool verify_valid_user_tally_proof(
  354. const std::vector<Proof>& pi,
  355. const EGCiphertext& commitment
  356. ) const;
  357. bool verify_valid_server_tally_proof(
  358. const std::vector<Proof>& pi,
  359. const CurveBipoint& commitment
  360. ) const;
  361. bool verify_valid_pseudonyms_proof(
  362. const std::vector<Proof>& pi,
  363. const std::vector<Twistpoint>& commitment
  364. ) const;
  365. };
  366. #endif