aboutsummaryrefslogtreecommitdiff
path: root/smc.c
diff options
context:
space:
mode:
Diffstat (limited to 'smc.c')
-rw-r--r--smc.c59
1 files changed, 59 insertions, 0 deletions
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
*