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) | |
download | libbrandt-557fbe2cc32f3ff6d8c2c0c8aa272f7b55f45618.tar.gz libbrandt-557fbe2cc32f3ff6d8c2c0c8aa272f7b55f45618.zip |
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) | |||
243 | { | 243 | { |
244 | gcry_sexp_t s_keyparam; | 244 | gcry_sexp_t s_keyparam; |
245 | gcry_sexp_t priv_sexp; | 245 | gcry_sexp_t priv_sexp; |
246 | gcry_mpi_t d; | ||
247 | gcry_error_t rc; | 246 | gcry_error_t rc; |
248 | 247 | ||
249 | rc = gcry_sexp_build (&s_keyparam, NULL, "(genkey(ecc(curve \"" CURVE "\")" | 248 | rc = gcry_sexp_build (&s_keyparam, NULL, "(genkey(ecc(curve \"" CURVE "\")" |
250 | "(flags)))"); | 249 | "(flags)))"); |
251 | brandt_assert_gpgerr (rc); | 250 | brandt_assert_gpgerr (rc); |
251 | |||
252 | rc = gcry_pk_genkey (&priv_sexp, s_keyparam); | 252 | rc = gcry_pk_genkey (&priv_sexp, s_keyparam); |
253 | brandt_assert_gpgerr (rc); | 253 | brandt_assert_gpgerr (rc); |
254 | gcry_sexp_release (s_keyparam); | 254 | gcry_sexp_release (s_keyparam); |
255 | |||
255 | rc = key_from_sexp (skey, priv_sexp, "private-key", "d"); | 256 | rc = key_from_sexp (skey, priv_sexp, "private-key", "d"); |
256 | brandt_assert_gpgerr (rc); | 257 | brandt_assert_gpgerr (rc); |
258 | |||
257 | gcry_sexp_release (priv_sexp); | 259 | gcry_sexp_release (priv_sexp); |
258 | } | 260 | } |
259 | 261 | ||
@@ -268,10 +270,10 @@ brandt_ec_pkey_compute (gcry_mpi_point_t* pkey, const gcry_mpi_t skey) | |||
268 | void | 270 | void |
269 | brandt_ec_keypair_create (gcry_mpi_point_t* pkey, gcry_mpi_t* skey) | 271 | brandt_ec_keypair_create (gcry_mpi_point_t* pkey, gcry_mpi_t* skey) |
270 | { | 272 | { |
271 | gcry_error_t rc; | 273 | gcry_ctx_t ctx; |
272 | gcry_sexp_t s_keyparam; | 274 | gcry_sexp_t s_keyparam; |
273 | gcry_sexp_t priv_sexp; | 275 | gcry_sexp_t priv_sexp; |
274 | gcry_ctx_t ctx; | 276 | gcry_error_t rc; |
275 | 277 | ||
276 | rc = gcry_sexp_build (&s_keyparam, NULL, "(genkey(ecc(curve \"" CURVE "\")" | 278 | rc = gcry_sexp_build (&s_keyparam, NULL, "(genkey(ecc(curve \"" CURVE "\")" |
277 | "(flags)))"); | 279 | "(flags)))"); |
@@ -294,6 +296,46 @@ brandt_ec_keypair_create (gcry_mpi_point_t* pkey, gcry_mpi_t* skey) | |||
294 | } | 296 | } |
295 | 297 | ||
296 | 298 | ||
299 | void | ||
300 | brandt_ec_keypair_create_base (gcry_mpi_point_t* pkey, gcry_mpi_t* skey, const gcry_mpi_point_t base) | ||
301 | { | ||
302 | brandt_ec_skey_create(skey); | ||
303 | brandt_assert(*skey); | ||
304 | *pkey = gcry_mpi_point_new(0); | ||
305 | brandt_assert(*pkey); | ||
306 | gcry_mpi_ec_mul(*pkey, *skey, base, ec_ctx); | ||
307 | } | ||
308 | |||
309 | |||
310 | int | ||
311 | brandt_ec_point_cmp (const gcry_mpi_point_t a, const gcry_mpi_point_t b) | ||
312 | { | ||
313 | int ret = 1; | ||
314 | gcry_mpi_t ax = gcry_mpi_new(0); | ||
315 | gcry_mpi_t bx = gcry_mpi_new(0); | ||
316 | gcry_mpi_t ay = gcry_mpi_new(0); | ||
317 | gcry_mpi_t by = gcry_mpi_new(0); | ||
318 | |||
319 | brandt_assert (a && b); | ||
320 | if (!ax || !bx || !ay || !by) | ||
321 | { | ||
322 | weprintf("could not init point in point_cmp"); | ||
323 | return 1; | ||
324 | } | ||
325 | |||
326 | if (!gcry_mpi_ec_get_affine(ax, ay, a, ec_ctx) && !gcry_mpi_ec_get_affine(bx, by, b, ec_ctx)) | ||
327 | { | ||
328 | ret = gcry_mpi_cmp(ax, bx) || gcry_mpi_cmp(ay, by); | ||
329 | } | ||
330 | |||
331 | gcry_mpi_release(ax); | ||
332 | gcry_mpi_release(bx); | ||
333 | gcry_mpi_release(ay); | ||
334 | gcry_mpi_release(by); | ||
335 | return ret; | ||
336 | } | ||
337 | |||
338 | |||
297 | /** | 339 | /** |
298 | * Convert the given private key from the network format to the | 340 | * Convert the given private key from the network format to the |
299 | * S-expression that can be used by libgcrypt. | 341 | * S-expression that can be used by libgcrypt. |