diff options
Diffstat (limited to 'crypto.c')
-rw-r--r-- | crypto.c | 35 |
1 files changed, 33 insertions, 2 deletions
@@ -594,7 +594,7 @@ smc_sum (gcry_mpi_point_t out, brandt_assert (NULL != out); /**\todo: how to copy a point more efficiently? */ gcry_mpi_ec_add (out, ec_zero, ec_zero, ec_ctx); - for (uint16_t i = 0; i < len; i += step) + for (uint16_t i = 0; i < len * step; i += step) gcry_mpi_ec_add (out, out, in[i], ec_ctx); } @@ -616,7 +616,7 @@ smc_gen_keyshare (struct AuctionData *ad, size_t *buflen) brandt_assert (ad && buflen); *buflen = (sizeof (struct ec_mpi) + sizeof (*proof1)); if (NULL == (ret = calloc (1, *buflen)) || - NULL == (ad->y = calloc (ad->n, sizeof (*ad->y)))) + NULL == (ad->y = smc_init1 (ad->n))) { weprintf ("unable to alloc memory for key shares"); return NULL; @@ -1103,6 +1103,37 @@ quit: } +int32_t +smc_determine_outcome (struct AuctionData *ad) +{ + int32_t ret = -1; + gcry_mpi_point_t sum_gamma = gcry_mpi_point_new (0); + gcry_mpi_point_t sum_phi = gcry_mpi_point_new (0); + + brandt_assert (ad); + + for (uint16_t j = 0; j < ad->k; j++) + { + smc_sum (sum_gamma, &ad->gamma[0][ad->i][j], ad->n, ad->n * ad->k); + smc_sum (sum_phi, &ad->phi[0][ad->i][j], ad->n, ad->n * ad->k); + gcry_mpi_ec_sub (sum_gamma, sum_gamma, sum_phi, ec_ctx); + if (!ec_point_cmp (sum_gamma, ec_zero)) + { + if (-1 != ret) + { + weprintf ("multiple winning prices detected"); + return -1; + } + ret = j; + } + } + + gcry_mpi_point_release (sum_gamma); + gcry_mpi_point_release (sum_phi); + return ret; +} + + /** * smc_zkp_dl creates a proof of knowledge of @a x with \f$v = xg\f$ where * \f$g\f$ is the base point on Ed25519. |