server.cpp 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656
  1. #include <iostream>
  2. #include "server.hpp"
  3. /********************
  4. * PUBLIC FUNCTIONS *
  5. ********************/
  6. /*
  7. * CONSTRUCTORS
  8. */
  9. // Used to generate the first server; instantiates BGN for the first time
  10. PrsonaServer::PrsonaServer(size_t numServers)
  11. : numServers(numServers)
  12. {
  13. currentSeed.set_random();
  14. }
  15. // Used for all other servers, so they have the same BGN parameters
  16. PrsonaServer::PrsonaServer(size_t numServers, const BGN& otherBgn)
  17. : numServers(numServers), bgnSystem(otherBgn)
  18. {
  19. currentSeed.set_random();
  20. }
  21. /*
  22. * BASIC PUBLIC SYSTEM INFO GETTERS
  23. */
  24. BGNPublicKey PrsonaServer::get_bgn_public_key() const
  25. {
  26. return bgnSystem.get_public_key();
  27. }
  28. size_t PrsonaServer::get_num_clients() const
  29. {
  30. return currentPseudonyms.size();
  31. }
  32. size_t PrsonaServer::get_num_servers() const
  33. {
  34. return numServers;
  35. }
  36. /*
  37. * FRESH GENERATOR CALCULATION
  38. */
  39. // To calculate the current epoch's generator, start from the base generator,
  40. // then have every server call this function on it iteratively (in any order).
  41. Curvepoint PrsonaServer::add_curr_seed_to_generator(
  42. std::vector<Proof>& pi,
  43. const Curvepoint& currGenerator) const
  44. {
  45. pi.push_back(add_to_generator_proof(currGenerator, currentSeed));
  46. return currGenerator * currentSeed;
  47. }
  48. // To calculate the next epoch's generator, start from the base generator,
  49. // then have every server call this function on it iteratively (in any order).
  50. Curvepoint PrsonaServer::add_next_seed_to_generator(
  51. std::vector<Proof>& pi,
  52. const Curvepoint& currGenerator) const
  53. {
  54. pi.push_back(add_to_generator_proof(currGenerator, nextSeed));
  55. return currGenerator * nextSeed;
  56. }
  57. /*
  58. * ENCRYPTED DATA GETTERS
  59. */
  60. /* Call this in order to get the current encrypted votes cast by a given user
  61. * (who is identified by their short term public key).
  62. * In practice, this is intended for clients,
  63. * who need to know their current votes in order to rerandomize them. */
  64. std::vector<CurveBipoint> PrsonaServer::get_current_votes_by(
  65. Proof& pi, const Curvepoint& shortTermPublicKey) const
  66. {
  67. std::vector<CurveBipoint> retval;
  68. size_t voteSubmitter = binary_search(shortTermPublicKey);
  69. retval = voteMatrix[voteSubmitter];
  70. pi = generate_valid_vote_row_proof(retval);
  71. return retval;
  72. }
  73. std::vector<std::vector<CurveBipoint>> PrsonaServer::get_all_current_votes(
  74. Proof& pi) const
  75. {
  76. pi = generate_valid_vote_matrix_proof(voteMatrix);
  77. return voteMatrix;
  78. }
  79. /* Call this in order to get the current encrypted tally of a given user
  80. * (who is identified by their short term public key).
  81. * In practice, this is intended for clients, so that the servers vouch
  82. * for their ciphertexts being valid as part of their reputation proofs. */
  83. EGCiphertext PrsonaServer::get_current_user_encrypted_tally(
  84. Proof& pi, const Curvepoint& shortTermPublicKey) const
  85. {
  86. EGCiphertext retval;
  87. size_t tallyOwner = binary_search(shortTermPublicKey);
  88. retval = currentUserEncryptedTallies[tallyOwner];
  89. pi = generate_valid_user_tally_proof(retval);
  90. return retval;
  91. }
  92. TwistBipoint PrsonaServer::get_current_server_encrypted_tally(
  93. Proof& pi, const Curvepoint& shortTermPublicKey) const
  94. {
  95. TwistBipoint retval;
  96. size_t tallyOwner = binary_search(shortTermPublicKey);
  97. retval = previousVoteTallies[tallyOwner];
  98. pi = generate_valid_server_tally_proof(retval);
  99. return retval;
  100. }
  101. std::vector<Curvepoint> PrsonaServer::get_current_pseudonyms(Proof& pi) const
  102. {
  103. pi = generate_valid_pseudonyms_proof(currentPseudonyms);
  104. return currentPseudonyms;
  105. }
  106. /*
  107. * PROOF COMMITMENT GETTERS
  108. */
  109. Proof PrsonaServer::get_vote_row_commitment(const Curvepoint& request) const
  110. {
  111. size_t requestID = binary_search(request);
  112. return generate_valid_vote_row_proof(voteMatrix[requestID]);
  113. }
  114. Proof PrsonaServer::get_vote_matrix_commitment() const
  115. {
  116. return generate_valid_vote_matrix_proof(voteMatrix);
  117. }
  118. Proof PrsonaServer::get_user_tally_commitment(const Curvepoint& request) const
  119. {
  120. size_t requestID = binary_search(request);
  121. return generate_valid_user_tally_proof(currentUserEncryptedTallies[requestID]);
  122. }
  123. Proof PrsonaServer::get_server_tally_commitment(const Curvepoint& request) const
  124. {
  125. size_t requestID = binary_search(request);
  126. return generate_valid_server_tally_proof(previousVoteTallies[requestID]);
  127. }
  128. Proof PrsonaServer::get_pseudonyms_commitment() const
  129. {
  130. return generate_valid_pseudonyms_proof(currentPseudonyms);
  131. }
  132. /*
  133. * CLIENT INTERACTIONS
  134. */
  135. /* Add a new client (who is identified only by their short term public key)
  136. * One server will do this, then ask all other servers to import their
  137. * (proven) exported data. */
  138. void PrsonaServer::add_new_client(
  139. std::vector<Proof>& proofOfValidAddition,
  140. const Proof& proofOfValidKey,
  141. const Curvepoint& shortTermPublicKey)
  142. {
  143. if (!verify_ownership_proof(
  144. proofOfValidKey, currentFreshGenerator, shortTermPublicKey))
  145. {
  146. std::cerr << "Could not verify proof of valid key." << std::endl;
  147. return;
  148. }
  149. currentPseudonyms.push_back(shortTermPublicKey);
  150. // The first epoch's score for a new user will be low,
  151. // but will typically converge on an average score quickly
  152. Scalar tallySeed;
  153. TwistBipoint encryptedDefaultTally =
  154. bgnSystem.get_public_key().twistEncrypt(tallySeed, DEFAULT_TALLY);
  155. previousVoteTallies.push_back(encryptedDefaultTally);
  156. Scalar seedForUserTally;
  157. seedForUserTally.set_random();
  158. EGCiphertext newUserEncryptedTally;
  159. newUserEncryptedTally.mask = shortTermPublicKey * seedForUserTally;
  160. newUserEncryptedTally.encryptedMessage =
  161. currentFreshGenerator * seedForUserTally +
  162. elGamalBlindGenerator * DEFAULT_TALLY;
  163. currentUserEncryptedTallies.push_back(newUserEncryptedTally);
  164. // Users are defaulted to casting a neutral vote for others.
  165. CurveBipoint encryptedDefaultVote, encryptedSelfVote;
  166. Scalar currDefaultSeed, currSelfSeed;
  167. encryptedDefaultVote =
  168. bgnSystem.get_public_key().curveEncrypt(currDefaultSeed, DEFAULT_VOTE);
  169. encryptedSelfVote =
  170. bgnSystem.get_public_key().curveEncrypt(currSelfSeed, Scalar(MAX_ALLOWED_VOTE));
  171. std::vector<CurveBipoint> newRow;
  172. std::vector<Scalar> userVoteSeeds;
  173. std::vector<Scalar> otherVoteSeeds;
  174. for (size_t i = 0; i < voteMatrix.size(); i++)
  175. {
  176. Scalar addedSeed;
  177. encryptedDefaultVote = bgnSystem.get_public_key().rerandomize(addedSeed, encryptedDefaultVote);
  178. currDefaultSeed = currDefaultSeed.curveAdd(addedSeed);
  179. otherVoteSeeds.push_back(Scalar());
  180. otherVoteSeeds[i] = currDefaultSeed;
  181. voteMatrix[i].push_back(encryptedDefaultVote);
  182. encryptedDefaultVote = bgnSystem.get_public_key().rerandomize(addedSeed, encryptedDefaultVote);
  183. currDefaultSeed = currDefaultSeed.curveAdd(addedSeed);
  184. userVoteSeeds.push_back(Scalar());
  185. userVoteSeeds[i] = currDefaultSeed;
  186. newRow.push_back(encryptedDefaultVote);
  187. }
  188. // Because we are adding the new user to the end (and then sorting it),
  189. // this last element (bottom right corner) is always the self vote.
  190. userVoteSeeds.push_back(Scalar());
  191. userVoteSeeds[newRow.size()] = currSelfSeed;
  192. otherVoteSeeds.push_back(Scalar());
  193. otherVoteSeeds[newRow.size()] = currSelfSeed;
  194. newRow.push_back(encryptedSelfVote);
  195. voteMatrix.push_back(newRow);
  196. Proof unused;
  197. std::vector<size_t> sortOrder = order_data(unused);
  198. std::vector<Scalar> newUserVoteSeeds;
  199. std::vector<Scalar> newOtherVoteSeeds;
  200. for (size_t i = 0; i < sortOrder.size(); i++)
  201. {
  202. newUserVoteSeeds.push_back(userVoteSeeds[sortOrder[i]]);
  203. newOtherVoteSeeds.push_back(otherVoteSeeds[sortOrder[i]]);
  204. }
  205. proofOfValidAddition = generate_proof_of_added_user(
  206. tallySeed,
  207. seedForUserTally,
  208. newUserVoteSeeds,
  209. newOtherVoteSeeds);
  210. }
  211. // Receive a new vote row from a user (identified by short term public key).
  212. bool PrsonaServer::receive_vote(
  213. const std::vector<Proof>& pi,
  214. const std::vector<CurveBipoint>& newVotes,
  215. const Curvepoint& shortTermPublicKey)
  216. {
  217. size_t voteSubmitter = binary_search(shortTermPublicKey);
  218. std::vector<CurveBipoint> oldVotes = voteMatrix[voteSubmitter];
  219. if (!verify_vote_proof(pi, oldVotes, newVotes, shortTermPublicKey))
  220. return false;
  221. voteMatrix[voteSubmitter] = newVotes;
  222. return true;
  223. }
  224. /*********************
  225. * PRIVATE FUNCTIONS *
  226. *********************/
  227. /*
  228. * CONSTRUCTOR HELPERS
  229. */
  230. const BGN& PrsonaServer::get_bgn_details() const
  231. {
  232. return bgnSystem;
  233. }
  234. bool PrsonaServer::initialize_fresh_generator(
  235. const std::vector<Proof>& pi,
  236. const Curvepoint& firstGenerator)
  237. {
  238. if (!verify_generator_proof(pi, firstGenerator, numServers))
  239. {
  240. std::cerr << "Could not verify generator proof, aborting." << std::endl;
  241. return false;
  242. }
  243. currentFreshGenerator = firstGenerator;
  244. return true;
  245. }
  246. // To calculate the blind generator for ElGamal, start from the base generator,
  247. // then have every server call this function on it iteratively (in any order).
  248. Curvepoint PrsonaServer::add_rand_seed_to_generator(
  249. std::vector<Proof>& pi,
  250. const Curvepoint& currGenerator) const
  251. {
  252. Scalar lambda;
  253. lambda.set_random();
  254. pi.push_back(add_to_generator_proof(currGenerator, lambda));
  255. return currGenerator * lambda;
  256. }
  257. bool PrsonaServer::set_EG_blind_generator(
  258. const std::vector<Proof>& pi,
  259. const Curvepoint& currGenerator)
  260. {
  261. return PrsonaBase::set_EG_blind_generator(pi, currGenerator, numServers);
  262. }
  263. /*
  264. * SCORE TALLYING
  265. */
  266. /* Calculate scores homomorphically (as an individual server would normally)
  267. * and then decrypt them (which the servers would normally work together to do).
  268. *
  269. * Note that since these calculations are just for us, we don't need to do any
  270. * expensive rerandomizations of intermediate values. */
  271. std::vector<Scalar> PrsonaServer::tally_scores()
  272. {
  273. std::vector<Quadripoint> BGNEncryptedTallies;
  274. std::vector<Scalar> decryptedTallies;
  275. for (size_t i = 0; i < voteMatrix.size(); i++)
  276. {
  277. std::vector<Quadripoint> weightedVotes;
  278. // ZIP
  279. for (size_t j = 0; j < previousVoteTallies.size(); j++)
  280. {
  281. Quadripoint curr =
  282. bgnSystem.homomorphic_multiplication_no_rerandomize(
  283. voteMatrix[j][i], previousVoteTallies[j]);
  284. weightedVotes.push_back(curr);
  285. }
  286. // FOLDL
  287. Quadripoint currEncryptedTally = weightedVotes[0];
  288. for (size_t j = 1; j < weightedVotes.size(); j++)
  289. {
  290. currEncryptedTally =
  291. bgnSystem.homomorphic_addition_no_rerandomize(
  292. currEncryptedTally, weightedVotes[j]);
  293. }
  294. // DECRYPT
  295. decryptedTallies.push_back(bgnSystem.decrypt(currEncryptedTally));
  296. }
  297. return decryptedTallies;
  298. }
  299. /* Calculate what the maximum possible score this round was (that is,
  300. * given the current user weights, what was the highest possible score?).
  301. *
  302. * As with individual scores, this also does the decryption that servers
  303. * would ordinarily work together to form. */
  304. Scalar PrsonaServer::get_max_possible_score(Proof& pi)
  305. {
  306. // FOLDL
  307. TwistBipoint currEncryptedVal = previousVoteTallies[0];
  308. for (size_t i = 1; i < previousVoteTallies.size(); i++)
  309. {
  310. currEncryptedVal =
  311. bgnSystem.homomorphic_addition_no_rerandomize(
  312. currEncryptedVal, previousVoteTallies[i]);
  313. }
  314. // DECRYPT
  315. Scalar retval = bgnSystem.decrypt(currEncryptedVal);
  316. pi = generate_proof_of_correct_sum();
  317. return retval;
  318. }
  319. /*
  320. * EPOCH ROUNDS
  321. */
  322. // The first round, going from A_0 to A_0.5
  323. void PrsonaServer::build_up_midway_pseudonyms(
  324. Proof& pi, Curvepoint& nextGenerator)
  325. {
  326. nextSeed.set_random();
  327. nextGenerator = nextGenerator * nextSeed;
  328. currentUserEncryptedTallies.clear();
  329. for (size_t i = 0; i < currentPseudonyms.size(); i++)
  330. currentPseudonyms[i] = currentPseudonyms[i] * nextSeed;
  331. rerandomize_data();
  332. order_data(pi);
  333. }
  334. // In between these rounds, scores are tallied, decrypted,
  335. // and encrypted to fresh user pseudonyms (possible through weird math)
  336. // The second round, going from A_0.5 to A_1
  337. void PrsonaServer::break_down_midway_pseudonyms(
  338. Proof& pi, const Curvepoint& nextGenerator)
  339. {
  340. Scalar inverseSeed = currentSeed.curveInverse();
  341. for (size_t i = 0; i < currentPseudonyms.size(); i++)
  342. {
  343. currentPseudonyms[i] = currentPseudonyms[i] * inverseSeed;
  344. currentUserEncryptedTallies[i].mask =
  345. currentUserEncryptedTallies[i].mask * inverseSeed;
  346. }
  347. currentSeed = nextSeed;
  348. currentFreshGenerator = nextGenerator;
  349. rerandomize_data();
  350. order_data(pi);
  351. }
  352. /*
  353. * DATA MAINTENANCE
  354. */
  355. bool PrsonaServer::import_new_user_update(
  356. const std::vector<Proof>& pi,
  357. const std::vector<TwistBipoint>& otherPreviousVoteTallies,
  358. const std::vector<Curvepoint>& otherCurrentPseudonyms,
  359. const std::vector<EGCiphertext>& otherCurrentUserEncryptedTallies,
  360. const std::vector<std::vector<CurveBipoint>>& otherVoteMatrix)
  361. {
  362. size_t newIndex = 0;
  363. if (!currentPseudonyms.empty())
  364. while (otherCurrentPseudonyms[newIndex] == currentPseudonyms[newIndex])
  365. newIndex++;
  366. Curvepoint shortTermPublicKey = otherCurrentPseudonyms[newIndex];
  367. bool flag = verify_proof_of_added_user(
  368. pi,
  369. currentFreshGenerator,
  370. shortTermPublicKey,
  371. elGamalBlindGenerator,
  372. bgnSystem.get_public_key().get_bipoint_curvegen(),
  373. bgnSystem.get_public_key().get_bipoint_curve_subgroup_gen(),
  374. bgnSystem.get_public_key().get_bipoint_twistgen(),
  375. bgnSystem.get_public_key().get_bipoint_twist_subgroup_gen(),
  376. newIndex,
  377. otherCurrentUserEncryptedTallies[newIndex],
  378. otherPreviousVoteTallies[newIndex],
  379. otherVoteMatrix);
  380. if (!flag)
  381. {
  382. std::cerr << "Other server added new user invalidly, aborting." << std::endl;
  383. return false;
  384. }
  385. for (size_t i = 0; i < otherCurrentPseudonyms.size(); i++)
  386. {
  387. if (i == newIndex)
  388. continue;
  389. size_t otherI = (i > newIndex ? i - 1 : i);
  390. flag = flag && otherCurrentPseudonyms[i] ==
  391. currentPseudonyms[otherI];
  392. flag = flag && otherCurrentUserEncryptedTallies[i] ==
  393. currentUserEncryptedTallies[otherI];
  394. flag = flag && otherPreviousVoteTallies[i] ==
  395. previousVoteTallies[otherI];
  396. for (size_t j = 0; j < otherCurrentPseudonyms.size(); j++)
  397. {
  398. if (j == newIndex)
  399. continue;
  400. size_t otherJ = (j > newIndex ? j - 1 : j);
  401. flag = flag && otherVoteMatrix[i][j] ==
  402. voteMatrix[otherI][otherJ];
  403. }
  404. }
  405. if (!flag)
  406. {
  407. std::cerr << "Other server illicitly changed other value during new user add." << std::endl;
  408. return false;
  409. }
  410. previousVoteTallies = otherPreviousVoteTallies;
  411. currentPseudonyms = otherCurrentPseudonyms;
  412. currentUserEncryptedTallies = otherCurrentUserEncryptedTallies;
  413. voteMatrix = otherVoteMatrix;
  414. return true;
  415. }
  416. void PrsonaServer::import_updates(
  417. const Proof& pi,
  418. const std::vector<TwistBipoint>& otherPreviousVoteTallies,
  419. const std::vector<Curvepoint>& otherCurrentPseudonyms,
  420. const std::vector<EGCiphertext>& otherCurrentUserEncryptedTallies,
  421. const std::vector<std::vector<CurveBipoint>>& otherVoteMatrix)
  422. {
  423. if (!verify_update_proof(pi))
  424. {
  425. std::cerr << "Could not verify valid update." << std::endl;
  426. return;
  427. }
  428. previousVoteTallies = otherPreviousVoteTallies;
  429. currentPseudonyms = otherCurrentPseudonyms;
  430. currentUserEncryptedTallies = otherCurrentUserEncryptedTallies;
  431. voteMatrix = otherVoteMatrix;
  432. }
  433. void PrsonaServer::export_updates(
  434. std::vector<TwistBipoint>& otherPreviousVoteTallies,
  435. std::vector<Curvepoint>& otherCurrentPseudonyms,
  436. std::vector<EGCiphertext>& otherCurrentUserEncryptedTallies,
  437. std::vector<std::vector<CurveBipoint>>& otherVoteMatrix) const
  438. {
  439. otherPreviousVoteTallies = previousVoteTallies;
  440. otherCurrentPseudonyms = currentPseudonyms;
  441. otherCurrentUserEncryptedTallies = currentUserEncryptedTallies;
  442. otherVoteMatrix = voteMatrix;
  443. }
  444. /*
  445. * DATA SAFEKEEPING
  446. */
  447. // Everything needs to be rerandomized during epoch rounds
  448. // NOTE: this may need to add something about proofs later?
  449. void PrsonaServer::rerandomize_data()
  450. {
  451. for (size_t i = 0; i < voteMatrix.size(); i++)
  452. {
  453. for (size_t j = 0; j < voteMatrix[0].size(); j++)
  454. voteMatrix[i][j] = bgnSystem.rerandomize(voteMatrix[i][j]);
  455. bgnSystem.rerandomize(previousVoteTallies[i]);
  456. if (!currentUserEncryptedTallies.empty())
  457. {
  458. Scalar rerandomizer;
  459. rerandomizer.set_random();
  460. currentUserEncryptedTallies[i].mask =
  461. currentUserEncryptedTallies[i].mask +
  462. currentPseudonyms[i] * rerandomizer;
  463. currentUserEncryptedTallies[i].encryptedMessage =
  464. currentUserEncryptedTallies[i].encryptedMessage +
  465. currentFreshGenerator * rerandomizer;
  466. }
  467. }
  468. }
  469. /* This is what powers the "shuffle"; really, as pseudonyms get updated,
  470. * the pseudonyms are no longer in the order prescribed by operator<().
  471. * So, we put them (and everything else) back into that order,
  472. * effectively shuffling them (and making lookups easier later on). */
  473. std::vector<size_t> PrsonaServer::order_data(Proof& pi)
  474. {
  475. std::vector<size_t> retval;
  476. // SortingType's index member allows us to replicate the "sort" across
  477. std::vector<SortingType> sortTracker;
  478. for (size_t i = 0; i < currentPseudonyms.size(); i++)
  479. {
  480. SortingType curr;
  481. curr.pseudonym = currentPseudonyms[i];
  482. curr.index = i;
  483. sortTracker.push_back(curr);
  484. }
  485. std::sort(sortTracker.begin(), sortTracker.end());
  486. // Order all other data in the same way, for consistency
  487. std::vector<Curvepoint> newPseudonyms;
  488. std::vector<TwistBipoint> newVoteTallies;
  489. std::vector<EGCiphertext> newUserEncryptedTallies;
  490. std::vector<std::vector<CurveBipoint>> newVoteMatrix;
  491. for (size_t i = 0; i < sortTracker.size(); i++)
  492. {
  493. newPseudonyms.push_back(sortTracker[i].pseudonym);
  494. newVoteTallies.push_back(previousVoteTallies[sortTracker[i].index]);
  495. if (!currentUserEncryptedTallies.empty())
  496. {
  497. newUserEncryptedTallies.push_back(
  498. currentUserEncryptedTallies[sortTracker[i].index]);
  499. }
  500. std::vector<CurveBipoint> currNewRow;
  501. for (size_t j = 0; j < currentPseudonyms.size(); j++)
  502. {
  503. currNewRow.push_back(
  504. voteMatrix[sortTracker[i].index][sortTracker[j].index]);
  505. }
  506. newVoteMatrix.push_back(currNewRow);
  507. retval.push_back(sortTracker[i].index);
  508. }
  509. previousVoteTallies = newVoteTallies;
  510. currentPseudonyms = newPseudonyms;
  511. currentUserEncryptedTallies = newUserEncryptedTallies;
  512. voteMatrix = newVoteMatrix;
  513. pi = generate_proof_of_shuffle();
  514. return retval;
  515. }
  516. /*
  517. * BINARY SEARCH
  518. */
  519. // Completely normal binary search
  520. size_t PrsonaServer::binary_search(const Curvepoint& index) const
  521. {
  522. return PrsonaBase::binary_search(currentPseudonyms, index);
  523. }
  524. /*
  525. * VALID VOTE PROOFS
  526. */
  527. bool PrsonaServer::verify_vote_proof(
  528. const std::vector<Proof>& pi,
  529. const std::vector<CurveBipoint>& oldVotes,
  530. const std::vector<CurveBipoint>& newVotes,
  531. const Curvepoint& shortTermPublicKey) const
  532. {
  533. const BGNPublicKey& pubKey = bgnSystem.get_public_key();
  534. return PrsonaBase::verify_vote_proof(
  535. pubKey.get_bipoint_curvegen(),
  536. pubKey.get_bipoint_curve_subgroup_gen(),
  537. pi,
  538. oldVotes,
  539. newVotes,
  540. currentFreshGenerator,
  541. shortTermPublicKey);
  542. }