Skip to content

Commit

Permalink
Adds PALISADE-FHEW microbenchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
pjattke committed Dec 28, 2020
1 parent 6fafb90 commit abcd2ed
Show file tree
Hide file tree
Showing 3 changed files with 174 additions and 0 deletions.
2 changes: 2 additions & 0 deletions PALISADE/source/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ include_directories( ${PALISADE_INCLUDE} )
include_directories( ${PALISADE_INCLUDE}/third-party/include )
include_directories( ${PALISADE_INCLUDE}/core )
include_directories( ${PALISADE_INCLUDE}/pke )
include_directories( ${PALISADE_INCLUDE}/binfhe )
### add directories for other PALISADE modules as needed for your project

link_directories( ${PALISADE_LIBDIR} )
Expand All @@ -22,3 +23,4 @@ link_libraries( ${PALISADE_LIBRARIES} )
### ADD YOUR EXECUTABLE(s) HERE
add_executable(microbenchmark-bfv-bgv microbenchmark-bfv-bgv/microbenchmark.cpp )
add_executable(microbenchmark-ckks microbenchmark-ckks/microbenchmark.cpp )
add_executable(microbenchmark-fhew microbenchmark-fhew/microbenchmark.cpp )
4 changes: 4 additions & 0 deletions PALISADE/source/docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,7 @@ upload_files PALISADE-BFV-BGV ${OUTPUT_FILENAME} fhe_parameters_microbenchmark_b
export OUTPUT_FILENAME=palisade_microbenchmark-ckks.csv
./microbenchmark-ckks
upload_files PALISADE-CKKS ${OUTPUT_FILENAME} fhe_parameters_microbenchmark_ckks.txt

export OUTPUT_FILENAME=palisade_microbenchmark-fhew.csv
./microbenchmark-fhew
upload_files PALISADE-FHEW ${OUTPUT_FILENAME} fhe_parameters_microbenchmark_fhew.txt
168 changes: 168 additions & 0 deletions PALISADE/source/microbenchmark-fhew/microbenchmark.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
#define PROFILE

#include <chrono>
#include <fstream>
#include <iostream>
#include <iterator>

#include "binfhecontext.h"
#include "cryptocontextgen.h"
#include "palisade.h"

using namespace std;
using namespace lbcrypto;

typedef std::chrono::microseconds TARGET_TIME_UNIT;

int main(int argc, char *argv[]) {
auto cryptoContext = BinFHEContext();
// generate the crypto context with 128-bit of security
cryptoContext.GenerateBinFHEContext(STD128);

// generate the secret key
auto sk = cryptoContext.KeyGen();

// generate bootstrapping keys needed for refresh and key switching
cryptoContext.BTKeyGen(sk);

// encrypt two ciphertexts representing boolean 1
auto ct1 = cryptoContext.Encrypt(sk, 1);
auto ct2 = cryptoContext.Encrypt(sk, 1);

const int NUM_REPETITIONS{250};
std::stringstream ss_time;

// =======================================================
// Ctxt-Ctxt Multiplication with new ciphertext
// =======================================================

std::cout << "== Ctxt-Ctxt Multiplication with new ciphertext" << std::endl;
size_t total_time = 0;

for (size_t i = 0; i < NUM_REPETITIONS; i++) {
auto start = std::chrono::high_resolution_clock::now();
auto ctAND = cryptoContext.EvalBinGate(AND, ct1, ct2);
auto end = std::chrono::high_resolution_clock::now();

total_time +=
std::chrono::duration_cast<TARGET_TIME_UNIT>(end - start).count();
}
ss_time << (total_time / NUM_REPETITIONS) << ",";

// =======================================================
// Ctxt-Ctxt Multiplication in-place
// =======================================================

// not supported by PALISADE
ss_time << 0 << ",";

// =======================================================
// Ctxt-Ptxt Multiplication with new ciphertext
// =======================================================

// not supported by PALISADE
ss_time << 0 << ",";

// =======================================================
// Ctxt-Ptxt Multiplication in-place
// =======================================================

// not supported by PALISADE
ss_time << 0 << ",";

// =======================================================
// Ctxt-Ctxt Addition time with new ciphertext
// =======================================================

std::cout << "== Ctxt-Ctxt Addition time with new ciphertext" << std::endl;
total_time = 0;

for (size_t i = 0; i < NUM_REPETITIONS; i++) {
auto start = std::chrono::high_resolution_clock::now();
auto ct1 = cryptoContext.Encrypt(sk, 1);
auto end = std::chrono::high_resolution_clock::now();

total_time +=
std::chrono::duration_cast<TARGET_TIME_UNIT>(end - start).count();
}
ss_time << (total_time / NUM_REPETITIONS) << ",";

// =======================================================
// Ctxt-Ctxt Addition time in-place
// =======================================================

// not supported by PALISADE
ss_time << 0 << ",";

// =======================================================
// Ctxt-Ptxt Addition with new ciphertext
// =======================================================

// not supported by PALISADE
ss_time << 0 << ",";

// =======================================================
// Ctxt-Ptxt Addition in-place
// =======================================================

// not supported by PALISADE
ss_time << 0 << ",";

// =======================================================
// Sk Encryption time
// =======================================================

std::cout << "== Sk Encryption time" << std::endl;
total_time = 0;

for (size_t i = 0; i < NUM_REPETITIONS; i++) {
auto start = std::chrono::high_resolution_clock::now();
auto ct1 = cryptoContext.Encrypt(sk, 1);
auto end = std::chrono::high_resolution_clock::now();

total_time +=
std::chrono::duration_cast<TARGET_TIME_UNIT>(end - start).count();
}
ss_time << (total_time / NUM_REPETITIONS) << ",";

// =======================================================
// Pk Encryption Time
// =======================================================

// not supported by this scheme
ss_time << 0 << ",";

// =======================================================
// Decryption time
// =======================================================

std::cout << "== Decryption time" << std::endl;
total_time = 0;

for (size_t i = 0; i < NUM_REPETITIONS; i++) {
auto start = std::chrono::high_resolution_clock::now();
LWEPlaintext result;
cryptoContext.Decrypt(sk, ct1, &result);
auto end = std::chrono::high_resolution_clock::now();

total_time +=
std::chrono::duration_cast<TARGET_TIME_UNIT>(end - start).count();
}
ss_time << (total_time / NUM_REPETITIONS) << ",";

// =======================================================
// Rotation (native, i.e. single-key)
// =======================================================

// not supported by FHEW scheme
ss_time << 0 << std::endl;

// write ss_time into file
std::ofstream myfile;
auto out_filename = std::getenv("OUTPUT_FILENAME");
myfile.open(out_filename, std::ios_base::app);
myfile << ss_time.str() << std::endl;
myfile.close();

return 0;
}

0 comments on commit abcd2ed

Please sign in to comment.