diff options
author | WuKong <rebirthmonkey@gmail.com> | 2015-09-04 09:25:34 +0200 |
---|---|---|
committer | WuKong <rebirthmonkey@gmail.com> | 2015-09-04 09:25:34 +0200 |
commit | 3baeb11a8fbcfcdbc31976d421f17b85503b3ecd (patch) | |
tree | 04891d88c1127148f1b390b5a24414e85b270aee /moon-abe/pbc-0.5.14/guru/exp_test.c | |
parent | 67c5b73910f5fc437429c356978081b252a59480 (diff) |
init attribute-based encryption
Change-Id: Iba1a3d722110abf747a0fba366f3ebc911d25b25
Diffstat (limited to 'moon-abe/pbc-0.5.14/guru/exp_test.c')
-rw-r--r-- | moon-abe/pbc-0.5.14/guru/exp_test.c | 88 |
1 files changed, 88 insertions, 0 deletions
diff --git a/moon-abe/pbc-0.5.14/guru/exp_test.c b/moon-abe/pbc-0.5.14/guru/exp_test.c new file mode 100644 index 00000000..02ccfaba --- /dev/null +++ b/moon-abe/pbc-0.5.14/guru/exp_test.c @@ -0,0 +1,88 @@ +// Mutliexponentiation benchmark and test. + +#include <string.h> +#include "pbc.h" +#include "pbc_test.h" + +int main(int argc, char **argv) { + pairing_t pairing; + element_t g1, u1, up1, g2, u2, up2, r; + mpz_t r_mpz; + element_pp_t g1_pp, g2_pp; + double t0, t1; + int i, n; + + printf("reading pairing from stdin...\n"); + pbc_demo_pairing_init(pairing, argc, argv); + + element_init(r, pairing->Zr); + element_init(g1, pairing->G1); + element_init(u1, pairing->G1); + element_init(up1, pairing->G1); + element_init(g2, pairing->G2); + element_init(u2, pairing->G2); + element_init(up2, pairing->G2); + + element_random(r); + element_random(g1); + element_random(g2); + + mpz_init(r_mpz); + element_to_mpz(r_mpz, r); + + element_pp_init(g1_pp, g1); + element_pp_init(g2_pp, g2); + + n = 100; + t0 = pbc_get_time(); + for (i=0; i<n; i++) { + element_pow_mpz(u1, g1, r_mpz); + } + t1 = pbc_get_time(); + printf("G1 exp:\t\t%fs\n", t1 - t0); + + n = 100; + t0 = pbc_get_time(); + for (i=0; i<n; i++) { + element_pow_mpz(u2, g2, r_mpz); + } + t1 = pbc_get_time(); + printf("G2 exp:\t\t%fs\n", t1 - t0); + + n = 100; + t0 = pbc_get_time(); + for (i=0; i<n; i++) { + element_pp_pow(up1, r_mpz, g1_pp); + } + t1 = pbc_get_time(); + printf("G1 pp exp:\t%fs\n", t1 - t0); + + n = 100; + t0 = pbc_get_time(); + for (i=0; i<n; i++) { + element_pp_pow(up2, r_mpz, g2_pp); + } + t1 = pbc_get_time(); + printf("G2 pp exp:\t%fs\n", t1 - t0); + + if (element_cmp(u1, up1)) { + printf("Oops 1!\n"); + } + if (element_cmp(u2, up2)) { + printf("Oops 2!\n"); + } + + mpz_clear(r_mpz); + element_clear(g1); + element_clear(u1); + element_clear(up1); + element_clear(g2); + element_clear(u2); + element_clear(up2); + element_clear(r); + element_pp_clear(g1_pp); + element_pp_clear(g2_pp); + pairing_clear(pairing); + + return 0; +} |