move ecdlogctx passing to _join()/_new() functions
This commit is contained in:
parent
64689a9083
commit
e66cbbe44f
30
brandt.c
30
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 ();
|
||||
}
|
||||
|
||||
|
||||
@ -194,7 +194,8 @@ BRANDT_new (BRANDT_CbResult result,
|
||||
struct GNUNET_TIME_Relative time_round,
|
||||
uint16_t num_prices,
|
||||
uint16_t m,
|
||||
int outcome_public)
|
||||
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;
|
||||
@ -294,7 +304,8 @@ BRANDT_join (BRANDT_CbResult result,
|
||||
void *auction_closure,
|
||||
const void *auction_desc,
|
||||
size_t auction_desc_len,
|
||||
uint16_t bid)
|
||||
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;
|
||||
|
12
brandt.h
12
brandt.h
@ -108,7 +108,7 @@ typedef void
|
||||
|
||||
|
||||
void
|
||||
BRANDT_init (struct GNUNET_CRYPTO_EccDlogContext *dlogctx);
|
||||
BRANDT_init ();
|
||||
|
||||
|
||||
/**
|
||||
@ -149,6 +149,8 @@ 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!
|
||||
@ -160,7 +162,8 @@ BRANDT_join (BRANDT_CbResult result,
|
||||
void *auction_closure,
|
||||
const void *auction_desc,
|
||||
size_t auction_desc_len,
|
||||
uint16_t bid);
|
||||
uint16_t bid,
|
||||
struct GNUNET_CRYPTO_EccDlogContext *dlogctx);
|
||||
|
||||
|
||||
/* \todo: have cancellation (BRANDT_join_cancel()) */
|
||||
@ -190,6 +193,8 @@ 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
|
||||
@ -206,7 +211,8 @@ BRANDT_new (BRANDT_CbResult result,
|
||||
struct GNUNET_TIME_Relative time_round,
|
||||
uint16_t num_prices,
|
||||
uint16_t m,
|
||||
int outcome_public);
|
||||
int outcome_public,
|
||||
struct GNUNET_CRYPTO_EccDlogContext *dlogctx);
|
||||
|
||||
|
||||
/**
|
||||
|
5
crypto.c
5
crypto.c
@ -81,7 +81,6 @@ 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;
|
||||
|
||||
|
||||
/**
|
||||
@ -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);
|
||||
|
||||
|
2
crypto.h
2
crypto.h
@ -30,7 +30,7 @@
|
||||
|
||||
#include "internals.h"
|
||||
|
||||
void brandt_crypto_init (struct GNUNET_CRYPTO_EccDlogContext *dlogctx);
|
||||
void brandt_crypto_init ();
|
||||
|
||||
|
||||
/* --- EC --- */
|
||||
|
2
fp_pub.c
2
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 */
|
||||
|
@ -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;
|
||||
|
||||
#endif /* ifndef _BRANDT_INTERNALS_H */
|
||||
|
2
mp_pub.c
2
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 */
|
||||
|
@ -51,6 +51,7 @@ struct testcase {
|
||||
|
||||
|
||||
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");
|
||||
@ -440,13 +443,12 @@ int
|
||||
main (int argc, char *argv[])
|
||||
{
|
||||
int ret = 0;
|
||||
struct GNUNET_CRYPTO_EccDlogContext *edc;
|
||||
|
||||
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
|
||||
|
Loading…
Reference in New Issue
Block a user