|
@@ -27,16 +27,17 @@ using socket_t = boost::asio::ip::tcp::socket;
|
|
#include "prg_aes_impl.h"
|
|
#include "prg_aes_impl.h"
|
|
#include "block.h"
|
|
#include "block.h"
|
|
#include "duoram-utils.h"
|
|
#include "duoram-utils.h"
|
|
|
|
+#include "readvectors.h"
|
|
#include "duoram-read.h"
|
|
#include "duoram-read.h"
|
|
#include "duoram-refresh.h"
|
|
#include "duoram-refresh.h"
|
|
#include "duoram-write.h"
|
|
#include "duoram-write.h"
|
|
-#include "readvectors.h"
|
|
|
|
|
|
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void accept_conncections_from_Pb(boost::asio::io_context&io_context, std::vector<socket_t>& sockets_, int port, size_t j)
|
|
void accept_conncections_from_Pb(boost::asio::io_context&io_context, std::vector<socket_t>& sockets_, int port, size_t j)
|
|
{
|
|
{
|
|
- tcp::acceptor acceptor_a(io_context, tcp::endpoint(tcp::v4(), port));
|
|
|
|
|
|
+ tcp::acceptor acceptor_a(io_context, tcp::endpoint(tcp::v4(), port));
|
|
tcp::socket sb_a(acceptor_a.accept());
|
|
tcp::socket sb_a(acceptor_a.accept());
|
|
sockets_[j] = std::move(sb_a);
|
|
sockets_[j] = std::move(sb_a);
|
|
}
|
|
}
|
|
@@ -46,34 +47,34 @@ void accept_conncections_from_Pb(boost::asio::io_context&io_context, std::vector
|
|
int main(const int argc, const char * argv[])
|
|
int main(const int argc, const char * argv[])
|
|
{
|
|
{
|
|
|
|
|
|
- size_t expo = atoi(argv[3]);
|
|
|
|
- size_t db_nitems = 1ULL << expo;
|
|
|
|
- size_t number_of_writes = atoi(argv[4]);
|
|
|
|
- size_t number_of_ind_reads = atoi(argv[5]);
|
|
|
|
- size_t number_of_dep_reads = atoi(argv[6]);
|
|
|
|
- size_t number_of_accesses = atoi(argv[7]);
|
|
|
|
|
|
+ size_t expo = atoi(argv[3]);
|
|
|
|
+ size_t db_nitems = 1ULL << expo;
|
|
|
|
+ size_t number_of_writes = atoi(argv[4]);
|
|
|
|
+ size_t number_of_ind_reads = atoi(argv[5]);
|
|
|
|
+ size_t number_of_dep_reads = atoi(argv[6]);
|
|
|
|
+ size_t number_of_accesses = atoi(argv[7]);
|
|
|
|
|
|
- reading_temp = (DB_t *) std::aligned_alloc(sizeof(__m256i), db_nitems * sizeof(DB_t));
|
|
|
|
- DB = (DB_t *) std::aligned_alloc(sizeof(__m256i), db_nitems * sizeof(DB_t));
|
|
|
|
- updated_DB = (DB_t *) std::aligned_alloc(sizeof(__m256i), db_nitems * sizeof(DB_t));
|
|
|
|
- blinded_DB = (DB_t *) std::aligned_alloc(sizeof(__m256i), db_nitems * sizeof(DB_t));
|
|
|
|
|
|
+ reading_temp = (DB_t *) std::aligned_alloc(sizeof(__m256i), db_nitems * sizeof(DB_t));
|
|
|
|
+ DB = (DB_t *) std::aligned_alloc(sizeof(__m256i), db_nitems * sizeof(DB_t));
|
|
|
|
+ updated_DB = (DB_t *) std::aligned_alloc(sizeof(__m256i), db_nitems * sizeof(DB_t));
|
|
|
|
+ blinded_DB = (DB_t *) std::aligned_alloc(sizeof(__m256i), db_nitems * sizeof(DB_t));
|
|
|
|
|
|
- blinded_DB_recv = (DB_t *) std::aligned_alloc(sizeof(__m256i), db_nitems * sizeof(DB_t));
|
|
|
|
- updated_blinded_DB_recv = (DB_t *) std::aligned_alloc(sizeof(__m256i), db_nitems * sizeof(DB_t));
|
|
|
|
- b = (DB_t *) std::aligned_alloc(sizeof(__m256i), db_nitems * sizeof(DB_t));
|
|
|
|
- c = (DB_t *) std::aligned_alloc(sizeof(__m256i), db_nitems * sizeof(DB_t));
|
|
|
|
- d = (DB_t *) std::aligned_alloc(sizeof(__m256i), db_nitems * sizeof(DB_t));
|
|
|
|
|
|
+ blinded_DB_recv = (DB_t *) std::aligned_alloc(sizeof(__m256i), db_nitems * sizeof(DB_t));
|
|
|
|
+ updated_blinded_DB_recv = (DB_t *) std::aligned_alloc(sizeof(__m256i), db_nitems * sizeof(DB_t));
|
|
|
|
+
|
|
|
|
+ b = (DB_t *) std::aligned_alloc(sizeof(__m256i), db_nitems * sizeof(DB_t));
|
|
|
|
+ c = (DB_t *) std::aligned_alloc(sizeof(__m256i), db_nitems * sizeof(DB_t));
|
|
|
|
+ d = (DB_t *) std::aligned_alloc(sizeof(__m256i), db_nitems * sizeof(DB_t));
|
|
|
|
|
|
- reading_b = (int8_t *) malloc(db_nitems * sizeof(int8_t));
|
|
|
|
- reading_c = (int8_t *) malloc(db_nitems * sizeof(int8_t));
|
|
|
|
- reading_d = (int8_t *) malloc(db_nitems * sizeof(int8_t));
|
|
|
|
- writing_b = (int8_t *) malloc(db_nitems * sizeof(int8_t));
|
|
|
|
- writing_c = (int8_t *) malloc(db_nitems * sizeof(int8_t));
|
|
|
|
- writing_d = (int8_t *) malloc(db_nitems * sizeof(int8_t));
|
|
|
|
|
|
+ reading_b = (int8_t *) malloc(db_nitems * sizeof(int8_t));
|
|
|
|
+ reading_c = (int8_t *) malloc(db_nitems * sizeof(int8_t));
|
|
|
|
+ reading_d = (int8_t *) malloc(db_nitems * sizeof(int8_t));
|
|
|
|
+ writing_b = (int8_t *) malloc(db_nitems * sizeof(int8_t));
|
|
|
|
+ writing_c = (int8_t *) malloc(db_nitems * sizeof(int8_t));
|
|
|
|
+ writing_d = (int8_t *) malloc(db_nitems * sizeof(int8_t));
|
|
|
|
|
|
|
|
|
|
-
|
|
|
|
- size_t * rotate_by_ = new size_t[number_of_writes];
|
|
|
|
|
|
+ size_t * rotate_by_ = new size_t[number_of_writes];
|
|
|
|
|
|
|
|
|
|
boost::asio::io_context io_context;
|
|
boost::asio::io_context io_context;
|
|
@@ -84,32 +85,32 @@ int main(const int argc, const char * argv[])
|
|
const std::string host2 = (argc < 3) ? "127.0.0.1" : argv[2];
|
|
const std::string host2 = (argc < 3) ? "127.0.0.1" : argv[2];
|
|
|
|
|
|
|
|
|
|
- bool party;
|
|
|
|
- const size_t number_of_sockets = 40;
|
|
|
|
- std::vector<socket_t> sockets_;
|
|
|
|
- for(size_t j = 0; j < number_of_sockets + 1; ++j)
|
|
|
|
- {
|
|
|
|
- tcp::socket emptysocket(io_context);
|
|
|
|
- sockets_.emplace_back(std::move(emptysocket));
|
|
|
|
- }
|
|
|
|
- sockets_.reserve(number_of_sockets + 1);
|
|
|
|
|
|
+ bool party;
|
|
|
|
+ const size_t number_of_sockets = 40;
|
|
|
|
+ std::vector<socket_t> sockets_;
|
|
|
|
+ for(size_t j = 0; j < number_of_sockets + 1; ++j)
|
|
|
|
+ {
|
|
|
|
+ tcp::socket emptysocket(io_context);
|
|
|
|
+ sockets_.emplace_back(std::move(emptysocket));
|
|
|
|
+ }
|
|
|
|
+ sockets_.reserve(number_of_sockets + 1);
|
|
printf("number_of_sockets = %zu\n", number_of_sockets);
|
|
printf("number_of_sockets = %zu\n", number_of_sockets);
|
|
|
|
|
|
- std::vector<socket_t> sockets_2;
|
|
|
|
|
|
+ std::vector<socket_t> sockets_2;
|
|
|
|
|
|
- std::vector<int> ports;
|
|
|
|
- for(size_t j = 0; j < number_of_sockets; ++j)
|
|
|
|
- {
|
|
|
|
- int port = 6000;
|
|
|
|
- ports.push_back(port + j);
|
|
|
|
- }
|
|
|
|
|
|
+ std::vector<int> ports;
|
|
|
|
+ for(size_t j = 0; j < number_of_sockets; ++j)
|
|
|
|
+ {
|
|
|
|
+ int port = 6000;
|
|
|
|
+ ports.push_back(port + j);
|
|
|
|
+ }
|
|
|
|
|
|
- std::vector<int> ports2_0;
|
|
|
|
- for(size_t j = 0; j < number_of_sockets; ++j)
|
|
|
|
- {
|
|
|
|
- int port = 8000;
|
|
|
|
- ports2_0.push_back(port + j);
|
|
|
|
- }
|
|
|
|
|
|
+ std::vector<int> ports2_0;
|
|
|
|
+ for(size_t j = 0; j < number_of_sockets; ++j)
|
|
|
|
+ {
|
|
|
|
+ int port = 8000;
|
|
|
|
+ ports2_0.push_back(port + j);
|
|
|
|
+ }
|
|
|
|
|
|
std::vector<int> ports2_1;
|
|
std::vector<int> ports2_1;
|
|
for(size_t j = 0; j < number_of_sockets; ++j)
|
|
for(size_t j = 0; j < number_of_sockets; ++j)
|
|
@@ -120,11 +121,11 @@ int main(const int argc, const char * argv[])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
- #if (PARTY == 0)
|
|
|
|
|
|
+#if (PARTY == 0)
|
|
|
|
|
|
- party = false;
|
|
|
|
|
|
+ party = false;
|
|
|
|
|
|
- #ifdef ThreeParty
|
|
|
|
|
|
+ #ifdef ThreeParty
|
|
for(size_t j = 0; j < number_of_sockets; ++j)
|
|
for(size_t j = 0; j < number_of_sockets; ++j)
|
|
{
|
|
{
|
|
tcp::socket sb_a(io_context);
|
|
tcp::socket sb_a(io_context);
|
|
@@ -132,41 +133,40 @@ int main(const int argc, const char * argv[])
|
|
sockets_2.emplace_back(std::move(sb_a));
|
|
sockets_2.emplace_back(std::move(sb_a));
|
|
}
|
|
}
|
|
#endif
|
|
#endif
|
|
-
|
|
|
|
- for(size_t j = 0; j < number_of_sockets; ++j)
|
|
|
|
- {
|
|
|
|
- tcp::socket sb_a(io_context);
|
|
|
|
- boost::asio::connect(sb_a, resolver.resolve({host1, std::to_string(ports[j])}));
|
|
|
|
- sockets_[j] = std::move(sb_a);
|
|
|
|
- }
|
|
|
|
|
|
+ for(size_t j = 0; j < number_of_sockets; ++j)
|
|
|
|
+ {
|
|
|
|
+ tcp::socket sb_a(io_context);
|
|
|
|
+ boost::asio::connect(sb_a, resolver.resolve({host1, std::to_string(ports[j])}));
|
|
|
|
+ sockets_[j] = std::move(sb_a);
|
|
|
|
+ }
|
|
#else
|
|
#else
|
|
|
|
|
|
party = true;
|
|
party = true;
|
|
|
|
|
|
#ifdef ThreeParty
|
|
#ifdef ThreeParty
|
|
- for(size_t j = 0; j < number_of_sockets; ++j)
|
|
|
|
- {
|
|
|
|
- tcp::socket sb_a(io_context);
|
|
|
|
- boost::asio::connect(sb_a, resolver.resolve({host2, std::to_string(ports2_1[j])}));
|
|
|
|
- sockets_2.emplace_back(std::move(sb_a));
|
|
|
|
- }
|
|
|
|
|
|
+ for(size_t j = 0; j < number_of_sockets; ++j)
|
|
|
|
+ {
|
|
|
|
+ tcp::socket sb_a(io_context);
|
|
|
|
+ boost::asio::connect(sb_a, resolver.resolve({host2, std::to_string(ports2_1[j])}));
|
|
|
|
+ sockets_2.emplace_back(std::move(sb_a));
|
|
|
|
+ }
|
|
#endif
|
|
#endif
|
|
|
|
|
|
- boost::asio::thread_pool pool2(number_of_sockets);
|
|
|
|
- for(size_t j = 0; j < number_of_sockets; ++j)
|
|
|
|
- {
|
|
|
|
- boost::asio::post(pool2, std::bind(accept_conncections_from_Pb, std::ref(io_context), std::ref(sockets_), ports[j], j));
|
|
|
|
- }
|
|
|
|
- pool2.join();
|
|
|
|
|
|
+ boost::asio::thread_pool pool2(number_of_sockets);
|
|
|
|
+ for(size_t j = 0; j < number_of_sockets; ++j)
|
|
|
|
+ {
|
|
|
|
+ boost::asio::post(pool2, std::bind(accept_conncections_from_Pb, std::ref(io_context), std::ref(sockets_), ports[j], j));
|
|
|
|
+ }
|
|
|
|
+ pool2.join();
|
|
|
|
|
|
#endif
|
|
#endif
|
|
|
|
|
|
|
|
|
|
generate_random_distinguished_points(party);
|
|
generate_random_distinguished_points(party);
|
|
|
|
|
|
- AES_KEY aeskey;
|
|
|
|
- blinds = (DB_t *) std::aligned_alloc(sizeof(__m256i), db_nitems * sizeof(DB_t));
|
|
|
|
- updated_blinds = (DB_t *) std::aligned_alloc(sizeof(__m256i), db_nitems * sizeof(DB_t));
|
|
|
|
|
|
+ AES_KEY aeskey;
|
|
|
|
+ blinds = (DB_t *) std::aligned_alloc(sizeof(__m256i), db_nitems * sizeof(DB_t));
|
|
|
|
+ updated_blinds = (DB_t *) std::aligned_alloc(sizeof(__m256i), db_nitems * sizeof(DB_t));
|
|
|
|
|
|
size_t * where_to_write = new size_t[number_of_writes];
|
|
size_t * where_to_write = new size_t[number_of_writes];
|
|
size_t * where_to_read_dependent = new size_t[number_of_dep_reads];
|
|
size_t * where_to_read_dependent = new size_t[number_of_dep_reads];
|
|
@@ -198,14 +198,14 @@ int main(const int argc, const char * argv[])
|
|
updated_blinded_DB_recv[j] = blinded_DB_recv[j];
|
|
updated_blinded_DB_recv[j] = blinded_DB_recv[j];
|
|
}
|
|
}
|
|
|
|
|
|
- int64_t ri, ri_recv;
|
|
|
|
- arc4random_buf(&ri, sizeof(ri));
|
|
|
|
- ri = ri % db_nitems;
|
|
|
|
- boost::asio::write(sockets_[0], boost::asio::buffer(&ri, sizeof(ri)));
|
|
|
|
- boost::asio::read(sockets_[0], boost::asio::buffer(&ri_recv, sizeof(ri_recv)));
|
|
|
|
|
|
+ int64_t ri, ri_recv;
|
|
|
|
+ arc4random_buf(&ri, sizeof(ri));
|
|
|
|
+ ri = ri % db_nitems;
|
|
|
|
+ boost::asio::write(sockets_[0], boost::asio::buffer(&ri, sizeof(ri)));
|
|
|
|
+ boost::asio::read(sockets_[0], boost::asio::buffer(&ri_recv, sizeof(ri_recv)));
|
|
|
|
|
|
- std::cout << "ri = " << ri << std::endl;
|
|
|
|
- if(party) ri = 2 - ri_recv;
|
|
|
|
|
|
+ std::cout << "ri = " << ri << std::endl;
|
|
|
|
+ if(party) ri = 2 - ri_recv;
|
|
|
|
|
|
#ifdef VERBOSE
|
|
#ifdef VERBOSE
|
|
boost::asio::write(sockets_[0], boost::asio::buffer(&ri, sizeof(ri)));
|
|
boost::asio::write(sockets_[0], boost::asio::buffer(&ri, sizeof(ri)));
|
|
@@ -252,7 +252,7 @@ int main(const int argc, const char * argv[])
|
|
rotate_by_[w] = WritePb_[w].shift + WritePb_recv[w].shift;
|
|
rotate_by_[w] = WritePb_[w].shift + WritePb_recv[w].shift;
|
|
|
|
|
|
#ifdef VERBOSE
|
|
#ifdef VERBOSE
|
|
- std::cout << "print database: " << std::endl;
|
|
|
|
|
|
+ std::cout << "print database (prints the non-zero database entries): " << std::endl;
|
|
/* The definition of reconstruct_database appears in duoram-utils.h */
|
|
/* The definition of reconstruct_database appears in duoram-utils.h */
|
|
reconstruct_database(sockets_[0], DB, db_nitems);
|
|
reconstruct_database(sockets_[0], DB, db_nitems);
|
|
#endif
|
|
#endif
|
|
@@ -295,18 +295,18 @@ int main(const int argc, const char * argv[])
|
|
#endif
|
|
#endif
|
|
|
|
|
|
for(size_t w = 0; w < number_of_writes; ++w)
|
|
for(size_t w = 0; w < number_of_writes; ++w)
|
|
- {
|
|
|
|
|
|
+ {
|
|
|
|
|
|
/*The definition of DuoramUpdate appears in duoram-write.h*/
|
|
/*The definition of DuoramUpdate appears in duoram-write.h*/
|
|
DuoramUpdate(party, db_nitems, rotate_by_[w], DB, updated_DB, writing_b, b, CW[w], update_message[w], writing_c, writing_d, c, d);
|
|
DuoramUpdate(party, db_nitems, rotate_by_[w], DB, updated_DB, writing_b, b, CW[w], update_message[w], writing_c, writing_d, c, d);
|
|
|
|
|
|
- #ifdef DEBUG
|
|
|
|
- #ifdef ThreeParty
|
|
|
|
|
|
+ #ifdef DEBUG
|
|
|
|
+ #ifdef ThreeParty
|
|
/*The definition debug_ appears in duoram-utils.h*/
|
|
/*The definition debug_ appears in duoram-utils.h*/
|
|
debug_(sockets_2[0], sockets_[0], db_nitems);
|
|
debug_(sockets_2[0], sockets_[0], db_nitems);
|
|
- #endif
|
|
|
|
- #endif
|
|
|
|
- }
|
|
|
|
|
|
+ #endif
|
|
|
|
+ #endif
|
|
|
|
+ }
|
|
|
|
|
|
auto end_writes = std::chrono::steady_clock::now();
|
|
auto end_writes = std::chrono::steady_clock::now();
|
|
std::chrono::duration<double> elapsed_seconds_writes = end_writes - start_writes;
|
|
std::chrono::duration<double> elapsed_seconds_writes = end_writes - start_writes;
|
|
@@ -358,11 +358,11 @@ int main(const int argc, const char * argv[])
|
|
auto end_ind_reads = std::chrono::steady_clock::now();
|
|
auto end_ind_reads = std::chrono::steady_clock::now();
|
|
std::chrono::duration<double> elapsed_seconds_ind_reads = end_ind_reads - start_ind_reads;
|
|
std::chrono::duration<double> elapsed_seconds_ind_reads = end_ind_reads - start_ind_reads;
|
|
printf("elapsed_seconds_ind_reads = %f\n",elapsed_seconds_ind_reads.count());
|
|
printf("elapsed_seconds_ind_reads = %f\n",elapsed_seconds_ind_reads.count());
|
|
- printf("\n\n================================= INDEPENDENT READS END =================================\n\n\n");
|
|
|
|
-
|
|
|
|
|
|
+ std::cout << std::endl << std::endl << "============== INDEPENDENT READS END ==============" << std::endl << std::endl;
|
|
auto start_dep_reads = std::chrono::steady_clock::now();
|
|
auto start_dep_reads = std::chrono::steady_clock::now();
|
|
|
|
|
|
- printf("\n\n================================= DEPENDENT READS START =================================\n\n\n");
|
|
|
|
|
|
+
|
|
|
|
+ std::cout << std::endl << std::endl << "============== DEPENDENT READS START ==============" << std::endl << std::endl;
|
|
DB_t * read_out_dependent_reads = new DB_t[number_of_dep_reads];
|
|
DB_t * read_out_dependent_reads = new DB_t[number_of_dep_reads];
|
|
for(size_t r = 0; r < number_of_dep_reads; ++r)
|
|
for(size_t r = 0; r < number_of_dep_reads; ++r)
|
|
{
|
|
{
|
|
@@ -374,20 +374,19 @@ int main(const int argc, const char * argv[])
|
|
#endif
|
|
#endif
|
|
}
|
|
}
|
|
|
|
|
|
- auto end_dep_reads = std::chrono::steady_clock::now();
|
|
|
|
- std::chrono::duration<double> elapsed_seconds_dep_reads = end_dep_reads - start_dep_reads;
|
|
|
|
- printf("elapsed_seconds_dep_reads = %f\n",elapsed_seconds_dep_reads.count());
|
|
|
|
- printf("\n\n================================= DEPENDENT READS END =================================n\n");
|
|
|
|
-
|
|
|
|
|
|
+ auto end_dep_reads = std::chrono::steady_clock::now();
|
|
|
|
+ std::chrono::duration<double> elapsed_seconds_dep_reads = end_dep_reads - start_dep_reads;
|
|
|
|
+ printf("elapsed_seconds_dep_reads = %f\n",elapsed_seconds_dep_reads.count());
|
|
|
|
+ std::cout << std::endl << std::endl << "============== DEPENDENT READS END ==============" << std::endl << std::endl;
|
|
|
|
|
|
- printf("\n\n\n\n\n-----------------------------------------------------------------------------------------------------------\n\n\n\n\n\n");
|
|
|
|
|
|
+
|
|
#endif
|
|
#endif
|
|
}
|
|
}
|
|
- auto end_total = std::chrono::steady_clock::now();
|
|
|
|
- std::chrono::duration<double> elapsed_seconds_total = end_total - start_total;
|
|
|
|
- printf("elapsed_seconds_total = %f\n",elapsed_seconds_total.count());
|
|
|
|
|
|
+ auto end_total = std::chrono::steady_clock::now();
|
|
|
|
+ std::chrono::duration<double> elapsed_seconds_total = end_total - start_total;
|
|
|
|
+ printf("elapsed_seconds_total = %f\n",elapsed_seconds_total.count());
|
|
|
|
|
|
- free(reading_temp);
|
|
|
|
|
|
+free(reading_temp);
|
|
|
|
|
|
return 0;
|
|
return 0;
|
|
}
|
|
}
|