123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 |
- #include "client.hpp"
- extern const scalar_t bn_n;
- const Scalar PrsonaServer::scalarN(bn_n);
- extern const curvepoint_fp_t bn_curvegen;
- const Curvepoint PrsonaClient::elGamalGenerator(bn_curvegen);
- PrsonaClient::PrsonaClient(const BGNPublicKey& serverPublicKey, const Curvepoint& elGamalBlindGenerator)
- : serverPublicKey(serverPublicKey), elGamalBlindGenerator(elGamalBlindGenerator), max_checked(0)
- {
- longTermPrivateKey.set_random();
- decryption_memoizer[elGamalBlindGenerator * max_checked] = max_checked;
- }
- Curvepoint PrsonaClient::get_long_term_public_key() const
- {
- return elGamalGenerator * longTermPrivateKey;
- }
- Curvepoint PrsonaClient::get_short_term_public_key() const
- {
- return currentFreshGenerator * longTermPrivateKey;
- }
- void PrsonaClient::receive_score(const Proof& pi, const EGCiphertext& score, const Curvepoint& newGenerator)
- {
- if (!verify_score_proof(pi))
- return;
- currentEncryptedScore = score;
- currentFreshGenerator = newGenerator;
- Curvepoint s, hashedDecrypted;
- Scalar decryptionKey = scalarN - longTermPrivateKey;
- s = currentEncryptedScore.mask * decryptionKey;
- hashedDecrypted = currentEncryptedScore.encryptedMessage + s;
-
- auto lookup = decryption_memoizer.find(hashedDecrypted);
- if (lookup != decryption_memoizer.end())
- {
- currentScore = lookup->second;
- return;
- }
- max_checked++;
- Curvepoint decryptionCandidate = elGamalBlindGenerator * max_checked;
- while (decryptionCandidate != hashedDecrypted)
- {
- decryption_memoizer[decryptionCandidate] = max_checked;
- decryptionCandidate = decryptionCandidate + elGamalBlindGenerator;
- max_checked++;
- }
- curve_memoizer[decryptionCandidate] = max_checked;
- currentScore = max_checked;
- }
- void PrsonaClient::make_votes(vector<CurveBipoint>& encryptedVotes, vector<Proof>& validVoteProofs, const vector<Scalar>& vote) const
- {
- encryptedVotes.clear();
- validVoteProofs.clear();
- for (size_t i = 0; i < vote.size(); i++)
- {
- CurveBipoint currScore;
- serverPublicKey.encrypt(currScore, vote[i]);
- encryptedVotes.push_back(currScore);
- validVoteProofs.push_back(generate_vote_proof(vote[i], currScore));
- }
- }
- Proof PrsonaClient::generate_reputation_proof() const
- {
-
- }
- bool PrsonaClient::verify_reputation_proof(const Proof& pi, const PrsonaPublicKey& shortTermPublicKey) const
- {
- }
- Proof PrsonaClient::generate_vote_proof(const Scalar& vote, const CurveBipoint& encryptedVote) const
- {
- }
- bool verify_score_proof(const Proof& pi) const
- {
- }
|