aboutsummaryrefslogtreecommitdiff
path: root/test_crypto.c
diff options
context:
space:
mode:
authorMarkus Teich <markus.teich@stusta.mhn.de>2016-06-16 00:09:29 +0200
committerMarkus Teich <markus.teich@stusta.mhn.de>2016-06-17 10:29:49 +0200
commit761dd37e1f905719df2cd8f4420e4b46da80bffb (patch)
treeb93ec567a19e2407274fc3350ea51186aac8f091 /test_crypto.c
parent6f3fb463176c04c9a258fce820ec66724a4d13f4 (diff)
refactor smc and ec crypto functions and ad 0og zkp
Diffstat (limited to 'test_crypto.c')
-rw-r--r--test_crypto.c160
1 files changed, 90 insertions, 70 deletions
diff --git a/test_crypto.c b/test_crypto.c
index 610dc6d..5cc2ed1 100644
--- a/test_crypto.c
+++ b/test_crypto.c
@@ -23,111 +23,85 @@
#include "smc.h"
#include "test.h"
-extern gcry_mpi_point_t ec_gen;
extern gcry_ctx_t ec_ctx;
-
-int
-test_brandt_ec_keypair_create ()
-{
- gcry_mpi_t skey;
- gcry_mpi_point_t pkey1;
- gcry_mpi_point_t pkey2 = gcry_mpi_point_new (0);
-
- brandt_ec_keypair_create (&pkey1, &skey);
- check (skey, "no sec key created");
- check (pkey1, "no pub key created");
- check (pkey2, "could not init pkey2");
-
- gcry_mpi_ec_mul (pkey2, skey, ec_gen, ec_ctx);
- check (!brandt_ec_point_cmp (pkey1, pkey2), "pkeys do not match");
-
- gcry_mpi_release (skey);
- gcry_mpi_point_release (pkey1);
- gcry_mpi_point_release (pkey2);
-}
+extern gcry_mpi_point_t ec_gen;
+extern gcry_mpi_point_t ec_zero;
+extern gcry_mpi_t ec_n;
int
test_smc_zkp_dl ()
{
- static int first = 1;
- gcry_mpi_t c;
- gcry_mpi_t r;
- gcry_mpi_t s;
- gcry_mpi_t x;
- gcry_mpi_point_t a;
- gcry_mpi_point_t g;
+ gcry_mpi_t c = gcry_mpi_new (0);
+ gcry_mpi_t r = gcry_mpi_new (0);
+ gcry_mpi_t x = gcry_mpi_new (0);
+ gcry_mpi_point_t a = gcry_mpi_point_new (0);
+ gcry_mpi_point_t g = gcry_mpi_point_new (0);
gcry_mpi_point_t v = gcry_mpi_point_new (0);
- check (v, "no pub key initialized");
- brandt_ec_keypair_create (&g, &s);
- check (g, "no gen created");
+ brandt_ec_keypair_create (g, c);
- if (first)
+ if (0 == tests_run)
{
+ /**TODO: there has to be a better way to copy a point */
gcry_mpi_ec_mul (g, GCRYMPI_CONST_ONE, ec_gen, ec_ctx);
- first = 0;
}
- brandt_ec_skey_create (&x);
- check (x, "no sec key created");
- gcry_mpi_ec_mul (v, x, g, ec_ctx);
- check (v, "no pub key created");
+ brandt_ec_keypair_create_base (v, x, g);
+
+ smc_zkp_dl (v, g, x, a, c, r);
+ check (!smc_zkp_dl_check (v, g, a, c, r), "zkp dl wrong");
- smc_zkp_dl (v, g, x, &a, &c, &r);
- check (!smc_zkp_dl_check (v, g, a, c, r), "zkp was false, should be true");
+ check (gcry_mpi_ec_curve_point (a, ec_ctx), "not on curve");
+ check (gcry_mpi_ec_curve_point (g, ec_ctx), "not on curve");
+ check (gcry_mpi_ec_curve_point (v, ec_ctx), "not on curve");
gcry_mpi_release (c);
gcry_mpi_release (r);
- gcry_mpi_release (s);
gcry_mpi_release (x);
gcry_mpi_point_release (a);
gcry_mpi_point_release (g);
gcry_mpi_point_release (v);
}
+
int
test_smc_zkp_2dle ()
{
- static int first = 1;
- gcry_mpi_t c;
- gcry_mpi_t r;
- gcry_mpi_t s;
- gcry_mpi_t x;
- gcry_mpi_point_t a;
- gcry_mpi_point_t b;
- gcry_mpi_point_t g1;
- gcry_mpi_point_t g2;
+ gcry_mpi_t c = gcry_mpi_new (0);
+ gcry_mpi_t r = gcry_mpi_new (0);
+ gcry_mpi_t x = gcry_mpi_new (0);
+ gcry_mpi_point_t a = gcry_mpi_point_new (0);
+ gcry_mpi_point_t b = gcry_mpi_point_new (0);
+ gcry_mpi_point_t g1 = gcry_mpi_point_new (0);
+ gcry_mpi_point_t g2 = gcry_mpi_point_new (0);
gcry_mpi_point_t v = gcry_mpi_point_new (0);
gcry_mpi_point_t w = gcry_mpi_point_new (0);
- check (v, "no pub1 key initialized");
- check (w, "no pub2 key initialized");
- brandt_ec_keypair_create (&g1, &s);
- gcry_mpi_release (s);
- brandt_ec_keypair_create (&g2, &s);
- check (g1, "no gen1 created");
- check (g2, "no gen2 created");
+ brandt_ec_keypair_create (g1, c);
+ brandt_ec_keypair_create (g2, c);
- if (first)
+ if (0 == tests_run)
{
+ /**TODO: there has to be a better way to copy a point */
gcry_mpi_ec_mul (g1, GCRYMPI_CONST_ONE, ec_gen, ec_ctx);
gcry_mpi_ec_mul (g2, GCRYMPI_CONST_ONE, ec_gen, ec_ctx);
- first = 0;
}
- brandt_ec_skey_create (&x);
- check (x, "no sec key created");
- gcry_mpi_ec_mul (v, x, g1, ec_ctx);
- check (v, "no pub1 key created");
+ brandt_ec_keypair_create_base (v, x, g1);
gcry_mpi_ec_mul (w, x, g2, ec_ctx);
- check (w, "no pub2 key created");
- smc_zkp_2dle (v, w, g1, g2, x, &a, &b, &c, &r);
- check (!smc_zkp_2dle_check (v, w, g1, g2, a, b, c, r), "zkp was false, should be true");
+ smc_zkp_2dle (v, w, g1, g2, x, a, b, c, r);
+ check (!smc_zkp_2dle_check (v, w, g1, g2, a, b, c, r), "zkp 2dle wrong");
+
+ check (gcry_mpi_ec_curve_point (a, ec_ctx), "not on curve");
+ check (gcry_mpi_ec_curve_point (b, ec_ctx), "not on curve");
+ check (gcry_mpi_ec_curve_point (g1, ec_ctx), "not on curve");
+ check (gcry_mpi_ec_curve_point (g2, ec_ctx), "not on curve");
+ check (gcry_mpi_ec_curve_point (v, ec_ctx), "not on curve");
+ check (gcry_mpi_ec_curve_point (w, ec_ctx), "not on curve");
gcry_mpi_release (c);
gcry_mpi_release (r);
- gcry_mpi_release (s);
gcry_mpi_release (x);
gcry_mpi_point_release (a);
gcry_mpi_point_release (b);
@@ -137,19 +111,65 @@ test_smc_zkp_2dle ()
gcry_mpi_point_release (w);
}
+
+int
+test_smc_zkp_0og ()
+{
+ gcry_mpi_t c = gcry_mpi_new (0);
+ gcry_mpi_t d1 = gcry_mpi_new (0);
+ gcry_mpi_t d2 = gcry_mpi_new (0);
+ gcry_mpi_t r1 = gcry_mpi_new (0);
+ gcry_mpi_t r2 = gcry_mpi_new (0);
+ gcry_mpi_point_t y = gcry_mpi_point_new (0);
+ gcry_mpi_point_t alpha = gcry_mpi_point_new (0);
+ gcry_mpi_point_t beta = gcry_mpi_point_new (0);
+ gcry_mpi_point_t a1 = gcry_mpi_point_new (0);
+ gcry_mpi_point_t a2 = gcry_mpi_point_new (0);
+ gcry_mpi_point_t b1 = gcry_mpi_point_new (0);
+ gcry_mpi_point_t b2 = gcry_mpi_point_new (0);
+
+ brandt_ec_keypair_create (y, c);
+
+ smc_zkp_0og (alpha, (tests_run % 2 ? ec_zero : ec_gen), y, beta, a1, a2, b1,
+ b2, c, d1, d2, r1, r2);
+ check (!smc_zkp_0og_check (alpha, y, beta, a1, a2, b1, b2, c, d1, d2, r1,
+ r2), "zkp 0og is wrong");
+
+ check (gcry_mpi_ec_curve_point (y, ec_ctx), "not on curve");
+ check (gcry_mpi_ec_curve_point (alpha, ec_ctx), "not on curve");
+ check (gcry_mpi_ec_curve_point (beta, ec_ctx), "not on curve");
+ check (gcry_mpi_ec_curve_point (a1, ec_ctx), "not on curve");
+ check (gcry_mpi_ec_curve_point (a2, ec_ctx), "not on curve");
+ check (gcry_mpi_ec_curve_point (b1, ec_ctx), "not on curve");
+ check (gcry_mpi_ec_curve_point (b2, ec_ctx), "not on curve");
+
+ gcry_mpi_release (c);
+ gcry_mpi_release (d1);
+ gcry_mpi_release (d2);
+ gcry_mpi_release (r1);
+ gcry_mpi_release (r2);
+ gcry_mpi_point_release (y);
+ gcry_mpi_point_release (alpha);
+ gcry_mpi_point_release (beta);
+ gcry_mpi_point_release (a1);
+ gcry_mpi_point_release (a2);
+ gcry_mpi_point_release (b1);
+ gcry_mpi_point_release (b2);
+}
+
+
int
main (int argc, char *argv[])
{
- int repeat = 50;
- int i;
+ int repeat = 32;
BRANDT_init ();
- for (i = 0; i < repeat; i++)
+ for (tests_run = 0; tests_run < repeat; tests_run++)
{
- run (test_brandt_ec_keypair_create);
run (test_smc_zkp_dl);
run (test_smc_zkp_2dle);
+ run (test_smc_zkp_0og);
}
return ret;