Browse Source

Minor changes to pir_client api

Andrew Beams 2 years ago
parent
commit
521aa6f55e

+ 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
 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
 
 SealPIR depends on [Microsoft SEAL version 3.6.5](https://github.com/microsoft/SEAL/tree/3.6.5).

BIN
src/CMakeFiles/main.dir/main.cpp.o


+ 0 - 4
src/CMakeFiles/sealpir.dir/CXX.includecache

@@ -6,10 +6,6 @@
 
 #IncludeRegexTransform: 
 
-/home/andrew/Documents/Research/AC-PIR/SealPIR/src/pir.cpp
-pir.hpp
-/home/andrew/Documents/Research/AC-PIR/SealPIR/src/pir.hpp
-
 /home/andrew/Documents/Research/AC-PIR/SealPIR/src/pir.hpp
 seal/seal.h
 /home/andrew/Documents/Research/AC-PIR/SealPIR/src/seal/seal.h

BIN
src/CMakeFiles/sealpir.dir/pir_client.cpp.o


BIN
src/CMakeFiles/sealpir.dir/pir_server.cpp.o


+ 10 - 7
src/main.cpp

@@ -101,23 +101,21 @@ int main(int argc, char *argv[]) {
     cout << "Main: query generated" << endl;
 
     // 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();
-    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_us = duration_cast<microseconds>(time_s_query_e - time_s_query_s).count();
     cout << "Main: serialized query generated" << endl;
 
     // Measure query deserialization (useful for receiving over the network)
     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_us = duration_cast<microseconds>(time_deserial_e - time_deserial_s).count();
     cout << "Main: query deserialized" << endl;
 
-    //XXX: deserialization is not working correctly at the moment. There is likely a bug in either
-    //serialize or deserialize.
-
     // Measure query processing (including expansion)
     auto time_server_s = high_resolution_clock::now();
     // Answer PIR query from client 0. If there are multiple clients, 
@@ -127,6 +125,9 @@ int main(int argc, char *argv[]) {
     auto time_server_us = duration_cast<microseconds>(time_server_e - time_server_s).count();
     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
     auto time_decode_s = chrono::high_resolution_clock::now();
     vector<uint8_t> elems = client.decode_reply(reply, offset);
@@ -155,10 +156,12 @@ int main(int argc, char *argv[]) {
     cout << "Main: PIRServer pre-processing time: " << time_pre_us / 1000 << " ms" << endl;
     cout << "Main: PIRClient query generation time: " << time_query_us / 1000 << " ms" << endl;
     cout << "Main: PIRClient serialized query generation time: " << time_s_query_us / 1000 << " ms" << 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: 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: Reply num ciphertexts: " << reply.size() << endl;
+    cout << "Main: Reply size: " << reply_size << " bytes" << endl;
 
     return 0;
 }

+ 2 - 3
src/pir_client.cpp

@@ -126,7 +126,7 @@ Plaintext PIRClient::decrypt(Ciphertext ct){
     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);
     return extract_bytes(result, offset);   
 }
@@ -160,8 +160,7 @@ std::vector<uint8_t> PIRClient::extract_bytes(seal::Plaintext pt, uint64_t offse
     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 recursion_level = pir_params_.d;
 

+ 3 - 2
src/pir_client.hpp

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

+ 9 - 1
src/pir_server.cpp

@@ -147,7 +147,15 @@ PirQuery PIRServer::deserialize_query(stringstream &stream) {
     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;
     uint64_t product = 1;

+ 3 - 1
src/pir_server.hpp

@@ -20,7 +20,9 @@ class PIRServer {
             const seal::Ciphertext &encrypted, std::uint32_t m, std::uint32_t client_id);
 
     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);
 
     seal::Plaintext simple_query(std::uint64_t index, std::uint64_t offset);
 

BIN
test/CMakeFiles/query_test.dir/query_test.cpp.o