diff --git a/internals.h b/internals.h index 32080ec..f705c6d 100644 --- a/internals.h +++ b/internals.h @@ -22,25 +22,25 @@ #ifndef _BRANDT_INTERNALS_H #define _BRANDT_INTERNALS_H -#include +#include struct AuctionData { - GEN p; /** The "safe prime" p */ - GEN q; /** The prime @f$q = (p - 1) / 2@f$. */ - GEN g; /** The generator of @f$\mathbb{G}_q@f$ */ - uint16_t n; /** The amount of bidders/agents */ - uint16_t k; /** The amount of possible prices */ + uint16_t n; /** The amount of bidders/agents */ + uint16_t k; /** The amount of possible prices */ + uint16_t i; /** Own agents index, only used when bidding */ - GEN x; /** Own private additive key share */ - GEN y; /** Own public multiplicative key share */ - GEN Y; /** Shared public key */ + gcry_mpi_t x; /** Own private additive key share */ + gcry_mpi_point_t *y; /** public multiplicative key shares, size: n */ + gcry_mpi_point_t Y; /** Shared public key */ - GEN m; /** Additive share of random exponents, type: Matrix(n,k) */ - GEN r; /** Key share exponent, type: Vector(k) */ - GEN b; /** Own bid, type: Vector(k) */ + gcry_mpi_point_t *b; /** Own bid, size: k */ - GEN alpha; /** Own alpha, type: Vector(k) */ - GEN beta; /** Own beta, type: Vector(k) */ + gcry_mpi_point_t **alpha; /** alphas, size: n*k */ + gcry_mpi_point_t **beta; /** betas, size: n*k */ + + gcry_mpi_point_t ***gamma; /** gamma, size: n*n*k */ + gcry_mpi_point_t ***delta; /** delta, size: n*n*k */ + gcry_mpi_point_t ***phi; /** phi, size: n*n*k */ }; -#endif +#endif /* ifndef _BRANDT_INTERNALS_H */ 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 *