From be1ac2e45203ce88e12aaba076fb68d86ff79e03 Mon Sep 17 00:00:00 2001 From: Markus Teich Date: Fri, 17 Jun 2016 15:34:46 +0200 Subject: update internals.h, add first algorithm functions --- smc.c | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) (limited to 'smc.c') diff --git a/smc.c b/smc.c index 9e4fd40..debc5b4 100644 --- a/smc.c +++ b/smc.c @@ -22,6 +22,7 @@ #include #include "crypto.h" +#include "internals.h" #include "smc.h" #include "util.h" @@ -30,6 +31,64 @@ extern gcry_mpi_point_t ec_gen; extern gcry_mpi_point_t ec_zero; extern gcry_mpi_t ec_n; + +/** + * smc_sums_partial calculates sums up until the current index and stores them + * in @a out. @$f\forall i \leq len: out_i=sum_{h=1}^iin_h@$f + * + * @param[out] out Where to store the resulting sums. Points may be given + * uninitialized, but the appropriate amount of memory has to be allocated + * beforehand. + * @param[in] in Input points. + * @param[in] len The length of both @a out and @a in. + */ +static void +smc_sums_partial (gcry_mpi_point_t out[], gcry_mpi_point_t in[], uint16_t len) +{ + uint16_t i; + + for (i = 0; i < len; i++) + { + out[i] = gcry_mpi_point_new (0); + gcry_mpi_ec_add (out[i], in[i], (i ? out[i - 1] : ec_zero), ec_ctx); + brandt_assert (NULL != out[i]); + } +} + + +/** + * smc_sum calculates the sum of all input points. @$fout=sum_{i=1}^{len}in_i@$f + * + * @param[out] out Where to store the result + * @param[in] in Input points. + * @param[in] len The length of @a in. + */ +static void +smc_sum (gcry_mpi_point_t out, gcry_mpi_point_t in[], uint16_t len) +{ + uint16_t i; + + brandt_assert (NULL != out); + /**TODO: how to copy a point more efficiently? */ + gcry_mpi_ec_add (out, ec_zero, ec_zero, ec_ctx); + for (i = 0; i < len; i++) + gcry_mpi_ec_add (out, out, in[i], ec_ctx); +} + + +/** + * smc_compute_pkey calculates the shared public key + * + * @param[in,out] ad The struct AuctionData used + */ +void +smc_compute_pkey (struct AuctionData *ad) +{ + ad->Y = gcry_mpi_point_new (0); + smc_sum (ad->Y, ad->y, ad->n); +} + + /** * smc_zkp_dl * -- cgit v1.2.3