move ecdlogctx passing to _join()/_new() functions
This commit is contained in:
parent
64689a9083
commit
e66cbbe44f
62
brandt.c
62
brandt.c
@ -28,7 +28,7 @@
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
BRANDT_init (struct GNUNET_CRYPTO_EccDlogContext *dlogctx)
|
BRANDT_init ()
|
||||||
{
|
{
|
||||||
gcry_error_t err = 0;
|
gcry_error_t err = 0;
|
||||||
|
|
||||||
@ -56,7 +56,7 @@ BRANDT_init (struct GNUNET_CRYPTO_EccDlogContext *dlogctx)
|
|||||||
gcry_strerror (err));
|
gcry_strerror (err));
|
||||||
|
|
||||||
gcry_control (GCRYCTL_INITIALIZATION_FINISHED, 0);
|
gcry_control (GCRYCTL_INITIALIZATION_FINISHED, 0);
|
||||||
brandt_crypto_init (dlogctx);
|
brandt_crypto_init ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -184,17 +184,18 @@ seller_start (void *arg)
|
|||||||
|
|
||||||
|
|
||||||
struct BRANDT_Auction *
|
struct BRANDT_Auction *
|
||||||
BRANDT_new (BRANDT_CbResult result,
|
BRANDT_new (BRANDT_CbResult result,
|
||||||
BRANDT_CbDeliver broadcast,
|
BRANDT_CbDeliver broadcast,
|
||||||
BRANDT_CbStart start,
|
BRANDT_CbStart start,
|
||||||
void *auction_closure,
|
void *auction_closure,
|
||||||
void **auction_desc,
|
void **auction_desc,
|
||||||
size_t *auction_desc_len,
|
size_t *auction_desc_len,
|
||||||
struct GNUNET_TIME_Absolute time_start,
|
struct GNUNET_TIME_Absolute time_start,
|
||||||
struct GNUNET_TIME_Relative time_round,
|
struct GNUNET_TIME_Relative time_round,
|
||||||
uint16_t num_prices,
|
uint16_t num_prices,
|
||||||
uint16_t m,
|
uint16_t m,
|
||||||
int outcome_public)
|
int outcome_public,
|
||||||
|
struct GNUNET_CRYPTO_EccDlogContext *dlogctx)
|
||||||
{
|
{
|
||||||
struct BRANDT_Auction *ret;
|
struct BRANDT_Auction *ret;
|
||||||
struct BRANDT_DescrP *desc;
|
struct BRANDT_DescrP *desc;
|
||||||
@ -208,6 +209,14 @@ BRANDT_new (BRANDT_CbResult result,
|
|||||||
return NULL;
|
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 = GNUNET_new (struct BRANDT_DescrP);
|
||||||
desc->time_start = GNUNET_TIME_absolute_hton (time_start);
|
desc->time_start = GNUNET_TIME_absolute_hton (time_start);
|
||||||
desc->time_round = GNUNET_TIME_relative_hton (time_round);
|
desc->time_round = GNUNET_TIME_relative_hton (time_round);
|
||||||
@ -223,6 +232,7 @@ BRANDT_new (BRANDT_CbResult result,
|
|||||||
ret->outcome_public = outcome_public;
|
ret->outcome_public = outcome_public;
|
||||||
ret->cur_round = msg_init;
|
ret->cur_round = msg_init;
|
||||||
ret->round_progress = gcry_mpi_new (256);
|
ret->round_progress = gcry_mpi_new (256);
|
||||||
|
ret->dlogctx = dlogctx;
|
||||||
|
|
||||||
/* we are the seller */
|
/* we are the seller */
|
||||||
ret->seller_mode = 1;
|
ret->seller_mode = 1;
|
||||||
@ -288,13 +298,14 @@ BRANDT_parse_desc (const void *auction_desc,
|
|||||||
|
|
||||||
|
|
||||||
struct BRANDT_Auction *
|
struct BRANDT_Auction *
|
||||||
BRANDT_join (BRANDT_CbResult result,
|
BRANDT_join (BRANDT_CbResult result,
|
||||||
BRANDT_CbDeliver broadcast,
|
BRANDT_CbDeliver broadcast,
|
||||||
BRANDT_CbDeliver unicast,
|
BRANDT_CbDeliver unicast,
|
||||||
void *auction_closure,
|
void *auction_closure,
|
||||||
const void *auction_desc,
|
const void *auction_desc,
|
||||||
size_t auction_desc_len,
|
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);
|
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");
|
"failed to parse auction description blob\n");
|
||||||
return NULL;
|
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->cur_round = msg_init;
|
||||||
ret->round_progress = gcry_mpi_new (256);
|
ret->round_progress = gcry_mpi_new (256);
|
||||||
ret->b = bid;
|
ret->b = bid;
|
||||||
|
ret->dlogctx = dlogctx;
|
||||||
|
|
||||||
/* we are the seller */
|
/* we are the seller */
|
||||||
ret->seller_mode = 0;
|
ret->seller_mode = 0;
|
||||||
|
44
brandt.h
44
brandt.h
@ -108,7 +108,7 @@ typedef void
|
|||||||
|
|
||||||
|
|
||||||
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
|
* @param[in] auction_desc_len The length in byte of the @a auction_desc
|
||||||
* structure.
|
* structure.
|
||||||
* @param[in] bid How much to bid on this auction.
|
* @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
|
* @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
|
* 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!
|
* black-box pointer, do NOT dereference/change it or the data it points to!
|
||||||
*/
|
*/
|
||||||
struct BRANDT_Auction *
|
struct BRANDT_Auction *
|
||||||
BRANDT_join (BRANDT_CbResult result,
|
BRANDT_join (BRANDT_CbResult result,
|
||||||
BRANDT_CbDeliver broadcast,
|
BRANDT_CbDeliver broadcast,
|
||||||
BRANDT_CbDeliver unicast,
|
BRANDT_CbDeliver unicast,
|
||||||
void *auction_closure,
|
void *auction_closure,
|
||||||
const void *auction_desc,
|
const void *auction_desc,
|
||||||
size_t auction_desc_len,
|
size_t auction_desc_len,
|
||||||
uint16_t bid);
|
uint16_t bid,
|
||||||
|
struct GNUNET_CRYPTO_EccDlogContext *dlogctx);
|
||||||
|
|
||||||
|
|
||||||
/* \todo: have cancellation (BRANDT_join_cancel()) */
|
/* \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
|
* @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
|
* to all participants, if 0, this information will only be revealed to the
|
||||||
* winner and the seller.
|
* 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
|
* @return If invalid parameters are passed, NULL is returned. Else the return
|
||||||
* value is a pointer, which should only be remembered and passed to
|
* 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
|
* 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!
|
* black-box pointer, do NOT dereference/change it or the data it points to!
|
||||||
*/
|
*/
|
||||||
struct BRANDT_Auction *
|
struct BRANDT_Auction *
|
||||||
BRANDT_new (BRANDT_CbResult result,
|
BRANDT_new (BRANDT_CbResult result,
|
||||||
BRANDT_CbDeliver broadcast,
|
BRANDT_CbDeliver broadcast,
|
||||||
BRANDT_CbStart start,
|
BRANDT_CbStart start,
|
||||||
void *auction_closure,
|
void *auction_closure,
|
||||||
void **auction_desc,
|
void **auction_desc,
|
||||||
size_t *auction_desc_len,
|
size_t *auction_desc_len,
|
||||||
struct GNUNET_TIME_Absolute time_start,
|
struct GNUNET_TIME_Absolute time_start,
|
||||||
struct GNUNET_TIME_Relative time_round,
|
struct GNUNET_TIME_Relative time_round,
|
||||||
uint16_t num_prices,
|
uint16_t num_prices,
|
||||||
uint16_t m,
|
uint16_t m,
|
||||||
int outcome_public);
|
int outcome_public,
|
||||||
|
struct GNUNET_CRYPTO_EccDlogContext *dlogctx);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
13
crypto.c
13
crypto.c
@ -77,11 +77,10 @@ struct zkp_challenge_0og {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
gcry_ctx_t ec_ctx = NULL;
|
gcry_ctx_t ec_ctx = NULL;
|
||||||
gcry_mpi_point_t ec_gen = NULL;
|
gcry_mpi_point_t ec_gen = NULL;
|
||||||
gcry_mpi_point_t ec_zero = NULL;
|
gcry_mpi_point_t ec_zero = NULL;
|
||||||
gcry_mpi_t ec_n = 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.
|
* @param[in] dlogctx Pointer to the prepared dlog context.
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
brandt_crypto_init (struct GNUNET_CRYPTO_EccDlogContext *dlogctx)
|
brandt_crypto_init ()
|
||||||
{
|
{
|
||||||
gcry_error_t rc;
|
gcry_error_t rc;
|
||||||
|
|
||||||
ec_dlogctx = dlogctx;
|
|
||||||
|
|
||||||
rc = gcry_mpi_ec_new (&ec_ctx, NULL, CURVE);
|
rc = gcry_mpi_ec_new (&ec_ctx, NULL, CURVE);
|
||||||
ASSERT_GCRY ("gcry_mpi_ec_new", rc);
|
ASSERT_GCRY ("gcry_mpi_ec_new", rc);
|
||||||
|
|
||||||
|
2
crypto.h
2
crypto.h
@ -30,7 +30,7 @@
|
|||||||
|
|
||||||
#include "internals.h"
|
#include "internals.h"
|
||||||
|
|
||||||
void brandt_crypto_init (struct GNUNET_CRYPTO_EccDlogContext *dlogctx);
|
void brandt_crypto_init ();
|
||||||
|
|
||||||
|
|
||||||
/* --- EC --- */
|
/* --- 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);
|
brandt_assert (dlogi > 0);
|
||||||
|
|
||||||
/* all bidders participated with a multiplicative share */
|
/* all bidders participated with a multiplicative share */
|
||||||
|
12
internals.h
12
internals.h
@ -146,12 +146,14 @@ struct BRANDT_Auction {
|
|||||||
|
|
||||||
gcry_mpi_point_t *tmpa1; /** used for temporary storage, size: k */
|
gcry_mpi_point_t *tmpa1; /** used for temporary storage, size: k */
|
||||||
gcry_mpi_point_t *tmpb1; /** 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_ctx_t ec_ctx;
|
||||||
extern gcry_mpi_point_t ec_gen;
|
extern gcry_mpi_point_t ec_gen;
|
||||||
extern gcry_mpi_point_t ec_zero;
|
extern gcry_mpi_point_t ec_zero;
|
||||||
extern gcry_mpi_t ec_n;
|
extern gcry_mpi_t ec_n;
|
||||||
extern struct GNUNET_CRYPTO_EccDlogContext *ec_dlogctx;
|
|
||||||
|
|
||||||
#endif /* ifndef _BRANDT_INTERNALS_H */
|
#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);
|
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);
|
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);
|
brandt_assert (dlogi > 0);
|
||||||
|
|
||||||
/* all bidders participated with a multiplicative share */
|
/* all bidders participated with a multiplicative share */
|
||||||
|
@ -50,7 +50,8 @@ struct testcase {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
static struct testcase tcase;
|
static struct testcase tcase;
|
||||||
|
static struct GNUNET_CRYPTO_EccDlogContext *edc;
|
||||||
|
|
||||||
|
|
||||||
static struct BRANDT_Result *
|
static struct BRANDT_Result *
|
||||||
@ -330,7 +331,8 @@ run_auction (void *arg)
|
|||||||
GNUNET_TIME_UNIT_MINUTES,
|
GNUNET_TIME_UNIT_MINUTES,
|
||||||
tcase.k, /* number of prizes */
|
tcase.k, /* number of prizes */
|
||||||
tcase.m, /* m */
|
tcase.m, /* m */
|
||||||
tcase.outcome_public); /* outcome public */
|
tcase.outcome_public, /* outcome public */
|
||||||
|
tcase.outcome_public ? edc : NULL);
|
||||||
if (!tcase.ad[tcase.n])
|
if (!tcase.ad[tcase.n])
|
||||||
{
|
{
|
||||||
GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "BRANDT_new() failed.\n");
|
GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "BRANDT_new() failed.\n");
|
||||||
@ -345,7 +347,8 @@ run_auction (void *arg)
|
|||||||
&tcase.id[i],
|
&tcase.id[i],
|
||||||
desc,
|
desc,
|
||||||
desc_len,
|
desc_len,
|
||||||
tcase.bids[i]); /* bid */
|
tcase.bids[i], /* bid */
|
||||||
|
tcase.outcome_public ? edc : NULL);
|
||||||
if (!tcase.ad[i])
|
if (!tcase.ad[i])
|
||||||
{
|
{
|
||||||
GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "BRANDT_join() failed.\n");
|
GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "BRANDT_join() failed.\n");
|
||||||
@ -439,14 +442,13 @@ test_auction (uint16_t n,
|
|||||||
int
|
int
|
||||||
main (int argc, char *argv[])
|
main (int argc, char *argv[])
|
||||||
{
|
{
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
struct GNUNET_CRYPTO_EccDlogContext *edc;
|
|
||||||
|
|
||||||
if (GNUNET_OK != GNUNET_log_setup ("test_brandt", "WARNING", NULL))
|
if (GNUNET_OK != GNUNET_log_setup ("test_brandt", "WARNING", NULL))
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
edc = GNUNET_CRYPTO_ecc_dlog_prepare (1024, 16);
|
edc = GNUNET_CRYPTO_ecc_dlog_prepare (1024, 16);
|
||||||
BRANDT_init (edc);
|
BRANDT_init ();
|
||||||
|
|
||||||
ret |= 0 ||
|
ret |= 0 ||
|
||||||
// zero bidders
|
// zero bidders
|
||||||
|
Loading…
Reference in New Issue
Block a user