diff options
author | Ruan HE <ruan.he@orange.com> | 2015-09-04 07:35:06 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@172.30.200.206> | 2015-09-04 07:35:06 +0000 |
commit | ca6aa8198d2335f8c326c3dd4d26bf5899064214 (patch) | |
tree | 6274a2d971fc0cac0896efe8583927d0190e3d20 /moon-abe/pbc-0.5.14/benchmark/multipairing.c | |
parent | 92fd2dbfb672d7b2b1cdfd5dd5cf89f7716b3e12 (diff) | |
parent | 3baeb11a8fbcfcdbc31976d421f17b85503b3ecd (diff) |
Merge "init attribute-based encryption"
Diffstat (limited to 'moon-abe/pbc-0.5.14/benchmark/multipairing.c')
-rw-r--r-- | moon-abe/pbc-0.5.14/benchmark/multipairing.c | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/moon-abe/pbc-0.5.14/benchmark/multipairing.c b/moon-abe/pbc-0.5.14/benchmark/multipairing.c new file mode 100644 index 00000000..39c9ce77 --- /dev/null +++ b/moon-abe/pbc-0.5.14/benchmark/multipairing.c @@ -0,0 +1,62 @@ +// Compares dedicated multipairing (product of pairings) routine with naive +// method. +#include <pbc.h> +#include "pbc_test.h" + +int main(int argc, char **argv) { + enum { K = 5 }; + pairing_t pairing; + element_t x[K], y[K], r, r2, tmp; + int i, n; + double t0, t1, ttotal, ttotalm; + + pbc_demo_pairing_init(pairing, argc, argv); + + for(i = 0; i < K; i++) { + element_init_G1(x[i], pairing); + element_init_G2(y[i], pairing); + } + element_init_GT(r, pairing); + element_init_GT(r2, pairing); + element_init_GT(tmp, pairing); + + n = 10; + ttotal = 0.0; + ttotalm = 0.0; + for (i=0; i<n; i++) { + int j; + for(j = 0; j < K; j++) { + element_random(x[j]); + element_random(y[j]); + } + + t0 = pbc_get_time(); + element_prod_pairing(r, x, y, K); + t1 = pbc_get_time(); + ttotalm += t1 - t0; + + t0 = pbc_get_time(); + element_pairing(r2, x[0], y[0]); + for(j = 1; j < K; j++) { + element_pairing(tmp, x[j], y[j]); + element_mul(r2, r2, tmp); + } + t1 = pbc_get_time(); + ttotal += t1 - t0; + + element_printf("e(x,y) = %B\n", r); + EXPECT(!element_cmp(r, r2)); + } + printf("average pairing time = %f\n", ttotal / n); + printf("average multi-pairing time = %f\n", ttotalm / n); + + for(i = 0; i < K; i++) { + element_clear(x[i]); + element_clear(y[i]); + } + element_clear(r); + element_clear(r2); + + pairing_clear(pairing); + return 0; +} |