diff options
author | Markus Teich <markus.teich@stusta.mhn.de> | 2016-06-21 23:06:15 +0200 |
---|---|---|
committer | Markus Teich <markus.teich@stusta.mhn.de> | 2016-06-21 23:06:15 +0200 |
commit | 8d717c4b3d126104929aeb5e3a2176dd534e25ea (patch) | |
tree | 65fb80bd331e8ce5991aa723502e7a023cc0b8f6 /test_crypto.c | |
parent | 584423199339cff2e0ad348df60148672a562fe4 (diff) |
use proof structs. fix bug in mpi_serialize
Diffstat (limited to 'test_crypto.c')
-rw-r--r-- | test_crypto.c | 104 |
1 files changed, 27 insertions, 77 deletions
diff --git a/test_crypto.c b/test_crypto.c index 93f1cb4..f8abe68 100644 --- a/test_crypto.c +++ b/test_crypto.c @@ -88,6 +88,10 @@ test_serialization () check (!ec_point_cmp (oldp, newp), "serialization changed point"); check (!gcry_mpi_cmp (oldi, newi), "serialization changed mpi"); + mpi_serialize (&seri, GCRYMPI_CONST_ONE); + mpi_parse (newi, &seri); + check (!gcry_mpi_cmp (GCRYMPI_CONST_ONE, newi), "serializing mpi 1 fail"); + gcry_mpi_point_release (oldp); gcry_mpi_point_release (newp); gcry_mpi_release (oldi); @@ -98,33 +102,18 @@ test_serialization () int test_smc_zkp_dl () { - gcry_mpi_t r = gcry_mpi_new (0); + struct proof_dl proof; 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); - ec_keypair_create (g, r); - - 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); - } - - ec_keypair_create_base (v, x, g); + /* v = xg */ + ec_keypair_create (v, x); - smc_zkp_dl (v, g, x, a, r); - check (!smc_zkp_dl_check (v, g, a, r), "zkp dl wrong"); - - check (gcry_mpi_ec_curve_point (a, ec_ctx), "not on curve"); - check (gcry_mpi_ec_curve_point (g, ec_ctx), "not on curve"); + smc_zkp_dl (v, x, &proof); check (gcry_mpi_ec_curve_point (v, ec_ctx), "not on curve"); + check (!smc_zkp_dl_check (v, &proof), "zkp dl wrong"); - gcry_mpi_release (r); gcry_mpi_release (x); - gcry_mpi_point_release (a); - gcry_mpi_point_release (g); gcry_mpi_point_release (v); } @@ -132,42 +121,24 @@ test_smc_zkp_dl () int test_smc_zkp_2dle () { - 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); - - ec_keypair_create (g1, r); - ec_keypair_create (g2, r); - - 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); - } - - ec_keypair_create_base (v, x, g1); - gcry_mpi_ec_mul (w, x, g2, ec_ctx); + struct proof_2dle proof; + gcry_mpi_t x = gcry_mpi_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); - smc_zkp_2dle (v, w, g1, g2, x, a, b, r); - check (!smc_zkp_2dle_check (v, w, g1, g2, a, b, r), "zkp 2dle wrong"); + ec_keypair_create (g1, x); + ec_keypair_create (g2, x); - check (gcry_mpi_ec_curve_point (a, ec_ctx), "not on curve"); - check (gcry_mpi_ec_curve_point (b, ec_ctx), "not on curve"); + smc_zkp_2dle (v, w, g1, g2, x, &proof); 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"); + check (!smc_zkp_2dle_check (v, w, g1, g2, &proof), "zkp 2dle wrong"); - gcry_mpi_release (r); gcry_mpi_release (x); - gcry_mpi_point_release (a); - gcry_mpi_point_release (b); gcry_mpi_point_release (g1); gcry_mpi_point_release (g2); gcry_mpi_point_release (v); @@ -178,51 +149,30 @@ test_smc_zkp_2dle () int test_smc_zkp_0og () { - 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); + struct proof_0og proof; 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); - ec_keypair_create (y, r1); + /* get random public key point. We don't need the secret key to check the + * proof here */ + ec_keypair_create (y, NULL); - smc_zkp_0og (alpha, (tests_run % 2 ? ec_zero : ec_gen), y, beta, a1, a2, b1, - b2, d1, d2, r1, r2); - check (!smc_zkp_0og_check (alpha, y, beta, a1, a2, b1, b2, d1, d2, r1, - r2), "zkp 0og is wrong"); - - check (gcry_mpi_ec_curve_point (y, ec_ctx), "not on curve"); + smc_zkp_0og (tests_run % 2, y, NULL, alpha, beta, &proof); 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 (d1); - gcry_mpi_release (d2); - gcry_mpi_release (r1); - gcry_mpi_release (r2); + check (!smc_zkp_0og_check (y, alpha, beta, &proof), "zkp 0og is wrong"); + 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 = 8; + int repeat = 16; BRANDT_init (); |