|
@@ -1,7 +1,6 @@
|
|
|
#include <iostream>
|
|
|
|
|
|
#include "client.hpp"
|
|
|
-#include "serverEntity.hpp"
|
|
|
|
|
|
/********************
|
|
|
* PUBLIC FUNCTIONS *
|
|
@@ -15,13 +14,13 @@ PrsonaClient::PrsonaClient(
|
|
|
const std::vector<Proof>& generatorProof,
|
|
|
const Curvepoint& elGamalBlindGenerator,
|
|
|
const BGNPublicKey& serverPublicKey,
|
|
|
- const PrsonaServerEntity* servers)
|
|
|
+ size_t numServers)
|
|
|
: serverPublicKey(serverPublicKey),
|
|
|
- servers(servers),
|
|
|
+ numServers(numServers),
|
|
|
max_checked(0)
|
|
|
{
|
|
|
set_EG_blind_generator(
|
|
|
- generatorProof, elGamalBlindGenerator, servers->get_num_servers());
|
|
|
+ generatorProof, elGamalBlindGenerator, numServers);
|
|
|
|
|
|
longTermPrivateKey.set_random();
|
|
|
inversePrivateKey = longTermPrivateKey.curveMultInverse();
|
|
@@ -55,14 +54,12 @@ Curvepoint PrsonaClient::get_short_term_public_key(Proof &pi) const
|
|
|
* but it doesn't behave correctly when adding new clients after this one. */
|
|
|
std::vector<CurveBipoint> PrsonaClient::make_votes(
|
|
|
std::vector<Proof>& validVoteProof,
|
|
|
- const Proof& serverProof,
|
|
|
+ const std::vector<Proof>& serverProof,
|
|
|
const std::vector<CurveBipoint>& oldEncryptedVotes,
|
|
|
const std::vector<Scalar>& votes,
|
|
|
const std::vector<bool>& replaces) const
|
|
|
{
|
|
|
- Curvepoint shortTermPublicKey = get_short_term_public_key();
|
|
|
-
|
|
|
- if (!verify_valid_vote_row_proof(serverProof, shortTermPublicKey, oldEncryptedVotes))
|
|
|
+ if (!verify_valid_vote_row_proof(serverProof, oldEncryptedVotes))
|
|
|
{
|
|
|
std::cerr << "Could not verify proof of valid votes." << std::endl;
|
|
|
return oldEncryptedVotes;
|
|
@@ -92,9 +89,10 @@ std::vector<CurveBipoint> PrsonaClient::make_votes(
|
|
|
|
|
|
// Get a new fresh generator (happens at initialization and during each epoch)
|
|
|
bool PrsonaClient::receive_fresh_generator(
|
|
|
- const std::vector<Proof>& pi, const Curvepoint& freshGenerator)
|
|
|
+ const std::vector<Proof>& pi,
|
|
|
+ const Curvepoint& freshGenerator)
|
|
|
{
|
|
|
- if (!verify_generator_proof(pi, freshGenerator, servers->get_num_servers()))
|
|
|
+ if (!verify_generator_proof(pi, freshGenerator, numServers))
|
|
|
{
|
|
|
std::cerr << "Issue verifying fresh generator proof." << std::endl;
|
|
|
return false;
|
|
@@ -105,15 +103,11 @@ bool PrsonaClient::receive_fresh_generator(
|
|
|
}
|
|
|
|
|
|
// Receive a new encrypted score from the servers (each epoch)
|
|
|
-bool PrsonaClient::receive_vote_tally()
|
|
|
+bool PrsonaClient::receive_vote_tally(
|
|
|
+ const std::vector<Proof>& pi,
|
|
|
+ const EGCiphertext& score)
|
|
|
{
|
|
|
- Proof pi;
|
|
|
- Curvepoint shortTermPublicKey = get_short_term_public_key();
|
|
|
-
|
|
|
- EGCiphertext score =
|
|
|
- servers->get_current_user_encrypted_tally(pi, shortTermPublicKey);
|
|
|
-
|
|
|
- if (!verify_valid_user_tally_proof(pi, shortTermPublicKey, score))
|
|
|
+ if (!verify_valid_user_tally_proof(pi, score))
|
|
|
{
|
|
|
std::cerr << "Could not verify proof of valid tally." << std::endl;
|
|
|
return false;
|
|
@@ -124,38 +118,38 @@ bool PrsonaClient::receive_vote_tally()
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
-bool PrsonaClient::receive_new_user_data(const std::vector<Proof>& mainProof)
|
|
|
+bool PrsonaClient::receive_new_user_data(
|
|
|
+ const std::vector<Proof>& mainProof,
|
|
|
+ const std::vector<Proof>& serverEncryptedScoreProof,
|
|
|
+ const TwistBipoint& serverEncryptedScore,
|
|
|
+ const std::vector<Proof>& userEncryptedScoreProof,
|
|
|
+ const EGCiphertext& userEncryptedScore,
|
|
|
+ const std::vector<Proof>& voteMatrixProof,
|
|
|
+ const std::vector<std::vector<CurveBipoint>>& encryptedVoteMatrix,
|
|
|
+ const std::vector<Proof>& pseudonymsProof,
|
|
|
+ const std::vector<Curvepoint>& currentPseudonyms)
|
|
|
{
|
|
|
- Proof currProof;
|
|
|
Curvepoint shortTermPublicKey = get_short_term_public_key();
|
|
|
|
|
|
- TwistBipoint serverEncryptedScore =
|
|
|
- servers->get_current_server_encrypted_tally(currProof, shortTermPublicKey);
|
|
|
- if (!verify_valid_server_tally_proof(currProof, shortTermPublicKey, serverEncryptedScore))
|
|
|
+ if (!verify_valid_server_tally_proof(serverEncryptedScoreProof, serverEncryptedScore))
|
|
|
{
|
|
|
std::cerr << "Could not verify preliminary proof of server encrypted tally." << std::endl;
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
- EGCiphertext userEncryptedScore =
|
|
|
- servers->get_current_user_encrypted_tally(currProof, shortTermPublicKey);
|
|
|
- if (!verify_valid_user_tally_proof(currProof, shortTermPublicKey, userEncryptedScore))
|
|
|
+ if (!verify_valid_user_tally_proof(userEncryptedScoreProof, userEncryptedScore))
|
|
|
{
|
|
|
std::cerr << "Could not verify preliminary proof of user encrypted tally." << std::endl;
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
- std::vector<std::vector<CurveBipoint>> encryptedVoteMatrix =
|
|
|
- servers->get_all_current_votes(currProof);
|
|
|
- if (!verify_valid_vote_matrix_proof(currProof, encryptedVoteMatrix))
|
|
|
+ if (!verify_valid_vote_matrix_proof(voteMatrixProof, encryptedVoteMatrix))
|
|
|
{
|
|
|
std::cerr << "Could not verify preliminary proof of encrypted votes." << std::endl;
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
- std::vector<Curvepoint> currentPseudonyms =
|
|
|
- servers->get_current_pseudonyms(currProof);
|
|
|
- if (!verify_valid_pseudonyms_proof(currProof, currentPseudonyms))
|
|
|
+ if (!verify_valid_pseudonyms_proof(pseudonymsProof, currentPseudonyms))
|
|
|
{
|
|
|
std::cerr << "Could not verify preliminary proof of pseudonyms." << std::endl;
|
|
|
return false;
|
|
@@ -199,7 +193,8 @@ bool PrsonaClient::receive_new_user_data(const std::vector<Proof>& mainProof)
|
|
|
|
|
|
// A pretty straightforward range proof (generation)
|
|
|
std::vector<Proof> PrsonaClient::generate_reputation_proof(
|
|
|
- const Scalar& threshold) const
|
|
|
+ const Scalar& threshold,
|
|
|
+ size_t numClients) const
|
|
|
{
|
|
|
Proof ownershipProof = generate_ownership_proof();
|
|
|
|
|
@@ -209,19 +204,17 @@ std::vector<Proof> PrsonaClient::generate_reputation_proof(
|
|
|
currentScore,
|
|
|
threshold,
|
|
|
inversePrivateKey,
|
|
|
- servers->get_num_clients());
|
|
|
+ numClients);
|
|
|
}
|
|
|
|
|
|
bool PrsonaClient::verify_reputation_proof(
|
|
|
const std::vector<Proof>& pi,
|
|
|
const Curvepoint& shortTermPublicKey,
|
|
|
- const Scalar& threshold) const
|
|
|
+ const Scalar& threshold,
|
|
|
+ const std::vector<Proof>& encryptedScoreProof,
|
|
|
+ const EGCiphertext& encryptedScore) const
|
|
|
{
|
|
|
- Proof serverProof;
|
|
|
- EGCiphertext encryptedScore =
|
|
|
- servers->get_current_user_encrypted_tally(serverProof, shortTermPublicKey);
|
|
|
-
|
|
|
- if (!verify_valid_user_tally_proof(serverProof, shortTermPublicKey, encryptedScore))
|
|
|
+ if (!verify_valid_user_tally_proof(encryptedScoreProof, encryptedScore))
|
|
|
{
|
|
|
std::cerr << "Error getting score from server, aborting." << std::endl;
|
|
|
return false;
|
|
@@ -310,70 +303,3 @@ std::vector<Proof> PrsonaClient::generate_vote_proof(
|
|
|
seeds,
|
|
|
votes);
|
|
|
}
|
|
|
-
|
|
|
-/*
|
|
|
- * SERVER AGREEMENT PROOFS
|
|
|
- */
|
|
|
-
|
|
|
-bool PrsonaClient::verify_valid_vote_row_proof(
|
|
|
- const Proof& pi,
|
|
|
- const Curvepoint& shortTermPublicKey,
|
|
|
- const std::vector<CurveBipoint>& commitment) const
|
|
|
-{
|
|
|
- std::vector<Proof> fullProof;
|
|
|
- fullProof.push_back(pi);
|
|
|
-
|
|
|
- servers->get_other_vote_row_commitments(fullProof, shortTermPublicKey);
|
|
|
-
|
|
|
- return PrsonaBase::verify_valid_vote_row_proof(fullProof, commitment);
|
|
|
-}
|
|
|
-
|
|
|
-bool PrsonaClient::verify_valid_vote_matrix_proof(
|
|
|
- const Proof& pi,
|
|
|
- const std::vector<std::vector<CurveBipoint>>& commitment) const
|
|
|
-{
|
|
|
- std::vector<Proof> fullProof;
|
|
|
- fullProof.push_back(pi);
|
|
|
-
|
|
|
- servers->get_other_vote_matrix_commitments(fullProof);
|
|
|
-
|
|
|
- return PrsonaBase::verify_valid_vote_matrix_proof(fullProof, commitment);
|
|
|
-}
|
|
|
-
|
|
|
-bool PrsonaClient::verify_valid_user_tally_proof(
|
|
|
- const Proof& pi,
|
|
|
- const Curvepoint& shortTermPublicKey,
|
|
|
- const EGCiphertext& commitment) const
|
|
|
-{
|
|
|
- std::vector<Proof> fullProof;
|
|
|
- fullProof.push_back(pi);
|
|
|
-
|
|
|
- servers->get_other_user_tally_commitments(fullProof, shortTermPublicKey);
|
|
|
-
|
|
|
- return PrsonaBase::verify_valid_user_tally_proof(fullProof, commitment);
|
|
|
-}
|
|
|
-
|
|
|
-bool PrsonaClient::verify_valid_server_tally_proof(
|
|
|
- const Proof& pi,
|
|
|
- const Curvepoint& shortTermPublicKey,
|
|
|
- const TwistBipoint& commitment) const
|
|
|
-{
|
|
|
- std::vector<Proof> fullProof;
|
|
|
- fullProof.push_back(pi);
|
|
|
-
|
|
|
- servers->get_other_server_tally_commitments(fullProof, shortTermPublicKey);
|
|
|
-
|
|
|
- return PrsonaBase::verify_valid_server_tally_proof(fullProof, commitment);
|
|
|
-}
|
|
|
-
|
|
|
-bool PrsonaClient::verify_valid_pseudonyms_proof(
|
|
|
- const Proof& pi,
|
|
|
- const std::vector<Curvepoint>& commitment) const
|
|
|
-{
|
|
|
- std::vector<Proof> fullProof;
|
|
|
- fullProof.push_back(pi);
|
|
|
-
|
|
|
- servers->get_other_pseudonyms_commitments(fullProof);
|
|
|
-
|
|
|
- return PrsonaBase::verify_valid_pseudonyms_proof(fullProof, commitment);
|
|
|
-}
|