diff options
author | Markus Teich <markus.teich@stusta.mhn.de> | 2016-06-13 21:01:14 +0200 |
---|---|---|
committer | Markus Teich <markus.teich@stusta.mhn.de> | 2016-06-13 21:01:14 +0200 |
commit | 557fbe2cc32f3ff6d8c2c0c8aa272f7b55f45618 (patch) | |
tree | 1804896d2e6d2ffb14936a6570b96c65e230143f /crypto.c | |
parent | 745dff3ac02a97d5686270fd142a31ad6e5badb2 (diff) |
add first ZKP including test case
Diffstat (limited to 'crypto.c')
-rw-r--r-- | crypto.c | 48 |
1 files changed, 45 insertions, 3 deletions
@@ -243,17 +243,19 @@ brandt_ec_skey_create (gcry_mpi_t* skey) { gcry_sexp_t s_keyparam; gcry_sexp_t priv_sexp; - gcry_mpi_t d; gcry_error_t rc; rc = gcry_sexp_build (&s_keyparam, NULL, "(genkey(ecc(curve \"" CURVE "\")" "(flags)))"); brandt_assert_gpgerr (rc); + rc = gcry_pk_genkey (&priv_sexp, s_keyparam); brandt_assert_gpgerr (rc); gcry_sexp_release (s_keyparam); + rc = key_from_sexp (skey, priv_sexp, "private-key", "d"); brandt_assert_gpgerr (rc); + gcry_sexp_release (priv_sexp); } @@ -268,10 +270,10 @@ brandt_ec_pkey_compute (gcry_mpi_point_t* pkey, const gcry_mpi_t skey) void brandt_ec_keypair_create (gcry_mpi_point_t* pkey, gcry_mpi_t* skey) { - gcry_error_t rc; + gcry_ctx_t ctx; gcry_sexp_t s_keyparam; gcry_sexp_t priv_sexp; - gcry_ctx_t ctx; + gcry_error_t rc; rc = gcry_sexp_build (&s_keyparam, NULL, "(genkey(ecc(curve \"" CURVE "\")" "(flags)))"); @@ -294,6 +296,46 @@ brandt_ec_keypair_create (gcry_mpi_point_t* pkey, gcry_mpi_t* skey) } +void +brandt_ec_keypair_create_base (gcry_mpi_point_t* pkey, gcry_mpi_t* skey, const gcry_mpi_point_t base) +{ + brandt_ec_skey_create(skey); + brandt_assert(*skey); + *pkey = gcry_mpi_point_new(0); + brandt_assert(*pkey); + gcry_mpi_ec_mul(*pkey, *skey, base, ec_ctx); +} + + +int +brandt_ec_point_cmp (const gcry_mpi_point_t a, const gcry_mpi_point_t b) +{ + int ret = 1; + gcry_mpi_t ax = gcry_mpi_new(0); + gcry_mpi_t bx = gcry_mpi_new(0); + gcry_mpi_t ay = gcry_mpi_new(0); + gcry_mpi_t by = gcry_mpi_new(0); + + brandt_assert (a && b); + if (!ax || !bx || !ay || !by) + { + weprintf("could not init point in point_cmp"); + return 1; + } + + if (!gcry_mpi_ec_get_affine(ax, ay, a, ec_ctx) && !gcry_mpi_ec_get_affine(bx, by, b, ec_ctx)) + { + ret = gcry_mpi_cmp(ax, bx) || gcry_mpi_cmp(ay, by); + } + + gcry_mpi_release(ax); + gcry_mpi_release(bx); + gcry_mpi_release(ay); + gcry_mpi_release(by); + return ret; +} + + /** * Convert the given private key from the network format to the * S-expression that can be used by libgcrypt. |