client.cpp 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. #include "client.hpp"
  2. extern const scalar_t bn_n;
  3. const Scalar PrsonaServer::scalarN(bn_n);
  4. extern const curvepoint_fp_t bn_curvegen;
  5. const Curvepoint PrsonaClient::elGamalGenerator(bn_curvegen);
  6. PrsonaClient::PrsonaClient(const BGNPublicKey& serverPublicKey, const Curvepoint& elGamalBlindGenerator)
  7. : serverPublicKey(serverPublicKey), elGamalBlindGenerator(elGamalBlindGenerator), max_checked(0)
  8. {
  9. longTermPrivateKey.set_random();
  10. decryption_memoizer[elGamalBlindGenerator * max_checked] = max_checked;
  11. }
  12. Curvepoint PrsonaClient::get_long_term_public_key() const
  13. {
  14. return elGamalGenerator * longTermPrivateKey;
  15. }
  16. Curvepoint PrsonaClient::get_short_term_public_key() const
  17. {
  18. return currentFreshGenerator * longTermPrivateKey;
  19. }
  20. void PrsonaClient::receive_score(const Proof& pi, const EGCiphertext& score, const Curvepoint& newGenerator)
  21. {
  22. if (!verify_score_proof(pi))
  23. return;
  24. currentEncryptedScore = score;
  25. currentFreshGenerator = newGenerator;
  26. Curvepoint s, hashedDecrypted;
  27. Scalar decryptionKey = scalarN - longTermPrivateKey;
  28. s = currentEncryptedScore.mask * decryptionKey;
  29. hashedDecrypted = currentEncryptedScore.encryptedMessage + s;
  30. auto lookup = decryption_memoizer.find(hashedDecrypted);
  31. if (lookup != decryption_memoizer.end())
  32. {
  33. currentScore = lookup->second;
  34. return;
  35. }
  36. max_checked++;
  37. Curvepoint decryptionCandidate = elGamalBlindGenerator * max_checked;
  38. while (decryptionCandidate != hashedDecrypted)
  39. {
  40. decryption_memoizer[decryptionCandidate] = max_checked;
  41. decryptionCandidate = decryptionCandidate + elGamalBlindGenerator;
  42. max_checked++;
  43. }
  44. curve_memoizer[decryptionCandidate] = max_checked;
  45. currentScore = max_checked;
  46. }
  47. void PrsonaClient::make_votes(vector<CurveBipoint>& encryptedVotes, vector<Proof>& validVoteProofs, const vector<Scalar>& vote) const
  48. {
  49. encryptedVotes.clear();
  50. validVoteProofs.clear();
  51. for (size_t i = 0; i < vote.size(); i++)
  52. {
  53. CurveBipoint currScore;
  54. serverPublicKey.encrypt(currScore, vote[i]);
  55. encryptedVotes.push_back(currScore);
  56. validVoteProofs.push_back(generate_vote_proof(vote[i], currScore));
  57. }
  58. }
  59. Proof PrsonaClient::generate_reputation_proof() const
  60. {
  61. }
  62. bool PrsonaClient::verify_reputation_proof(const Proof& pi, const PrsonaPublicKey& shortTermPublicKey) const
  63. {
  64. }
  65. Proof PrsonaClient::generate_vote_proof(const Scalar& vote, const CurveBipoint& encryptedVote) const
  66. {
  67. }
  68. bool verify_score_proof(const Proof& pi) const
  69. {
  70. }