diff options
Diffstat (limited to 'test_crypto.c')
-rw-r--r-- | test_crypto.c | 67 |
1 files changed, 46 insertions, 21 deletions
diff --git a/test_crypto.c b/test_crypto.c index 67894eb..1bfc321 100644 --- a/test_crypto.c +++ b/test_crypto.c @@ -1,16 +1,16 @@ #include "brandt.h" #include "crypto.h" +#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_t x1 = gcry_mpi_new(0); - gcry_mpi_t x2 = gcry_mpi_new(0); - gcry_mpi_t y1 = gcry_mpi_new(0); - gcry_mpi_t y2 = gcry_mpi_new(0); gcry_mpi_point_t pkey1; gcry_mpi_point_t pkey2 = gcry_mpi_point_new(0); @@ -18,30 +18,58 @@ test_brandt_ec_keypair_create () check(skey, "no sec key created"); check(pkey1, "no pub key created"); check(pkey2, "could not init pkey2"); - check(x1, "could not init x1"); - check(x2, "could not init x2"); - check(y1, "could not init y1"); - check(y2, "could not init y2"); gcry_mpi_ec_mul(pkey2, skey, ec_gen, ec_ctx); - check(!gcry_mpi_ec_get_affine(x1, y1, pkey1, ec_ctx), "could not get affine coords for pkey1"); - check(!gcry_mpi_ec_get_affine(x2, y2, pkey2, ec_ctx), "could not get affine coords for pkey1"); - check(!gcry_mpi_cmp(x1, x2), "x component does not match"); - check(!gcry_mpi_cmp(y1, y2), "y component does not match"); + check(!brandt_ec_point_cmp(pkey1, pkey2), "pkeys do not match"); gcry_mpi_release(skey); - gcry_mpi_release(x1); - gcry_mpi_release(x2); - gcry_mpi_release(y1); - gcry_mpi_release(y2); gcry_mpi_point_release(pkey1); gcry_mpi_point_release(pkey2); } 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_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"); + + if (first) + { + 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"); + + 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"); + + 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 main (int argc, char *argv[]) { - int repeat = 100; + int repeat = 50; int i; BRANDT_init(); @@ -49,11 +77,8 @@ main (int argc, char *argv[]) for (i = 0; i < repeat; i++) { run(test_brandt_ec_keypair_create); + run(test_smc_zkp_dl); } - if (!ret) - { - fputs("All tests passed", stderr); - } return ret; } |