|
@@ -17,6 +17,8 @@ PrsonaServer::PrsonaServer(
|
|
|
: numServers(numServers)
|
|
|
{
|
|
|
currentSeed.set_random();
|
|
|
+
|
|
|
+ decryptMtx = new std::mutex();
|
|
|
}
|
|
|
|
|
|
// Used for all other servers, so they have the same BGN parameters
|
|
@@ -26,6 +28,98 @@ PrsonaServer::PrsonaServer(
|
|
|
: numServers(numServers), bgnSystem(otherBgn)
|
|
|
{
|
|
|
currentSeed.set_random();
|
|
|
+
|
|
|
+ decryptMtx = new std::mutex();
|
|
|
+}
|
|
|
+
|
|
|
+PrsonaServer::PrsonaServer(
|
|
|
+ const PrsonaServer& other)
|
|
|
+{
|
|
|
+ copy(other);
|
|
|
+}
|
|
|
+
|
|
|
+PrsonaServer::PrsonaServer(
|
|
|
+ PrsonaServer&& other)
|
|
|
+{
|
|
|
+ numServers = std::move(other.numServers);
|
|
|
+
|
|
|
+ decryptMtx = other.decryptMtx;
|
|
|
+ other.decryptMtx = NULL;
|
|
|
+
|
|
|
+ bgnSystem = std::move(other.bgnSystem);
|
|
|
+ currentSeed = std::move(other.currentSeed);
|
|
|
+ nextSeed = std::move(other.nextSeed);
|
|
|
+ currentGeneratorProof = std::move(other.currentGeneratorProof);
|
|
|
+ currentFreshGenerator = std::move(other.currentFreshGenerator);
|
|
|
+ previousVoteTallies = std::move(other.previousVoteTallies);
|
|
|
+ currentPseudonyms = std::move(other.currentPseudonyms);
|
|
|
+ currentUserEncryptedTallies = std::move(other.currentUserEncryptedTallies);
|
|
|
+ voteMatrix = std::move(other.voteMatrix);
|
|
|
+}
|
|
|
+
|
|
|
+PrsonaServer &PrsonaServer::operator=(
|
|
|
+ const PrsonaServer& other)
|
|
|
+{
|
|
|
+ if (&other != this)
|
|
|
+ {
|
|
|
+ remove();
|
|
|
+ copy(other);
|
|
|
+ }
|
|
|
+
|
|
|
+ return *this;
|
|
|
+}
|
|
|
+
|
|
|
+PrsonaServer &PrsonaServer::operator=(
|
|
|
+ PrsonaServer&& other)
|
|
|
+{
|
|
|
+ if (&other != this)
|
|
|
+ {
|
|
|
+ remove();
|
|
|
+
|
|
|
+ numServers = std::move(other.numServers);
|
|
|
+
|
|
|
+ decryptMtx = other.decryptMtx;
|
|
|
+ other.decryptMtx = new std::mutex();
|
|
|
+
|
|
|
+ bgnSystem = std::move(other.bgnSystem);
|
|
|
+ currentSeed = std::move(other.currentSeed);
|
|
|
+ nextSeed = std::move(other.nextSeed);
|
|
|
+ currentGeneratorProof = std::move(other.currentGeneratorProof);
|
|
|
+ currentFreshGenerator = std::move(other.currentFreshGenerator);
|
|
|
+ previousVoteTallies = std::move(other.previousVoteTallies);
|
|
|
+ currentPseudonyms = std::move(other.currentPseudonyms);
|
|
|
+ currentUserEncryptedTallies = std::move(other.currentUserEncryptedTallies);
|
|
|
+ voteMatrix = std::move(other.voteMatrix);
|
|
|
+ }
|
|
|
+
|
|
|
+ return *this;
|
|
|
+}
|
|
|
+
|
|
|
+PrsonaServer::~PrsonaServer()
|
|
|
+{
|
|
|
+ remove();
|
|
|
+}
|
|
|
+
|
|
|
+void PrsonaServer::copy(
|
|
|
+ const PrsonaServer& other)
|
|
|
+{
|
|
|
+ numServers = other.numServers;
|
|
|
+ decryptMtx = new std::mutex();
|
|
|
+ bgnSystem = other.bgnSystem;
|
|
|
+ currentSeed = other.currentSeed;
|
|
|
+ nextSeed = other.nextSeed;
|
|
|
+ currentGeneratorProof = other.currentGeneratorProof;
|
|
|
+ currentFreshGenerator = other.currentFreshGenerator;
|
|
|
+ previousVoteTallies = other.previousVoteTallies;
|
|
|
+ currentPseudonyms = other.currentPseudonyms;
|
|
|
+ currentUserEncryptedTallies = other.currentUserEncryptedTallies;
|
|
|
+ voteMatrix = other.voteMatrix;
|
|
|
+}
|
|
|
+
|
|
|
+void PrsonaServer::remove()
|
|
|
+{
|
|
|
+ delete decryptMtx;
|
|
|
+ decryptMtx = NULL;
|
|
|
}
|
|
|
|
|
|
/*
|
|
@@ -407,14 +501,16 @@ void homomorphic_addition_r(
|
|
|
void tally_r(
|
|
|
void *a,
|
|
|
void *b,
|
|
|
- const void *c,
|
|
|
+ void *c,
|
|
|
const void *d,
|
|
|
+ const void *e,
|
|
|
size_t i)
|
|
|
{
|
|
|
- BGN *bgnSystem = (BGN *) a;
|
|
|
- Scalar *dst = (Scalar *) b;
|
|
|
- const std::vector<CurveBipoint> *previousVoteTallies = (const std::vector<CurveBipoint> *) c;
|
|
|
- const std::vector<std::vector<TwistBipoint>> *voteMatrix = (const std::vector<std::vector<TwistBipoint>> *) d;
|
|
|
+ std::mutex *decryptMtx = (std::mutex *) a;
|
|
|
+ BGN *bgnSystem = (BGN *) b;
|
|
|
+ Scalar *dst = (Scalar *) c;
|
|
|
+ const std::vector<CurveBipoint> *previousVoteTallies = (const std::vector<CurveBipoint> *) d;
|
|
|
+ const std::vector<std::vector<TwistBipoint>> *voteMatrix = (const std::vector<std::vector<TwistBipoint>> *) e;
|
|
|
|
|
|
Quadripoint *weightedVotes = new Quadripoint[previousVoteTallies->size()];
|
|
|
std::vector<std::thread> parallelizedMults;
|
|
@@ -429,6 +525,7 @@ void tally_r(
|
|
|
homomorphic_addition_r(bgnSystem, weightedVotes, previousVoteTallies->size());
|
|
|
|
|
|
// DECRYPT
|
|
|
+ std::unique_lock<std::mutex> lck(*decryptMtx);
|
|
|
*dst = bgnSystem->decrypt(weightedVotes[0]);
|
|
|
|
|
|
delete [] weightedVotes;
|
|
@@ -446,7 +543,7 @@ std::vector<Scalar> PrsonaServer::tally_scores()
|
|
|
std::vector<std::thread> parallelizedTallies;
|
|
|
|
|
|
for (size_t i = 0; i < voteMatrix.size(); i++)
|
|
|
- parallelizedTallies.push_back(std::thread(tally_r, &bgnSystem, decryptedTallies + i, &previousVoteTallies, &voteMatrix, i));
|
|
|
+ parallelizedTallies.push_back(std::thread(tally_r, decryptMtx, &bgnSystem, decryptedTallies + i, &previousVoteTallies, &voteMatrix, i));
|
|
|
for (size_t i = 0; i < parallelizedTallies.size(); i++)
|
|
|
parallelizedTallies[i].join();
|
|
|
|
|
@@ -470,6 +567,7 @@ Scalar PrsonaServer::get_max_possible_score()
|
|
|
currEncryptedVal = bgnSystem.homomorphic_addition_no_rerandomize(currEncryptedVal, previousVoteTallies[i]);
|
|
|
|
|
|
// DECRYPT
|
|
|
+ std::unique_lock<std::mutex> lck(*decryptMtx);
|
|
|
Scalar retval = bgnSystem.decrypt(currEncryptedVal);
|
|
|
|
|
|
return retval;
|
|
@@ -1826,6 +1924,7 @@ bool PrsonaServer::verify_vote_proof(
|
|
|
void PrsonaServer::print_scores(
|
|
|
const std::vector<CurveBipoint>& scores)
|
|
|
{
|
|
|
+ std::unique_lock<std::mutex> lck(*decryptMtx);
|
|
|
std::cout << "[";
|
|
|
for (size_t i = 0; i < scores.size(); i++)
|
|
|
std::cout << bgnSystem.decrypt(scores[i]) << (i == scores.size() - 1 ? "]" : " ");
|