aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarkus Teich <markus.teich@stusta.mhn.de>2016-12-02 12:53:54 +0100
committerMarkus Teich <markus.teich@stusta.mhn.de>2016-12-02 12:53:54 +0100
commite66cbbe44f3708e6d6a30b216035bcccfc8e7207 (patch)
tree5329f963c2eee3af18976862cdfdf9e344dfd109
parent64689a9083fd11a1e482cc86c0417183cdc76ece (diff)
move ecdlogctx passing to _join()/_new() functions
-rw-r--r--brandt.c62
-rw-r--r--brandt.h44
-rw-r--r--crypto.c13
-rw-r--r--crypto.h2
-rw-r--r--fp_pub.c2
-rw-r--r--internals.h12
-rw-r--r--mp_pub.c2
-rw-r--r--test_brandt.c14
8 files changed, 90 insertions, 61 deletions
diff --git a/brandt.c b/brandt.c
index f5bb4fa..bd6e01e 100644
--- a/brandt.c
+++ b/brandt.c
@@ -28,7 +28,7 @@
void
-BRANDT_init (struct GNUNET_CRYPTO_EccDlogContext *dlogctx)
+BRANDT_init ()
{
gcry_error_t err = 0;
@@ -56,7 +56,7 @@ BRANDT_init (struct GNUNET_CRYPTO_EccDlogContext *dlogctx)
gcry_strerror (err));
gcry_control (GCRYCTL_INITIALIZATION_FINISHED, 0);
- brandt_crypto_init (dlogctx);
+ brandt_crypto_init ();
}
@@ -184,17 +184,18 @@ seller_start (void *arg)
struct BRANDT_Auction *
-BRANDT_new (BRANDT_CbResult result,
- BRANDT_CbDeliver broadcast,
- BRANDT_CbStart start,
- void *auction_closure,
- void **auction_desc,
- size_t *auction_desc_len,
- struct GNUNET_TIME_Absolute time_start,
- struct GNUNET_TIME_Relative time_round,
- uint16_t num_prices,
- uint16_t m,
- int outcome_public)
+BRANDT_new (BRANDT_CbResult result,
+ BRANDT_CbDeliver broadcast,
+ BRANDT_CbStart start,
+ void *auction_closure,
+ void **auction_desc,
+ size_t *auction_desc_len,
+ struct GNUNET_TIME_Absolute time_start,
+ struct GNUNET_TIME_Relative time_round,
+ uint16_t num_prices,
+ uint16_t m,
+ int outcome_public,
+ struct GNUNET_CRYPTO_EccDlogContext *dlogctx)
{
struct BRANDT_Auction *ret;
struct BRANDT_DescrP *desc;
@@ -208,6 +209,14 @@ BRANDT_new (BRANDT_CbResult result,
return NULL;
}
+ if (1 == outcome_public && NULL == dlogctx)
+ {
+ GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
+ "libbrandt",
+ "need dlogctx for public outcome auctions\n");
+ return NULL;
+ }
+
desc = GNUNET_new (struct BRANDT_DescrP);
desc->time_start = GNUNET_TIME_absolute_hton (time_start);
desc->time_round = GNUNET_TIME_relative_hton (time_round);
@@ -223,6 +232,7 @@ BRANDT_new (BRANDT_CbResult result,
ret->outcome_public = outcome_public;
ret->cur_round = msg_init;
ret->round_progress = gcry_mpi_new (256);
+ ret->dlogctx = dlogctx;
/* we are the seller */
ret->seller_mode = 1;
@@ -288,13 +298,14 @@ BRANDT_parse_desc (const void *auction_desc,
struct BRANDT_Auction *
-BRANDT_join (BRANDT_CbResult result,
- BRANDT_CbDeliver broadcast,
- BRANDT_CbDeliver unicast,
- void *auction_closure,
- const void *auction_desc,
- size_t auction_desc_len,
- uint16_t bid)
+BRANDT_join (BRANDT_CbResult result,
+ BRANDT_CbDeliver broadcast,
+ BRANDT_CbDeliver unicast,
+ void *auction_closure,
+ const void *auction_desc,
+ size_t auction_desc_len,
+ uint16_t bid,
+ struct GNUNET_CRYPTO_EccDlogContext *dlogctx)
{
struct BRANDT_Auction *ret = GNUNET_new (struct BRANDT_Auction);
@@ -312,9 +323,20 @@ BRANDT_join (BRANDT_CbResult result,
"failed to parse auction description blob\n");
return NULL;
}
+
+ if (1 == ret->outcome_public && NULL == dlogctx)
+ {
+ GNUNET_free (ret);
+ GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
+ "libbrandt",
+ "need dlogctx for public outcome auctions\n");
+ return NULL;
+ }
+
ret->cur_round = msg_init;
ret->round_progress = gcry_mpi_new (256);
ret->b = bid;
+ ret->dlogctx = dlogctx;
/* we are the seller */
ret->seller_mode = 0;
diff --git a/brandt.h b/brandt.h
index ceee3d1..b967656 100644
--- a/brandt.h
+++ b/brandt.h
@@ -108,7 +108,7 @@ typedef void
void
-BRANDT_init (struct GNUNET_CRYPTO_EccDlogContext *dlogctx);
+BRANDT_init ();
/**
@@ -149,18 +149,21 @@ BRANDT_parse_desc (const void *auction_desc,
* @param[in] auction_desc_len The length in byte of the @a auction_desc
* structure.
* @param[in] bid How much to bid on this auction.
+ * @param[in] dlogctx The discrete log context obtained from
+ * GNUNET_CRYPTO_ecc_dlog_prepare(). Only needed for M+1st price auctions.
* @return A pointer, which should only be remembered and passed to
* libbrandt functions when the client needs to refer to this auction. This is a
* black-box pointer, do NOT dereference/change it or the data it points to!
*/
struct BRANDT_Auction *
-BRANDT_join (BRANDT_CbResult result,
- BRANDT_CbDeliver broadcast,
- BRANDT_CbDeliver unicast,
- void *auction_closure,
- const void *auction_desc,
- size_t auction_desc_len,
- uint16_t bid);
+BRANDT_join (BRANDT_CbResult result,
+ BRANDT_CbDeliver broadcast,
+ BRANDT_CbDeliver unicast,
+ void *auction_closure,
+ const void *auction_desc,
+ size_t auction_desc_len,
+ uint16_t bid,
+ struct GNUNET_CRYPTO_EccDlogContext *dlogctx);
/* \todo: have cancellation (BRANDT_join_cancel()) */
@@ -190,23 +193,26 @@ BRANDT_join (BRANDT_CbResult result,
* @param[in] outcome_public If 1, the auction winner and price will be public
* to all participants, if 0, this information will only be revealed to the
* winner and the seller.
+ * @param[in] dlogctx The discrete log context obtained from
+ * GNUNET_CRYPTO_ecc_dlog_prepare(). Only needed for M+1st price auctions.
* @return If invalid parameters are passed, NULL is returned. Else the return
* value is a pointer, which should only be remembered and passed to
* libbrandt functions when the client needs to refer to this auction. This is a
* black-box pointer, do NOT dereference/change it or the data it points to!
*/
struct BRANDT_Auction *
-BRANDT_new (BRANDT_CbResult result,
- BRANDT_CbDeliver broadcast,
- BRANDT_CbStart start,
- void *auction_closure,
- void **auction_desc,
- size_t *auction_desc_len,
- struct GNUNET_TIME_Absolute time_start,
- struct GNUNET_TIME_Relative time_round,
- uint16_t num_prices,
- uint16_t m,
- int outcome_public);
+BRANDT_new (BRANDT_CbResult result,
+ BRANDT_CbDeliver broadcast,
+ BRANDT_CbStart start,
+ void *auction_closure,
+ void **auction_desc,
+ size_t *auction_desc_len,
+ struct GNUNET_TIME_Absolute time_start,
+ struct GNUNET_TIME_Relative time_round,
+ uint16_t num_prices,
+ uint16_t m,
+ int outcome_public,
+ struct GNUNET_CRYPTO_EccDlogContext *dlogctx);
/**
diff --git a/crypto.c b/crypto.c
index e067f04..e513e6f 100644
--- a/crypto.c
+++ b/crypto.c
@@ -77,11 +77,10 @@ struct zkp_challenge_0og {
};
-gcry_ctx_t ec_ctx = NULL;
-gcry_mpi_point_t ec_gen = NULL;
-gcry_mpi_point_t ec_zero = NULL;
-gcry_mpi_t ec_n = NULL;
-struct GNUNET_CRYPTO_EccDlogContext *ec_dlogctx = NULL;
+gcry_ctx_t ec_ctx = NULL;
+gcry_mpi_point_t ec_gen = NULL;
+gcry_mpi_point_t ec_zero = NULL;
+gcry_mpi_t ec_n = NULL;
/**
@@ -91,12 +90,10 @@ struct GNUNET_CRYPTO_EccDlogContext *ec_dlogctx = NULL;
* @param[in] dlogctx Pointer to the prepared dlog context.
*/
void
-brandt_crypto_init (struct GNUNET_CRYPTO_EccDlogContext *dlogctx)
+brandt_crypto_init ()
{
gcry_error_t rc;
- ec_dlogctx = dlogctx;
-
rc = gcry_mpi_ec_new (&ec_ctx, NULL, CURVE);
ASSERT_GCRY ("gcry_mpi_ec_new", rc);
diff --git a/crypto.h b/crypto.h
index 8291bc2..4ba850e 100644
--- a/crypto.h
+++ b/crypto.h
@@ -30,7 +30,7 @@
#include "internals.h"
-void brandt_crypto_init (struct GNUNET_CRYPTO_EccDlogContext *dlogctx);
+void brandt_crypto_init ();
/* --- EC --- */
diff --git a/fp_pub.c b/fp_pub.c
index ff6cfaf..c7308f6 100644
--- a/fp_pub.c
+++ b/fp_pub.c
@@ -412,7 +412,7 @@ fp_pub_determine_outcome (struct BRANDT_Auction *ad,
}
}
- dlogi = GNUNET_CRYPTO_ecc_dlog (ec_dlogctx, sum_gamma);
+ dlogi = GNUNET_CRYPTO_ecc_dlog (ad->dlogctx, sum_gamma);
brandt_assert (dlogi > 0);
/* all bidders participated with a multiplicative share */
diff --git a/internals.h b/internals.h
index 8a82e2e..8e97e8a 100644
--- a/internals.h
+++ b/internals.h
@@ -146,12 +146,14 @@ struct BRANDT_Auction {
gcry_mpi_point_t *tmpa1; /** used for temporary storage, size: k */
gcry_mpi_point_t *tmpb1; /** used for temporary storage, size: k */
+
+ /** only needed in M+1st price auctions to determine winners */
+ struct GNUNET_CRYPTO_EccDlogContext *dlogctx;
};
-extern gcry_ctx_t ec_ctx;
-extern gcry_mpi_point_t ec_gen;
-extern gcry_mpi_point_t ec_zero;
-extern gcry_mpi_t ec_n;
-extern struct GNUNET_CRYPTO_EccDlogContext *ec_dlogctx;
+extern gcry_ctx_t ec_ctx;
+extern gcry_mpi_point_t ec_gen;
+extern gcry_mpi_point_t ec_zero;
+extern gcry_mpi_t ec_n;
#endif /* ifndef _BRANDT_INTERNALS_H */
diff --git a/mp_pub.c b/mp_pub.c
index 712c148..661a4de 100644
--- a/mp_pub.c
+++ b/mp_pub.c
@@ -486,7 +486,7 @@ mp_pub_determine_outcome (struct BRANDT_Auction *ad,
smc_sum (sum_phi, &ad->phi3[0][1][price], ad->n, 2 * ad->k);
gcry_mpi_ec_sub (sum_gamma, sum_gamma, sum_phi, ec_ctx);
- dlogi = GNUNET_CRYPTO_ecc_dlog (ec_dlogctx, sum_gamma);
+ dlogi = GNUNET_CRYPTO_ecc_dlog (ad->dlogctx, sum_gamma);
brandt_assert (dlogi > 0);
/* all bidders participated with a multiplicative share */
diff --git a/test_brandt.c b/test_brandt.c
index 47f3711..afc178a 100644
--- a/test_brandt.c
+++ b/test_brandt.c
@@ -50,7 +50,8 @@ struct testcase {
};
-static struct testcase tcase;
+static struct testcase tcase;
+static struct GNUNET_CRYPTO_EccDlogContext *edc;
static struct BRANDT_Result *
@@ -330,7 +331,8 @@ run_auction (void *arg)
GNUNET_TIME_UNIT_MINUTES,
tcase.k, /* number of prizes */
tcase.m, /* m */
- tcase.outcome_public); /* outcome public */
+ tcase.outcome_public, /* outcome public */
+ tcase.outcome_public ? edc : NULL);
if (!tcase.ad[tcase.n])
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "BRANDT_new() failed.\n");
@@ -345,7 +347,8 @@ run_auction (void *arg)
&tcase.id[i],
desc,
desc_len,
- tcase.bids[i]); /* bid */
+ tcase.bids[i], /* bid */
+ tcase.outcome_public ? edc : NULL);
if (!tcase.ad[i])
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "BRANDT_join() failed.\n");
@@ -439,14 +442,13 @@ test_auction (uint16_t n,
int
main (int argc, char *argv[])
{
- int ret = 0;
- struct GNUNET_CRYPTO_EccDlogContext *edc;
+ int ret = 0;
if (GNUNET_OK != GNUNET_log_setup ("test_brandt", "WARNING", NULL))
return 1;
edc = GNUNET_CRYPTO_ecc_dlog_prepare (1024, 16);
- BRANDT_init (edc);
+ BRANDT_init ();
ret |= 0 ||
// zero bidders