]> git.siccegge.de Git - software/DIPE.git/commitdiff
Extend tests
authorChristoph Egger <christoph@christoph-egger.org>
Mon, 6 Jan 2020 22:00:54 +0000 (23:00 +0100)
committerChristoph Egger <christoph@christoph-egger.org>
Mon, 6 Jan 2020 22:00:54 +0000 (23:00 +0100)
tests/testDIPE.cpp

index c335d48e4fcc1baba98f9930d44f1b34b37e4124..f1b6332398d5f95b6ad7aed938424324b5959260 100644 (file)
@@ -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);