]> git.siccegge.de Git - software/DIPE.git/blob - benchmark/benchDIPE.cpp
benchmarks\~
[software/DIPE.git] / benchmark / benchDIPE.cpp
1 #include <benchmark/benchmark.h>
2 #include <DIPE.h>
3 #include <string.h>
4
5 void dipe_bench_master_keygen(benchmark::State& state) {
6 dipe_param_t param;
7 dipe_init(fopen("../tests/a.param", "r"), &param);
8
9 dipe_master_publickey_t pk;
10 dipe_master_secretkey_t sk;
11
12 for (auto _ : state) {
13 dipe_master_keygen(param, 12, &pk, &sk);
14 }
15
16 dipe_free_param(param);
17 }
18
19
20 void dipe_bench_keygen(benchmark::State& state) {
21 dipe_param_t param;
22 dipe_init(fopen("../tests/a.param", "r"), &param);
23
24 dipe_master_publickey_t mpk;
25 dipe_master_secretkey_t msk;
26 dipe_secretkey_t sk;
27
28 dipe_master_keygen(param, 2, &mpk, &msk);
29 element_t y[2];
30 for (size_t i = 0; i < 2; ++i) {
31 element_init_Zr(y[i], *dipe_get_pairing(param));
32 element_random(y[i]);
33 }
34
35 for (auto _ : state) {
36 dipe_keygen(param, msk, "1234567890abcdef", y, &sk);
37 }
38
39 dipe_free_master_secretkey(msk);
40 dipe_free_master_publickey(mpk);
41 dipe_free_param(param);
42 }
43
44
45
46 void dipe_bench_encryption(benchmark::State& state) {
47 dipe_param_t param;
48 dipe_init(fopen("../tests/a.param", "r"), &param);
49
50 char ctxt[state.range(0)];
51 char ptxt[state.range(0)];
52 size_t ptxt_len;
53 size_t overhead;
54 dipe_master_publickey_t pk;
55 dipe_master_secretkey_t msk;
56 dipe_secretkey_t sk;
57
58 element_t y[2];
59 element_t x[2];
60
61 for (size_t i = 0; i < 2; i+=2) {
62 element_init_Zr(y[i], *dipe_get_pairing(param));
63 element_init_Zr(x[i], *dipe_get_pairing(param));
64 element_init_Zr(y[i+1], *dipe_get_pairing(param));
65 element_init_Zr(x[i+1], *dipe_get_pairing(param));
66
67 element_set1(y[i]);
68 element_set1(x[i+1]);
69 element_random(y[i+1]);
70 element_neg(x[i], y[i+1]);
71 }
72
73 dipe_master_keygen(param, 2, &pk, &msk);
74 dipe_keygen(param, msk, "1234567890abcdef", y, &sk);
75 overhead = dipe_ciphertext_overhead(param, 2, 0);
76
77 memset(ctxt, 0, state.range(0));
78 memset(ptxt, 0, state.range(0));
79 memcpy(ptxt, "test", 4);
80
81 for (auto _ : state) {
82 dipe_encrypt(param, 1, &pk, 1, x, 4, ptxt, state.range(0), ctxt);
83 }
84
85
86 ptxt_len = dipe_decrypt(param, 1, &sk, 0, "1234567890abcdef", y, state.range(0), ctxt, ptxt);
87
88
89 for (size_t i = 0; i < 2; ++i) {
90 element_clear(y[i]);
91 element_clear(x[i]);
92 }
93
94 dipe_free_master_secretkey(msk);
95 dipe_free_master_publickey(pk);
96 dipe_free_secretkey(sk);
97
98
99
100 dipe_free_param(param);
101 }
102
103 void dipe_bench_decryption(benchmark::State& state) {
104 dipe_param_t param;
105 dipe_init(fopen("../tests/a.param", "r"), &param);
106
107 char ctxt[state.range(0)];
108 char ptxt[state.range(0)];
109 size_t ptxt_len;
110 size_t overhead;
111 dipe_master_publickey_t pk;
112 dipe_master_secretkey_t msk;
113 dipe_secretkey_t sk;
114
115 element_t y[2*state.range(1)];
116 element_t x[2*state.range(1)];
117
118 for (size_t i = 0; i < 2*state.range(1); i+=2) {
119 element_init_Zr(y[i], *dipe_get_pairing(param));
120 element_init_Zr(x[i], *dipe_get_pairing(param));
121 element_init_Zr(y[i+1], *dipe_get_pairing(param));
122 element_init_Zr(x[i+1], *dipe_get_pairing(param));
123
124 element_set1(y[i]);
125 element_set1(x[i+1]);
126 element_random(y[i+1]);
127 element_neg(x[i], y[i+1]);
128 }
129
130 dipe_master_keygen(param, 2*state.range(1), &pk, &msk);
131 dipe_keygen(param, msk, "1234567890abcdef", y, &sk);
132 overhead = dipe_ciphertext_overhead(param, 2*state.range(1), 0);
133
134 memset(ctxt, 0, state.range(0));
135 memset(ptxt, 0, state.range(0));
136 memcpy(ptxt, "test", 4);
137
138 dipe_encrypt(param, 1, &pk, 1, x, 4, ptxt, state.range(0), ctxt);
139
140 for (auto _ : state) {
141 dipe_decrypt(param, 1, &sk, 0, "1234567890abcdef", y, state.range(0), ctxt, ptxt);
142 }
143
144 for (size_t i = 0; i < 2*state.range(1); ++i) {
145 element_clear(y[i]);
146 element_clear(x[i]);
147 }
148
149 dipe_free_master_secretkey(msk);
150 dipe_free_master_publickey(pk);
151 dipe_free_secretkey(sk);
152
153 dipe_free_param(param);
154 }
155
156
157
158
159 BENCHMARK(dipe_bench_master_keygen)->Unit(benchmark::kMillisecond);
160 BENCHMARK(dipe_bench_keygen)->Unit(benchmark::kMillisecond);
161 BENCHMARK(dipe_bench_encryption)->Ranges({{1<<12, 1<<15}, {1, 18}})->Unit(benchmark::kMillisecond);
162 BENCHMARK(dipe_bench_decryption)->Ranges({{1<<12, 1<<15}, {1, 18}})->Unit(benchmark::kMillisecond);
163
164 BENCHMARK_MAIN();