From: Christoph Egger Date: Thu, 16 Jan 2020 23:57:40 +0000 (+0100) Subject: benchmarks\~ X-Git-Url: https://git.siccegge.de//index.cgi?a=commitdiff_plain;p=software%2FDIPE.git benchmarks\~ --- diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..35c4284 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "benchmark/gbench"] + path = benchmark/gbench + url = https://github.com/google/benchmark.git diff --git a/CMakeLists.txt b/CMakeLists.txt index 823157a..304cf04 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,3 +8,4 @@ set(CMAKE_VERBOSE_MAKEFILE on) add_subdirectory(src) add_subdirectory(tests) +add_subdirectory(benchmark) diff --git a/benchmark/CMakeLists.txt b/benchmark/CMakeLists.txt new file mode 100644 index 0000000..d37a4a9 --- /dev/null +++ b/benchmark/CMakeLists.txt @@ -0,0 +1,9 @@ +add_subdirectory(gbench) + +add_executable(benchPBC benchPBC.cpp) +target_link_libraries(benchPBC benchmark::benchmark pbc) + +add_executable(benchDIPE benchDIPE.cpp) +target_link_libraries(benchDIPE benchmark::benchmark DIPE) + + diff --git a/benchmark/benchDIPE.cpp b/benchmark/benchDIPE.cpp new file mode 100644 index 0000000..d6f9bce --- /dev/null +++ b/benchmark/benchDIPE.cpp @@ -0,0 +1,164 @@ +#include +#include +#include + +void dipe_bench_master_keygen(benchmark::State& state) { + dipe_param_t param; + dipe_init(fopen("../tests/a.param", "r"), ¶m); + + dipe_master_publickey_t pk; + dipe_master_secretkey_t sk; + + for (auto _ : state) { + dipe_master_keygen(param, 12, &pk, &sk); + } + + dipe_free_param(param); +} + + +void dipe_bench_keygen(benchmark::State& state) { + dipe_param_t param; + dipe_init(fopen("../tests/a.param", "r"), ¶m); + + dipe_master_publickey_t mpk; + dipe_master_secretkey_t msk; + dipe_secretkey_t sk; + + dipe_master_keygen(param, 2, &mpk, &msk); + element_t y[2]; + for (size_t i = 0; i < 2; ++i) { + element_init_Zr(y[i], *dipe_get_pairing(param)); + element_random(y[i]); + } + + for (auto _ : state) { + dipe_keygen(param, msk, "1234567890abcdef", y, &sk); + } + + dipe_free_master_secretkey(msk); + dipe_free_master_publickey(mpk); + dipe_free_param(param); +} + + + +void dipe_bench_encryption(benchmark::State& state) { + dipe_param_t param; + dipe_init(fopen("../tests/a.param", "r"), ¶m); + + char ctxt[state.range(0)]; + char ptxt[state.range(0)]; + size_t ptxt_len; + size_t overhead; + dipe_master_publickey_t pk; + dipe_master_secretkey_t msk; + dipe_secretkey_t sk; + + element_t y[2]; + element_t x[2]; + + for (size_t i = 0; i < 2; i+=2) { + element_init_Zr(y[i], *dipe_get_pairing(param)); + element_init_Zr(x[i], *dipe_get_pairing(param)); + element_init_Zr(y[i+1], *dipe_get_pairing(param)); + element_init_Zr(x[i+1], *dipe_get_pairing(param)); + + element_set1(y[i]); + element_set1(x[i+1]); + element_random(y[i+1]); + element_neg(x[i], y[i+1]); + } + + dipe_master_keygen(param, 2, &pk, &msk); + dipe_keygen(param, msk, "1234567890abcdef", y, &sk); + overhead = dipe_ciphertext_overhead(param, 2, 0); + + memset(ctxt, 0, state.range(0)); + memset(ptxt, 0, state.range(0)); + memcpy(ptxt, "test", 4); + + for (auto _ : state) { + dipe_encrypt(param, 1, &pk, 1, x, 4, ptxt, state.range(0), ctxt); + } + + + ptxt_len = dipe_decrypt(param, 1, &sk, 0, "1234567890abcdef", y, state.range(0), ctxt, ptxt); + + + for (size_t i = 0; i < 2; ++i) { + element_clear(y[i]); + element_clear(x[i]); + } + + dipe_free_master_secretkey(msk); + dipe_free_master_publickey(pk); + dipe_free_secretkey(sk); + + + + dipe_free_param(param); +} + +void dipe_bench_decryption(benchmark::State& state) { + dipe_param_t param; + dipe_init(fopen("../tests/a.param", "r"), ¶m); + + char ctxt[state.range(0)]; + char ptxt[state.range(0)]; + size_t ptxt_len; + size_t overhead; + dipe_master_publickey_t pk; + dipe_master_secretkey_t msk; + dipe_secretkey_t sk; + + element_t y[2*state.range(1)]; + element_t x[2*state.range(1)]; + + for (size_t i = 0; i < 2*state.range(1); i+=2) { + element_init_Zr(y[i], *dipe_get_pairing(param)); + element_init_Zr(x[i], *dipe_get_pairing(param)); + element_init_Zr(y[i+1], *dipe_get_pairing(param)); + element_init_Zr(x[i+1], *dipe_get_pairing(param)); + + element_set1(y[i]); + element_set1(x[i+1]); + element_random(y[i+1]); + element_neg(x[i], y[i+1]); + } + + dipe_master_keygen(param, 2*state.range(1), &pk, &msk); + dipe_keygen(param, msk, "1234567890abcdef", y, &sk); + overhead = dipe_ciphertext_overhead(param, 2*state.range(1), 0); + + memset(ctxt, 0, state.range(0)); + memset(ptxt, 0, state.range(0)); + memcpy(ptxt, "test", 4); + + dipe_encrypt(param, 1, &pk, 1, x, 4, ptxt, state.range(0), ctxt); + + for (auto _ : state) { + dipe_decrypt(param, 1, &sk, 0, "1234567890abcdef", y, state.range(0), ctxt, ptxt); + } + + for (size_t i = 0; i < 2*state.range(1); ++i) { + element_clear(y[i]); + element_clear(x[i]); + } + + dipe_free_master_secretkey(msk); + dipe_free_master_publickey(pk); + dipe_free_secretkey(sk); + + dipe_free_param(param); +} + + + + +BENCHMARK(dipe_bench_master_keygen)->Unit(benchmark::kMillisecond); +BENCHMARK(dipe_bench_keygen)->Unit(benchmark::kMillisecond); +BENCHMARK(dipe_bench_encryption)->Ranges({{1<<12, 1<<15}, {1, 18}})->Unit(benchmark::kMillisecond); +BENCHMARK(dipe_bench_decryption)->Ranges({{1<<12, 1<<15}, {1, 18}})->Unit(benchmark::kMillisecond); + +BENCHMARK_MAIN(); diff --git a/benchmark/benchPBC.cpp b/benchmark/benchPBC.cpp new file mode 100644 index 0000000..980de5e --- /dev/null +++ b/benchmark/benchPBC.cpp @@ -0,0 +1,35 @@ +#include +#include + +void pbc_multiply_elements(benchmark::State& state) { + pairing_t pairing; + FILE *fp; + + fp = fopen("../tests/a.param", "r"); + if (fp == NULL) { + perror("Reading Pairing Parameters"); + return; + } + char buffer[2<<16]; + size_t count = fread(buffer, 1, 2<<16, fp); + pairing_init_set_buf(pairing, buffer, 2<<16); + + element_t a, b, c; + element_init_G1(a, pairing); + element_init_G1(b, pairing); + element_init_G1(c, pairing); + + element_random(a); + element_random(b); + for (auto _ : state) { + element_mul(c, a, b); + } +} + + + + + +BENCHMARK(pbc_multiply_elements); + +BENCHMARK_MAIN(); diff --git a/benchmark/gbench b/benchmark/gbench new file mode 160000 index 0000000..daff5fe --- /dev/null +++ b/benchmark/gbench @@ -0,0 +1 @@ +Subproject commit daff5fead3fbe22c6fc58310ca3f49caf117f185