--- /dev/null
+#include <benchmark/benchmark.h>
+#include <DIPE.h>
+#include <string.h>
+
+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();