]> git.siccegge.de Git - software/DIPE.git/blob - tests/testSS.cpp
d5c1244f96baba6cc4b4b45be7cfc7621622be41
[software/DIPE.git] / tests / testSS.cpp
1 #include <gtest/gtest.h>
2 #include <pbc/pbc.h>
3
4 #include "DIPE.h"
5
6 static dipe_param_t param;
7
8 TEST(SSText, SSBaseTest) {
9 element_t types[3];
10 element_init_G1(types[0], *dipe_get_pairing(param));
11 element_init_G2(types[1], *dipe_get_pairing(param));
12 element_init_GT(types[2], *dipe_get_pairing(param));
13 size_t parties = 7;
14 size_t dummies = 7;
15
16 element_t shared_secret;
17 element_t recovered_secret;
18
19 element_t* shares[parties];
20 element_t* dummy_shares[dummies];
21 element_t identities[parties];
22 element_t dummy_identities[dummies];
23
24 for (size_t j = 0; j < parties; ++j) {
25 shares[j] = (element_t*)calloc(1, sizeof(element_t));
26 element_init_Zr(identities[j], *dipe_get_pairing(param));
27 element_random(identities[j]);
28
29 if (j < dummies) {
30 dummy_shares[j] = (element_t*)calloc(1, sizeof(element_t));
31 element_init_Zr(dummy_identities[j], *dipe_get_pairing(param));
32 element_random(dummy_identities[j]);
33 }
34 }
35
36
37 for (size_t i = 0; i < 3; ++i) {
38 element_init_same_as(shared_secret, types[i]);
39 element_init_same_as(recovered_secret, types[i]);
40
41 for (size_t j = 0; j < parties; ++j) {
42 element_init_same_as(shares[j][0], types[i]);
43 //element_init_same_as(dummy_shares[j][0], types[i]);
44 element_random(shares[j][0]);
45 }
46
47 dipe_ss_share(param, parties, identities, parties, dummy_identities, 1, shares, &shared_secret, dummy_shares);
48 dipe_ss_recover(param, parties, identities, 1, shares, &recovered_secret);
49 EXPECT_EQ(element_cmp(shared_secret, recovered_secret), 0);
50 dipe_ss_recover(param, parties, dummy_identities, 1, dummy_shares, &recovered_secret);
51 EXPECT_EQ(element_cmp(shared_secret, recovered_secret), 0);
52
53
54 for (size_t j = 0; j < parties; ++j) {
55 element_clear(shares[j][0]);
56 element_clear(dummy_shares[j][0]);
57 }
58
59 element_clear(shared_secret);
60 element_clear(recovered_secret);
61 }
62
63 for (size_t i = 0; i < 3; ++i) {
64 element_clear(types[i]);
65 }
66 for (size_t j = 0; j < parties; ++j) {
67 element_clear(identities[j]);
68 element_clear(dummy_identities[j]);
69
70 free(shares[j]);
71 free(dummy_shares[j]);
72 }
73 }
74
75
76 int main(int argc, char **argv) {
77 ::testing::InitGoogleTest(&argc, argv);
78
79 dipe_init(fopen("../tests/a.param", "r"), &param);
80
81 int result = RUN_ALL_TESTS();
82 dipe_free_param(param);
83 return result;
84 }
85