1 #include <gtest/gtest.h>
6 static dipe_param_t param
;
8 TEST(DipeTest
, DipeMasterKeygen
) {
9 dipe_master_publickey_t pk
;
10 dipe_master_secretkey_t sk
;
12 dipe_master_keygen(param
, 12, &pk
, &sk
);
14 dipe_free_master_secretkey(sk
);
15 dipe_free_master_publickey(pk
);
18 TEST(DipeTest
, DipeKeygen
) {
19 dipe_master_publickey_t pk
;
20 dipe_master_secretkey_t msk
;
23 for (size_t i
= 0; i
< 5; ++i
) {
24 element_init_Zr(y
[i
], *dipe_get_pairing(param
));
28 dipe_master_keygen(param
, 5, &pk
, &msk
);
29 dipe_keygen(param
, msk
, "1234567890abcdef", y
, &sk
);
31 dipe_free_master_secretkey(msk
);
32 dipe_free_master_publickey(pk
);
33 dipe_free_secretkey(sk
);
35 for (size_t i
= 0; i
< 5; ++i
) {
40 TEST(DipeTest
, DipeDecryptFail
) {
42 dipe_master_publickey_t pk
;
43 dipe_master_secretkey_t msk
;
47 for (size_t i
= 0; i
< 5; ++i
) {
48 element_init_Zr(y
[i
], *dipe_get_pairing(param
));
52 dipe_master_keygen(param
, 5, &pk
, &msk
);
53 dipe_keygen(param
, msk
, "1234567890abcdef", y
, &sk
);
55 element_t ptxt
, ptxtp
;
56 element_init_GT(ptxt
, *dipe_get_pairing(param
));
57 element_init_GT(ptxtp
, *dipe_get_pairing(param
));
61 dipe_encrypt(param
, pk
, y
, ptxt
, &ctxt
);
62 dipe_decrypt(param
, sk
, "1234567890abcdef", y
, ctxt
, ptxtp
);
64 EXPECT_NE(element_cmp(ptxt
, ptxtp
), 0);
66 for (size_t i
= 0; i
< 5; ++i
) {
73 dipe_free_master_secretkey(msk
);
74 dipe_free_master_publickey(pk
);
75 dipe_free_secretkey(sk
);
79 TEST(DipeTest
, DipeDecryptSuccess
) {
81 dipe_master_publickey_t pk
;
82 dipe_master_secretkey_t msk
;
86 for (size_t i
= 0; i
< 5; ++i
) {
87 element_init_Zr(y
[i
], *dipe_get_pairing(param
));
91 dipe_master_keygen(param
, 5, &pk
, &msk
);
92 dipe_keygen(param
, msk
, "1234567890abcdef", y
, &sk
);
94 element_t ptxt
, ptxtp
;
95 element_init_GT(ptxt
, *dipe_get_pairing(param
));
96 element_init_GT(ptxtp
, *dipe_get_pairing(param
));
100 dipe_encrypt(param
, pk
, y
, ptxt
, &ctxt
);
101 dipe_decrypt(param
, sk
, "1234567890abcdef", y
, ctxt
, ptxtp
);
102 element_printf("%B\n", ptxt
);
103 element_printf("%B\n", ptxtp
);
105 EXPECT_EQ(element_cmp(ptxt
, ptxtp
), 0);
107 for (size_t i
= 0; i
< 5; ++i
) {
112 element_clear(ptxtp
);
114 dipe_free_master_secretkey(msk
);
115 dipe_free_master_publickey(pk
);
116 dipe_free_secretkey(sk
);
117 dipe_free_ctxt(ctxt
);
121 int main(int argc
, char **argv
) {
122 ::testing::InitGoogleTest(&argc
, argv
);
124 dipe_init(fopen("../tests/a.param", "r"), ¶m
);
126 int result
= RUN_ALL_TESTS();
127 dipe_free_param(param
);