aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarkus Teich <markus.teich@stusta.mhn.de>2016-06-17 15:34:46 +0200
committerMarkus Teich <markus.teich@stusta.mhn.de>2016-06-17 15:35:46 +0200
commitbe1ac2e45203ce88e12aaba076fb68d86ff79e03 (patch)
treeea1773c987cc15709cce7926324908d694ba292f
parentb043bfc8d24a8e432472a3e16711f22bfcb6cd09 (diff)
update internals.h, add first algorithm functions
-rw-r--r--internals.h36
-rw-r--r--smc.c59
2 files changed, 77 insertions, 18 deletions
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 <pari/pari.h>
+#include <gcrypt.h>
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 */
-
- GEN x; /** Own private additive key share */
- GEN y; /** Own public multiplicative key share */
- GEN 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) */
-
- GEN alpha; /** Own alpha, type: Vector(k) */
- GEN beta; /** Own beta, type: Vector(k) */
+ 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 */
+
+ 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 */
+
+ gcry_mpi_point_t *b; /** Own bid, size: 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 <gcrypt.h>
#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
*