diff --git a/experiment/CMakeLists.txt b/experiment/CMakeLists.txt index b731e66..1ff5243 100644 --- a/experiment/CMakeLists.txt +++ b/experiment/CMakeLists.txt @@ -1,7 +1,7 @@ -# ----------------------------------------------------- -add_executable(SetupTime setup_time.cpp) -target_link_libraries(SetupTime PUBLIC EEJ) -# ----------------------------------------------------- -add_executable(EncTime encryption_time.cpp) -target_link_libraries(EncTime PUBLIC EEJ) -# ----------------------------------------------------- \ No newline at end of file +# Grab all cpp file except the run. +file(GLOB SOURCES "*.cpp") +list(REMOVE_ITEM SOURCES "run.cpp") + +# Add executable and link the library. +add_executable(EXP "run.cpp" ${SOURCES}) +target_link_libraries(EXP PUBLIC EEJ) diff --git a/experiment/encryption_time.cpp b/experiment/encryption_time.cpp index 535adbf..f390c70 100644 --- a/experiment/encryption_time.cpp +++ b/experiment/encryption_time.cpp @@ -1,14 +1,9 @@ -#include -#include -#include "filter.hpp" -#include "ipe_filter.hpp" +#include "exp.hpp" -static int ROUND = 10; - -void ipe_enc_time(){ +void ipe_enc_time(const int round){ // Open the output files. - std::ofstream file("ipe_enc_time.txt", std::ios_base::app); - file << "IPE Enc Timings" << std::endl << std::endl; + std::ofstream file("enc_time.txt", std::ios_base::app); + file << "IPE Enc Timings" << std::endl; for (int length = 10; length <= 200; length += 10){ // Create holder for timings. @@ -19,9 +14,9 @@ void ipe_enc_time(){ auto msk = IpeFilter::msk_gen(pp); // Perform ROUND number of Enc. - for (int i = 0; i < ROUND; ++i){ + for (int i = 0; i < round; ++i){ // Create a random vector of desired length. - auto x = Helper::rand_int_vec(length, 1, 65536); + auto x = Helper::rand_int_vec(length, 1, std::numeric_limits::max()); // Encryption timings. auto start = std::chrono::high_resolution_clock::now(); @@ -31,16 +26,19 @@ void ipe_enc_time(){ } // Output the time. - file << "(" << length << ", " << time.count() / ROUND << ")" << std::endl; + file << "(" << length << ", " << time.count() / round << ")" << std::endl; + + // Close the BP. + BP::close(); } // Create some blank spaces. file << std::endl << std::endl; } -void our_enc_time(){ +void our_enc_time(const int round){ // Open the output files. - std::ofstream file("our_enc_time.txt", std::ios_base::app); - file << "Our Enc Timings" << std::endl << std::endl; + std::ofstream file("enc_time.txt", std::ios_base::app); + file << "Our Enc Timings" << std::endl; for (int length = 10; length <= 200; length += 10){ // Create holder for timings. @@ -51,9 +49,9 @@ void our_enc_time(){ auto msk = Filter::msk_gen(pp); // Perform ROUND number of Enc. - for (int i = 0; i < ROUND; ++i){ + for (int i = 0; i < round; ++i){ // Create a random vector of desired length. - auto x = Helper::rand_int_vec(length, 1, 65536); + auto x = Helper::rand_int_vec(length, 1, std::numeric_limits::max()); // Encryption timings. auto start = std::chrono::high_resolution_clock::now(); @@ -63,16 +61,19 @@ void our_enc_time(){ } // Output the time. - file << "(" << length << ", " << time.count() / ROUND << ")" << std::endl; + file << "(" << length << ", " << time.count() / round << ")" << std::endl; + + // Close the BP. + BP::close(); } // Create some blank spaces. file << std::endl << std::endl; } -void sse_enc_time(){ +void sse_enc_time(const int round){ // Open the output files. - std::ofstream file("sse_enc_time.txt", std::ios_base::app); - file << "SSE Enc Timings" << std::endl << std::endl; + std::ofstream file("enc_time.txt", std::ios_base::app); + file << "SSE Enc Timings" << std::endl; // Setup and Encryption time. for (int length = 10; length <= 200; length += 10){ @@ -83,9 +84,9 @@ void sse_enc_time(){ auto prf = PRF(); // Perform ROUND number of setup. - for (int i = 0; i < ROUND; ++i){ + for (int i = 0; i < round; ++i){ // Create a random vector of desired length. - auto x = Helper::rand_int_vec(length, 1, 65536); + auto x = Helper::rand_int_vec(length, 1, std::numeric_limits::max()); // Setup timings. auto start = std::chrono::high_resolution_clock::now(); @@ -95,15 +96,14 @@ void sse_enc_time(){ } // Output the time. - file << "(" << length << ", " << time.count() / ROUND << ")" << std::endl; + file << "(" << length << ", " << time.count() / round << ")" << std::endl; } // Create some blank spaces. file << std::endl << std::endl; } - -int main(){ - ipe_enc_time(); - our_enc_time(); - sse_enc_time(); +void bench_enc_time(const int round){ + ipe_enc_time(round); + our_enc_time(round); + sse_enc_time(round); } diff --git a/experiment/exp.hpp b/experiment/exp.hpp new file mode 100644 index 0000000..583fd5a --- /dev/null +++ b/experiment/exp.hpp @@ -0,0 +1,31 @@ +#pragma once + +#include +#include +#include +#include "filter.hpp" +#include "ipe_filter.hpp" + +/// Benchmark for setup. +void ipe_setup_time(int round); +void our_setup_time(int round); +void sse_setup_time(int round); +void bench_setup_time(int round); + +/// Benchmark for encryption. +void ipe_enc_time(int round); +void our_enc_time(int round); +void sse_enc_time(int round); +void bench_enc_time(int round); + +/// Benchmark for generating queries for filtering multiple rows. +void ipe_mul_row_time(int round); +void our_mul_row_time(int round); +void sse_mul_row_time(int round); +void bench_mul_row_time(int round); + +/// Benchmark for generating single query while selecting different number of columns. +void ipe_sel_col_time(int round); +void our_sel_col_time(int round); +void sse_sel_col_time(int round); +void bench_sel_col_time(int round); diff --git a/experiment/multiple_row_time.cpp b/experiment/multiple_row_time.cpp new file mode 100644 index 0000000..ee58a67 --- /dev/null +++ b/experiment/multiple_row_time.cpp @@ -0,0 +1,149 @@ +/// This file benchmarks when total length is 20 and selecting all columns, the cost of filtering n rows. +/// Note this is client query operation time, hence keygen is used. + +#include "exp.hpp" + +void ipe_mul_row_time(const int round){ + // Open the output files. + std::ofstream time_file("multiple_row_time.txt", std::ios_base::app); + time_file << "IPE Row Timings" << std::endl; + + std::ofstream storage_file("multiple_row_storage.txt", std::ios_base::app); + storage_file << "IPE Row Storage" << std::endl; + + for (int num_row = 1; num_row <= 20; ++num_row){ + // Create holder for timings. + std::chrono::duration time{}; + + // Create pp and msk. + auto pp = IpeFilter::pp_gen(1, 20); + auto msk = IpeFilter::msk_gen(pp); + G2Vec sk; + + // Perform round number of Enc. + for (int i = 0; i < round; ++i){ + // Create a random vector of desired length. + auto y = Helper::rand_int_mat(20, 1, 1, std::numeric_limits::max()); + + // Encryption timings. + auto start = std::chrono::high_resolution_clock::now(); + sk = IpeFilter::keygen(pp, msk, y); + auto end = std::chrono::high_resolution_clock::now(); + time += end - start; + } + + // Compute the sk size. + unsigned long sk_size = sk.size() * sizeof(uint8_t) * pp.pairing_group->Gp->g2_size; + + // Output the time. + time_file << "(" << num_row << ", " << time.count() / round << ")" << std::endl; + + // Output the storage. + storage_file << "(" << num_row << ", " << sk_size << ")" << std::endl; + + // Close the BP. + BP::close(); + } + // Create some blank spaces. + time_file << std::endl << std::endl; + storage_file << std::endl << std::endl; +} + +void our_mul_row_time(const int round){ + // Open the output files. + std::ofstream time_file("multiple_row_time.txt", std::ios_base::app); + time_file << "Our Row Timings" << std::endl; + + std::ofstream storage_file("multiple_row_storage.txt", std::ios_base::app); + storage_file << "Our Row Storage" << std::endl; + + for (int num_row = 1; num_row <= 20; ++num_row){ + // Create holder for timings. + std::chrono::duration time{}; + + // Create pp and msk. + auto pp = Filter::pp_gen(1, 20); + auto msk = Filter::msk_gen(pp); + G2Vec sk; + + // Perform round number of Enc. + for (int i = 0; i < round; ++i){ + // Create a random vector of desired length. + auto y = Helper::rand_int_vec(20, 1, std::numeric_limits::max()); + + // Encryption timings. + auto start = std::chrono::high_resolution_clock::now(); + sk = Filter::keygen(pp, msk, y); + auto end = std::chrono::high_resolution_clock::now(); + time += end - start; + } + + // Compute the secret key size. + unsigned long sk_size = sk.size() * sizeof(uint8_t) * pp.pairing_group->Gp->g2_size; + + // Output the time. + time_file << "(" << num_row << ", " << time.count() / round << ")" << std::endl; + + // Output the storage. + storage_file << "(" << num_row << ", " << sk_size << ")" << std::endl; + + // Close the BP. + BP::close(); + } + // Create some blank spaces. + time_file << std::endl << std::endl; + storage_file << std::endl << std::endl; +} + +void sse_mul_row_time(const int round){ + // Open the output files. + std::ofstream time_file("multiple_row_time.txt", std::ios_base::app); + time_file << "SSE Row Timings" << std::endl; + + std::ofstream storage_file("multiple_row_storage.txt", std::ios_base::app); + storage_file << "SSE Row Storage" << std::endl; + + for (int num_row = 1; num_row <= 20; ++num_row){ + // Create holder for timings. + std::chrono::duration time{}; + + // Compute the number of rows used. + int pow_row = static_cast(std::pow(2, num_row)); + + // Create pp and msk. + auto prf = PRF(); + CharVec sk; + + // Perform ROUND number of setup. + for (int i = 0; i < round; ++i){ + for (int j = 0; j < pow_row; ++j){ + // Create a random vector of desired length. + auto y = Helper::rand_int_vec(20, 1, std::numeric_limits::max()); + + // Enc timings. + auto start = std::chrono::high_resolution_clock::now(); + for (const auto each_y : y) sk = prf.digest(Helper::int_to_char_vec(each_y)); + auto end = std::chrono::high_resolution_clock::now(); + time += end - start; + } + } + + // Also create holder for size. + unsigned long sk_size = sk.size() * sizeof(unsigned char) * 20 * pow_row; + + // Output the time. + time_file << "(" << num_row << ", " << time.count() / round << ")" << std::endl; + + // Output the storage. + storage_file << "(" << num_row << ", " << sk_size << ")" << std::endl; + } + // Create some blank spaces. + time_file << std::endl << std::endl; + storage_file << std::endl << std::endl; +} + +void bench_mul_row_time(const int round){ + ipe_mul_row_time(round); + our_mul_row_time(round); + sse_mul_row_time(round); +} diff --git a/experiment/run.cpp b/experiment/run.cpp new file mode 100644 index 0000000..930d3fc --- /dev/null +++ b/experiment/run.cpp @@ -0,0 +1,9 @@ +#include "exp.hpp" + +int main(){ + // bench_setup_time(1); + // bench_enc_time(1); + bench_mul_row_time(1); + + return 0; +} \ No newline at end of file diff --git a/experiment/select_col_time.cpp b/experiment/select_col_time.cpp new file mode 100644 index 0000000..ba525b5 --- /dev/null +++ b/experiment/select_col_time.cpp @@ -0,0 +1,115 @@ +#include "exp.hpp" + +void ipe_sel_col_time(const int round){ + // Open the output files. + std::ofstream file("sel_col_time.txt", std::ios_base::app); + file << "IPE Sel Col Timings" << std::endl; + + for (int num_col = 1; num_col <= 20; ++num_col){ + // Create holder for timings. + std::chrono::duration time{}; + + // Create pp and msk. + auto pp = IpeFilter::pp_gen(1, 20); + auto msk = IpeFilter::msk_gen(pp); + + // Perform round number of Enc. + for (int i = 0; i < round; ++i){ + // Create a random vector of desired length. + auto y = Helper::rand_int_mat(20, 1, 1, std::numeric_limits::max()); + + // Set the unselected portion to zero. + for (int j = num_col + 1; j < 20; ++j){ y[num_col][0] = 0; } + + // Encryption timings. + auto start = std::chrono::high_resolution_clock::now(); + auto sk = IpeFilter::keygen(pp, msk, y); + auto end = std::chrono::high_resolution_clock::now(); + time += end - start; + } + + // Output the time. + file << "(" << num_col << ", " << time.count() / round << ")" << std::endl; + + // Close the BP. + BP::close(); + } + // Create some blank spaces. + file << std::endl << std::endl; +} + +void our_sel_col_time(const int round){ + // Open the output files. + std::ofstream file("sel_col_time.txt", std::ios_base::app); + file << "Our Sel Col Timings" << std::endl; + + for (int num_col = 1; num_col <= 20; ++num_col){ + // Create holder for timings. + std::chrono::duration time{}; + + // Create pp and msk. + auto pp = Filter::pp_gen(1, 20); + auto msk = Filter::msk_gen(pp); + + // Perform round number of Enc. + for (int i = 0; i < round; ++i){ + // Create a random vector of desired length. + auto y = Helper::rand_int_vec(num_col, 1, std::numeric_limits::max()); + + // Set the unselected portion to zero. + IntVec sel; + for (int j = 0; j < num_col; ++j){ sel.push_back(j); } + + // Encryption timings. + auto start = std::chrono::high_resolution_clock::now(); + auto sk = Filter::keygen(pp, msk, y, sel); + auto end = std::chrono::high_resolution_clock::now(); + time += end - start; + } + + // Output the time. + file << "(" << num_col << ", " << time.count() / round << ")" << std::endl; + + // Close the BP. + BP::close(); + } + // Create some blank spaces. + file << std::endl << std::endl; +} + +void sse_sel_col_time(const int round){ + // Open the output files. + std::ofstream file("sel_col_time.txt", std::ios_base::app); + file << "SSE Sel Col Timings" << std::endl; + + for (int num_col = 1; num_col <= 20; ++num_col){ + // Create holder for timings. + std::chrono::duration time{}; + + // Create pp and msk. + auto prf = PRF(); + + // Perform round number of Enc. + for (int i = 0; i < round; ++i){ + // Create a random vector of desired length. + auto y = Helper::rand_int_vec(num_col, 1, std::numeric_limits::max()); + + // Enc timings. + auto start = std::chrono::high_resolution_clock::now(); + for (const auto each_y : y) auto sk = prf.digest(Helper::int_to_char_vec(each_y)); + auto end = std::chrono::high_resolution_clock::now(); + time += end - start; + } + + // Output the time. + file << "(" << num_col << ", " << time.count() / round << ")" << std::endl; + } + // Create some blank spaces. + file << std::endl << std::endl; +} + +void bench_sel_col_time(const int round){ + ipe_sel_col_time(round); + our_sel_col_time(round); + sse_sel_col_time(round); +} diff --git a/experiment/setup_time.cpp b/experiment/setup_time.cpp index d85ccbd..b1927b2 100644 --- a/experiment/setup_time.cpp +++ b/experiment/setup_time.cpp @@ -1,13 +1,8 @@ -#include -#include -#include "filter.hpp" -#include "ipe_filter.hpp" +#include "exp.hpp" -static int ROUND = 10; - -void ipe_setup_time(){ +void ipe_setup_time(const int round){ // Open the output files. - std::ofstream file("ipe_setup_time.txt", std::ios_base::app); + std::ofstream file("setup_time.txt", std::ios_base::app); file << "IPE Setup Timings" << std::endl << std::endl; for (int length = 10; length <= 200; length += 10){ @@ -15,7 +10,7 @@ void ipe_setup_time(){ std::chrono::duration time{}; // Perform ROUND number of setup. - for (int i = 0; i < ROUND; ++i){ + for (int i = 0; i < round; ++i){ // Setup timings. auto start = std::chrono::high_resolution_clock::now(); // Create pp and msk. @@ -23,18 +18,20 @@ void ipe_setup_time(){ auto msk = IpeFilter::msk_gen(pp); auto end = std::chrono::high_resolution_clock::now(); time += end - start; + // Close the pairing group. + BP::close(); } // Output the time. - file << "(" << length << ", " << time.count() / ROUND << ")" << std::endl; + file << "(" << length << ", " << time.count() / round << ")" << std::endl; } // Create some blank spaces. file << std::endl << std::endl; } -void our_setup_time(){ +void our_setup_time(const int round){ // Open the output files. - std::ofstream file("our_setup_time.txt", std::ios_base::app); + std::ofstream file("setup_time.txt", std::ios_base::app); file << "Our Setup Timings" << std::endl << std::endl; for (int length = 10; length <= 200; length += 10){ @@ -42,7 +39,7 @@ void our_setup_time(){ std::chrono::duration time{}; // Perform ROUND number of setup. - for (int i = 0; i < ROUND; ++i){ + for (int i = 0; i < round; ++i){ // Setup timings. auto start = std::chrono::high_resolution_clock::now(); // Create pp and msk. @@ -50,18 +47,20 @@ void our_setup_time(){ auto msk = Filter::msk_gen(pp); auto end = std::chrono::high_resolution_clock::now(); time += end - start; + // Close the pairing group. + BP::close(); } // Output the time. - file << "(" << length << ", " << time.count() / ROUND << ")" << std::endl; + file << "(" << length << ", " << time.count() / round << ")" << std::endl; } // Create some blank spaces. file << std::endl << std::endl; } -void sse_setup_time(){ +void sse_setup_time(const int round){ // Open the output files. - std::ofstream file("sse_setup_time.txt", std::ios_base::app); + std::ofstream file("setup_time.txt", std::ios_base::app); file << "SSE Setup Timings" << std::endl << std::endl; for (int length = 10; length <= 200; length += 10){ @@ -69,7 +68,7 @@ void sse_setup_time(){ std::chrono::duration time{}; // Perform ROUND number of setup. - for (int i = 0; i < ROUND; ++i){ + for (int i = 0; i < round; ++i){ // Setup timings. auto start = std::chrono::high_resolution_clock::now(); // Create the PRF object. @@ -79,15 +78,14 @@ void sse_setup_time(){ } // Output the time. - file << "(" << length << ", " << time.count() / ROUND << ")" << std::endl; + file << "(" << length << ", " << time.count() / round << ")" << std::endl; } // Create some blank spaces. file << std::endl << std::endl; } - -int main(){ - ipe_setup_time(); - our_setup_time(); - sse_setup_time(); +void bench_setup_time(const int round){ + ipe_setup_time(round); + our_setup_time(round); + sse_setup_time(round); }