Browse Source

update readme and add size

Sebastian Angel 2 years ago
parent
commit
dfc29d64e2
6 changed files with 33 additions and 10 deletions
  1. 8 0
      README.md
  2. 9 4
      src/main.cpp
  3. 2 2
      src/pir_client.cpp
  4. 2 2
      src/pir_client.hpp
  5. 9 1
      src/pir_server.cpp
  6. 3 1
      src/pir_server.hpp

+ 8 - 0
README.md

@@ -6,6 +6,14 @@ revealing which element was downloaded. SealPIR was introduced at
 the Symposium on Security and Privacy (Oakland) in 2018. You can find
 the Symposium on Security and Privacy (Oakland) in 2018. You can find
 a copy of the paper [here](https://eprint.iacr.org/2017/1142.pdf).
 a copy of the paper [here](https://eprint.iacr.org/2017/1142.pdf).
 
 
+This is a newer version of SealPIR that uses the latest version of SEAL
+and provides better serialization/deserialization of queries and responses,
+and a more streamlined code base. A drawback of this version is that ciphertexts 
+are slightly larger (due to specifics with SEAL). If you wish to use the 
+original version of SealPIR which uses an older version of SEAL and has smaller
+ciphertexts, check out the [original](https://github.com/microsoft/SealPIR/tree/original) 
+branch in this repository.
+
 # Compiling SEAL
 # Compiling SEAL
 
 
 SealPIR depends on [Microsoft SEAL version 3.6.5](https://github.com/microsoft/SEAL/tree/3.6.5).
 SealPIR depends on [Microsoft SEAL version 3.6.5](https://github.com/microsoft/SEAL/tree/3.6.5).

+ 9 - 4
src/main.cpp

@@ -101,16 +101,17 @@ int main(int argc, char *argv[]) {
     cout << "Main: query generated" << endl;
     cout << "Main: query generated" << endl;
 
 
     // Measure serialized query generation (useful for sending over the network)
     // Measure serialized query generation (useful for sending over the network)
-    stringstream stream;
+    stringstream client_stream;
+    stringstream server_stream;
     auto time_s_query_s = high_resolution_clock::now();
     auto time_s_query_s = high_resolution_clock::now();
-    int query_size = client.generate_serialized_query(index, stream);
+    int query_size = client.generate_serialized_query(index, client_stream);
     auto time_s_query_e = high_resolution_clock::now();
     auto time_s_query_e = high_resolution_clock::now();
     auto time_s_query_us = duration_cast<microseconds>(time_s_query_e - time_s_query_s).count();
     auto time_s_query_us = duration_cast<microseconds>(time_s_query_e - time_s_query_s).count();
     cout << "Main: serialized query generated" << endl;
     cout << "Main: serialized query generated" << endl;
 
 
     // Measure query deserialization (useful for receiving over the network)
     // Measure query deserialization (useful for receiving over the network)
     auto time_deserial_s = high_resolution_clock::now();
     auto time_deserial_s = high_resolution_clock::now();
-    PirQuery query2 = server.deserialize_query(stream);
+    PirQuery query2 = server.deserialize_query(client_stream);
     auto time_deserial_e = high_resolution_clock::now();
     auto time_deserial_e = high_resolution_clock::now();
     auto time_deserial_us = duration_cast<microseconds>(time_deserial_e - time_deserial_s).count();
     auto time_deserial_us = duration_cast<microseconds>(time_deserial_e - time_deserial_s).count();
     cout << "Main: query deserialized" << endl;
     cout << "Main: query deserialized" << endl;
@@ -124,6 +125,9 @@ int main(int argc, char *argv[]) {
     auto time_server_us = duration_cast<microseconds>(time_server_e - time_server_s).count();
     auto time_server_us = duration_cast<microseconds>(time_server_e - time_server_s).count();
     cout << "Main: reply generated" << endl;
     cout << "Main: reply generated" << endl;
 
 
+    // Serialize reply (useful for sending over the network)
+    int reply_size = server.serialize_reply(reply, server_stream);
+
     // Measure response extraction
     // Measure response extraction
     auto time_decode_s = chrono::high_resolution_clock::now();
     auto time_decode_s = chrono::high_resolution_clock::now();
     vector<uint8_t> elems = client.decode_reply(reply, offset);
     vector<uint8_t> elems = client.decode_reply(reply, offset);
@@ -155,8 +159,9 @@ int main(int argc, char *argv[]) {
     cout << "Main: PIRServer query deserialization time: " << time_deserial_us << " us" << endl;
     cout << "Main: PIRServer query deserialization time: " << time_deserial_us << " us" << endl;
     cout << "Main: PIRServer reply generation time: " << time_server_us / 1000 << " ms" << endl;
     cout << "Main: PIRServer reply generation time: " << time_server_us / 1000 << " ms" << endl;
     cout << "Main: PIRClient answer decode time: " << time_decode_us / 1000 << " ms" << endl;
     cout << "Main: PIRClient answer decode time: " << time_decode_us / 1000 << " ms" << endl;
-    cout << "Main: Reply num ciphertexts: " << reply.size() << endl;
     cout << "Main: Query size: " << query_size << " bytes" << endl;
     cout << "Main: Query size: " << query_size << " bytes" << endl;
+    cout << "Main: Reply num ciphertexts: " << reply.size() << endl;
+    cout << "Main: Reply size: " << reply_size << " bytes" << endl;
 
 
     return 0;
     return 0;
 }
 }

+ 2 - 2
src/pir_client.cpp

@@ -126,7 +126,7 @@ Plaintext PIRClient::decrypt(Ciphertext ct){
     return pt;
     return pt;
 }
 }
 
 
-vector<uint8_t> PIRClient::decode_reply(PirReply reply, uint64_t offset){
+vector<uint8_t> PIRClient::decode_reply(PirReply &reply, uint64_t offset){
     Plaintext result = decode_reply(reply);
     Plaintext result = decode_reply(reply);
     
     
     uint32_t N = enc_params_.poly_modulus_degree(); 
     uint32_t N = enc_params_.poly_modulus_degree(); 
@@ -140,7 +140,7 @@ vector<uint8_t> PIRClient::decode_reply(PirReply reply, uint64_t offset){
     return std::vector<uint8_t>(elems.begin() + offset * pir_params_.ele_size, elems.begin() + (offset + 1) * pir_params_.ele_size);
     return std::vector<uint8_t>(elems.begin() + offset * pir_params_.ele_size, elems.begin() + (offset + 1) * pir_params_.ele_size);
 }
 }
 
 
-Plaintext PIRClient::decode_reply(PirReply reply) {
+Plaintext PIRClient::decode_reply(PirReply &reply) {
     uint32_t exp_ratio = pir_params_.expansion_ratio;
     uint32_t exp_ratio = pir_params_.expansion_ratio;
     uint32_t recursion_level = pir_params_.d;
     uint32_t recursion_level = pir_params_.d;
 
 

+ 2 - 2
src/pir_client.hpp

@@ -14,8 +14,8 @@ class PIRClient {
     PirQuery generate_query(std::uint64_t desiredIndex);
     PirQuery generate_query(std::uint64_t desiredIndex);
     // Serializes the query into the provided stream and returns number of bytes written
     // Serializes the query into the provided stream and returns number of bytes written
     int generate_serialized_query(std::uint64_t desiredIndex, std::stringstream &stream);
     int generate_serialized_query(std::uint64_t desiredIndex, std::stringstream &stream);
-    seal::Plaintext decode_reply(PirReply reply);
-    std::vector<uint8_t> decode_reply(PirReply reply, uint64_t offset);
+    seal::Plaintext decode_reply(PirReply &reply);
+    std::vector<uint8_t> decode_reply(PirReply &reply, uint64_t offset);
 
 
     seal::Plaintext decrypt(seal::Ciphertext ct);
     seal::Plaintext decrypt(seal::Ciphertext ct);
 
 

+ 9 - 1
src/pir_server.cpp

@@ -147,7 +147,15 @@ PirQuery PIRServer::deserialize_query(stringstream &stream) {
     return q;
     return q;
 }
 }
 
 
-PirReply PIRServer::generate_reply(PirQuery query, uint32_t client_id) {
+int PIRServer::serialize_reply(PirReply &reply, stringstream &stream) {
+  int output_size = 0;
+  for (int i = 0; i < reply.size(); i++){
+    output_size += reply[i].save(stream);
+  }
+  return output_size;
+}
+
+PirReply PIRServer::generate_reply(PirQuery &query, uint32_t client_id) {
 
 
     vector<uint64_t> nvec = pir_params_.nvec;
     vector<uint64_t> nvec = pir_params_.nvec;
     uint64_t product = 1;
     uint64_t product = 1;

+ 3 - 1
src/pir_server.hpp

@@ -20,7 +20,9 @@ class PIRServer {
             const seal::Ciphertext &encrypted, std::uint32_t m, uint32_t client_id);
             const seal::Ciphertext &encrypted, std::uint32_t m, uint32_t client_id);
 
 
     PirQuery deserialize_query(std::stringstream &stream);
     PirQuery deserialize_query(std::stringstream &stream);
-    PirReply generate_reply(PirQuery query, std::uint32_t client_id);
+    PirReply generate_reply(PirQuery &query, std::uint32_t client_id);
+    // Serializes the reply into the provided stream and returns the number of bytes written
+    int serialize_reply(PirReply &reply, std::stringstream &stream);
 
 
     void set_galois_key(std::uint32_t client_id, seal::GaloisKeys galkey);
     void set_galois_key(std::uint32_t client_id, seal::GaloisKeys galkey);