base.hpp 17 KB

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