1 #include <benchmark/benchmark.h>
5 void dipe_bench_master_keygen(benchmark::State
& state
) {
7 dipe_init(fopen("../tests/a.param", "r"), ¶m
);
9 dipe_master_publickey_t pk
;
10 dipe_master_secretkey_t sk
;
12 for (auto _
: state
) {
13 dipe_master_keygen(param
, 12, &pk
, &sk
);
16 dipe_free_param(param
);
20 void dipe_bench_keygen(benchmark::State
& state
) {
22 dipe_init(fopen("../tests/a.param", "r"), ¶m
);
24 dipe_master_publickey_t mpk
;
25 dipe_master_secretkey_t msk
;
28 dipe_master_keygen(param
, 2, &mpk
, &msk
);
30 for (size_t i
= 0; i
< 2; ++i
) {
31 element_init_Zr(y
[i
], *dipe_get_pairing(param
));
35 for (auto _
: state
) {
36 dipe_keygen(param
, msk
, "1234567890abcdef", y
, &sk
);
39 dipe_free_master_secretkey(msk
);
40 dipe_free_master_publickey(mpk
);
41 dipe_free_param(param
);
46 void dipe_bench_encryption(benchmark::State
& state
) {
48 dipe_init(fopen("../tests/a.param", "r"), ¶m
);
50 char ctxt
[state
.range(0)];
51 char ptxt
[state
.range(0)];
54 dipe_master_publickey_t pk
;
55 dipe_master_secretkey_t msk
;
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
));
69 element_random(y
[i
+1]);
70 element_neg(x
[i
], y
[i
+1]);
73 dipe_master_keygen(param
, 2, &pk
, &msk
);
74 dipe_keygen(param
, msk
, "1234567890abcdef", y
, &sk
);
75 overhead
= dipe_ciphertext_overhead(param
, 2, 0);
77 memset(ctxt
, 0, state
.range(0));
78 memset(ptxt
, 0, state
.range(0));
79 memcpy(ptxt
, "test", 4);
81 for (auto _
: state
) {
82 dipe_encrypt(param
, 1, &pk
, 1, x
, 4, ptxt
, state
.range(0), ctxt
);
86 ptxt_len
= dipe_decrypt(param
, 1, &sk
, 0, "1234567890abcdef", y
, state
.range(0), ctxt
, ptxt
);
89 for (size_t i
= 0; i
< 2; ++i
) {
94 dipe_free_master_secretkey(msk
);
95 dipe_free_master_publickey(pk
);
96 dipe_free_secretkey(sk
);
100 dipe_free_param(param
);
103 void dipe_bench_decryption(benchmark::State
& state
) {
105 dipe_init(fopen("../tests/a.param", "r"), ¶m
);
107 char ctxt
[state
.range(0)];
108 char ptxt
[state
.range(0)];
111 dipe_master_publickey_t pk
;
112 dipe_master_secretkey_t msk
;
115 element_t y
[2*state
.range(1)];
116 element_t x
[2*state
.range(1)];
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
));
125 element_set1(x
[i
+1]);
126 element_random(y
[i
+1]);
127 element_neg(x
[i
], y
[i
+1]);
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);
134 memset(ctxt
, 0, state
.range(0));
135 memset(ptxt
, 0, state
.range(0));
136 memcpy(ptxt
, "test", 4);
138 dipe_encrypt(param
, 1, &pk
, 1, x
, 4, ptxt
, state
.range(0), ctxt
);
140 for (auto _
: state
) {
141 dipe_decrypt(param
, 1, &sk
, 0, "1234567890abcdef", y
, state
.range(0), ctxt
, ptxt
);
144 for (size_t i
= 0; i
< 2*state
.range(1); ++i
) {
149 dipe_free_master_secretkey(msk
);
150 dipe_free_master_publickey(pk
);
151 dipe_free_secretkey(sk
);
153 dipe_free_param(param
);
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
);