Skip to content

Commit

Permalink
Updated to SEAL 2.3.1
Browse files Browse the repository at this point in the history
  • Loading branch information
kimlaine committed Jun 18, 2018
1 parent 62fb317 commit dead23d
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 1,874 deletions.
20 changes: 20 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
cmake_minimum_required(VERSION 3.10)

project(SealPIR VERSION 1.1 LANGUAGES CXX)

set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/bin)

add_executable(sealpir
main.cpp
pir.cpp
pir_client.cpp
pir_server.cpp
)

find_package(SEAL 2.3.1 EXACT REQUIRED)
find_package(Threads REQUIRED)

target_link_libraries(sealpir
SEAL::seal
Threads::Threads
)
30 changes: 0 additions & 30 deletions Makefile

This file was deleted.

35 changes: 6 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,39 +5,16 @@ SealPIR is a (research) library and should not be used in production systems. Se

# Compiling SEAL

SealPIR depends on SEAL v2.3.0-4 and a patch that exposes the substitution operator. You can get SEAL v2.3.0-4 from this [link](http://sealcrypto.org).

Once you have downloaded SEAL, apply the patch SEAL_v2.3.0-4.patch (available in this repository) to it. Here are the exact steps.

We assume that you are in the SEAL directory, and that you have copied the patch to this directory.

First, convert the SEAL directory into a git repo:

```sh
$ git init
$ git add .
$ git commit -m "SEAL v2.3.0-4"
```
Then, apply the patch:

```sh
$ git am SEAL_v2.3.0-4.patch
```

Finally, compile SEAL (NOTE: gcc-8 is not currently supported):

```sh
$ cd SEAL
$ ./configure CXXFLAGS="-O3 -march=native -fPIC"
$ make clean && make
```
SealPIR depends on SEAL 2.3.1 ([link](http://sealcrypto.org). Download SEAL, and follow the instructions in INSTALL.txt to install it system-wide.

# Compiling SealPIR

The current Makefile assumes that SEAL_v2.3.0-4 is located (relative to SealPIR) at: ../SEAL/. If this is not the case change the IDIR and LDIR variables in the Makefile accordingly.

To compile SealPIR simply run ``make``. It should produce a binary file in ``bin/main``.
Once SEAL 2.3.1 is installed, to build SealPIR simply run:

cmake .
make

This should produce a binary file ``bin/sealpir``.

# Using SealPIR

Expand Down
1,801 changes: 0 additions & 1,801 deletions SEAL_v2.3.0-4.patch

This file was deleted.

2 changes: 1 addition & 1 deletion pir.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ void coeffs_to_bytes(uint32_t limit, const Plaintext &coeffs, uint8_t *output, u
void vector_to_plaintext(const vector<uint64_t> &coeffs, Plaintext &plain) {
uint32_t coeff_count = coeffs.size();
plain.resize(coeff_count);
util::set_uint_uint(coeffs.data(), coeff_count, plain.pointer());
util::set_uint_uint(coeffs.data(), coeff_count, plain.data());
}

vector<uint64_t> compute_indices(uint64_t desiredIndex, vector<uint64_t> Nvec) {
Expand Down
12 changes: 6 additions & 6 deletions pir_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ PIRClient::PIRClient(const EncryptionParameters &params,
encryptor_.reset(new Encryptor(context, keygen_->public_key()));

SecretKey secret_key = keygen_->secret_key();
secret_key.mutable_hash_block() = expanded_params.hash_block();
secret_key.hash_block() = expanded_params.hash_block();

decryptor_.reset(new Decryptor(newcontext, secret_key));
evaluator_.reset(new Evaluator(newcontext));
Expand All @@ -37,7 +37,7 @@ void PIRClient::update_parameters(const EncryptionParameters &expanded_params,
SEALContext newcontext(expanded_params);

SecretKey secret_key = keygen_->secret_key();
secret_key.mutable_hash_block() = expanded_params.hash_block();
secret_key.hash_block() = expanded_params.hash_block();

decryptor_.reset(new Decryptor(newcontext, secret_key));
evaluator_.reset(new Evaluator(newcontext));
Expand All @@ -51,7 +51,7 @@ PirQuery PIRClient::generate_query(uint64_t desiredIndex) {
for (uint32_t i = 0; i < indices.size(); i++) {
Ciphertext dest;
encryptor_->encrypt(Plaintext("1x^" + std::to_string(indices[i])), dest);
dest.mutable_hash_block() = expanded_params_.hash_block();
dest.hash_block() = expanded_params_.hash_block();
result.push_back(dest);
}

Expand Down Expand Up @@ -146,7 +146,7 @@ Ciphertext PIRClient::compose_to_ciphertext(vector<Plaintext> plains) {

// A triple for loop. Going over polys, moduli, and decomposed index.
for (int i = 0; i < encrypted_count; i++) {
uint64_t *encrypted_pointer = result.mutable_pointer(i);
uint64_t *encrypted_pointer = result.data(i);

for (int j = 0; j < coeff_mod_count; j++) {
// populate one poly at a time.
Expand All @@ -164,7 +164,7 @@ Ciphertext PIRClient::compose_to_ciphertext(vector<Plaintext> plains) {
// Compose here
const uint64_t *plain_coeff =
plains[k + j * (expansion_ratio) + i * (coeff_mod_count * expansion_ratio)]
.pointer();
.data();

for (int m = 0; m < coeff_count - 1; m++) {
if (k == 0) {
Expand All @@ -188,6 +188,6 @@ Ciphertext PIRClient::compose_to_ciphertext(vector<Plaintext> plains) {
}
}

result.mutable_hash_block() = expanded_params_.hash_block();
result.hash_block() = expanded_params_.hash_block();
return result;
}
14 changes: 7 additions & 7 deletions pir_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ void PIRServer::update_parameters(const EncryptionParameters &expanded_params,

// Update all the galois keys
for (std::pair<const int, GaloisKeys> &key : galoisKeys_) {
key.second.mutable_hash_block() = expanded_params_.hash_block();
key.second.hash_block() = expanded_params_.hash_block();
}
}

Expand Down Expand Up @@ -138,7 +138,7 @@ void PIRServer::set_database(const uint8_t *bytes, uint64_t ele_num, uint64_t el
}

void PIRServer::set_galois_key(std::uint32_t client_id, seal::GaloisKeys galkey) {
galkey.mutable_hash_block() = expanded_params_.hash_block();
galkey.hash_block() = expanded_params_.hash_block();
galoisKeys_[client_id] = galkey;
}

Expand Down Expand Up @@ -308,10 +308,10 @@ inline void PIRServer::multiply_power_of_X(const Ciphertext &encrypted, Cipherte
// Multiply X^index for each ciphertext polynomial
for (int i = 0; i < encrypted_count; i++) {
for (int j = 0; j < coeff_mod_count; j++) {
negacyclic_shift_poly_coeffmod(encrypted.pointer(i) + (j * coeff_count),
negacyclic_shift_poly_coeffmod(encrypted.data(i) + (j * coeff_count),
coeff_count - 1, index,
expanded_params_.coeff_modulus()[j],
destination.mutable_pointer(i) + (j * coeff_count));
destination.data(i) + (j * coeff_count));
}
}
}
Expand All @@ -330,7 +330,7 @@ inline void PIRServer::decompose_to_plaintexts_ptr(const Ciphertext &encrypted,
// A triple for loop. Going over polys, moduli, and decomposed index.

for (int i = 0; i < encrypted_count; i++) {
const uint64_t *encrypted_pointer = encrypted.pointer(i);
const uint64_t *encrypted_pointer = encrypted.data(i);
for (int j = 0; j < coeff_mod_count; j++) {
// populate one poly at a time.
// create a polynomial to store the current decomposition value
Expand Down Expand Up @@ -366,7 +366,7 @@ vector<Plaintext> PIRServer::decompose_to_plaintexts(const Ciphertext &encrypted

// A triple for loop. Going over polys, moduli, and decomposed index.
for (int i = 0; i < encrypted_count; i++) {
const uint64_t *encrypted_pointer = encrypted.pointer(i);
const uint64_t *encrypted_pointer = encrypted.data(i);
for (int j = 0; j < coeff_mod_count; j++) {
// populate one poly at a time.
// create a polynomial to store the current decomposition value
Expand All @@ -382,7 +382,7 @@ vector<Plaintext> PIRServer::decompose_to_plaintexts(const Ciphertext &encrypted
BigPoly temp;
temp.resize(coeff_count, plain_bit_count);
temp.set_zero();
uint64_t *plain_coeff = temp.pointer();
uint64_t *plain_coeff = temp.data();
for (int m = 0; m < coeff_count; m++) {
*(plain_coeff + m) =
(*(encrypted_pointer + m + (j * coeff_count)) / cur) % plainMod;
Expand Down

0 comments on commit dead23d

Please sign in to comment.