From 805a7d21d3115a2d2eafd9ebb1d32ea0a0826d66 Mon Sep 17 00:00:00 2001 From: Christoph Egger Date: Mon, 6 Jan 2020 23:00:54 +0100 Subject: [PATCH] Extend tests --- tests/testDIPE.cpp | 69 ++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 63 insertions(+), 6 deletions(-) diff --git a/tests/testDIPE.cpp b/tests/testDIPE.cpp index c335d48..f1b6332 100644 --- a/tests/testDIPE.cpp +++ b/tests/testDIPE.cpp @@ -37,7 +37,7 @@ TEST(DipeTest, DipeKeygen) { } } -TEST(DipeTest, DipeDecryptFail) { +TEST(DipeTest, DipeDecapFail) { dipe_ctxt_t ctxt; dipe_master_publickey_t pk; dipe_master_secretkey_t msk; @@ -58,8 +58,8 @@ TEST(DipeTest, DipeDecryptFail) { 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); @@ -76,7 +76,7 @@ TEST(DipeTest, DipeDecryptFail) { dipe_free_ctxt(ctxt); } -TEST(DipeTest, DipeDecryptSuccess) { +TEST(DipeTest, DipeDecapTrivialSuccess) { dipe_ctxt_t ctxt; dipe_master_publickey_t pk; dipe_master_secretkey_t msk; @@ -97,8 +97,8 @@ TEST(DipeTest, DipeDecryptSuccess) { 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); @@ -115,6 +115,63 @@ TEST(DipeTest, DipeDecryptSuccess) { 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); -- 2.39.5