}
}
-TEST(DipeTest, DipeDecryptFail) {
+TEST(DipeTest, DipeDecapFail) {
dipe_ctxt_t ctxt;
dipe_master_publickey_t pk;
dipe_master_secretkey_t msk;
element_random(ptxt);
- dipe_encrypt(param, pk, y, ptxt, &ctxt);
- dipe_decrypt(param, sk, "1234567890abcdef", y, ctxt, ptxtp);
+ dipe_encap(param, pk, y, ptxt, &ctxt);
+ dipe_decap(param, sk, "1234567890abcdef", y, ctxt, ptxtp);
EXPECT_NE(element_cmp(ptxt, ptxtp), 0);
dipe_free_ctxt(ctxt);
}
-TEST(DipeTest, DipeDecryptSuccess) {
+TEST(DipeTest, DipeDecapTrivialSuccess) {
dipe_ctxt_t ctxt;
dipe_master_publickey_t pk;
dipe_master_secretkey_t msk;
element_random(ptxt);
- dipe_encrypt(param, pk, y, ptxt, &ctxt);
- dipe_decrypt(param, sk, "1234567890abcdef", y, ctxt, ptxtp);
+ dipe_encap(param, pk, y, ptxt, &ctxt);
+ dipe_decap(param, sk, "1234567890abcdef", y, ctxt, ptxtp);
EXPECT_EQ(element_cmp(ptxt, ptxtp), 0);
dipe_free_ctxt(ctxt);
}
+TEST(DipeTest, DipeDecapSuccess) {
+ dipe_ctxt_t ctxt;
+ dipe_master_publickey_t pk;
+ dipe_master_secretkey_t msk;
+ dipe_secretkey_t sk;
+
+ element_t y[6];
+ element_t x[6];
+
+ for (size_t i = 0; i < 6; i+=2) {
+ element_init_Zr(y[i], *dipe_get_pairing(param));
+ element_init_Zr(x[i], *dipe_get_pairing(param));
+ element_init_Zr(y[i+1], *dipe_get_pairing(param));
+ element_init_Zr(x[i+1], *dipe_get_pairing(param));
+
+ element_set1(y[i]);
+ element_set1(x[i+1]);
+ element_random(y[i+1]);
+ element_neg(x[i], y[i+1]);
+ }
+
+ dipe_master_keygen(param, 6, &pk, &msk);
+ dipe_keygen(param, msk, "1234567890abcdef", y, &sk);
+
+ element_t ptxt, ptxtp;
+ element_init_GT(ptxt, *dipe_get_pairing(param));
+ element_init_GT(ptxtp, *dipe_get_pairing(param));
+
+ element_random(ptxt);
+
+ dipe_encap(param, pk, x, ptxt, &ctxt);
+
+ dipe_decap(param, sk, "1234567890abcdef", y, ctxt, ptxtp);
+ EXPECT_EQ(element_cmp(ptxt, ptxtp), 0);
+
+ /* non-matching CID */
+ dipe_decap(param, sk, "fedcba0987654321", y, ctxt, ptxtp);
+ EXPECT_NE(element_cmp(ptxt, ptxtp), 0);
+
+ /* inconsistent y value */
+ dipe_decap(param, sk, "1234567890abcdef", x, ctxt, ptxtp);
+ EXPECT_NE(element_cmp(ptxt, ptxtp), 0);
+
+ for (size_t i = 0; i < 6; ++i) {
+ element_clear(y[i]);
+ element_clear(x[i]);
+ }
+
+ element_clear(ptxt);
+ element_clear(ptxtp);
+
+ dipe_free_master_secretkey(msk);
+ dipe_free_master_publickey(pk);
+ dipe_free_secretkey(sk);
+ dipe_free_ctxt(ctxt);
+}
+
int main(int argc, char **argv) {
::testing::InitGoogleTest(&argc, argv);