aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--brandt.c13
-rw-r--r--brandt.h6
-rw-r--r--crypto.c64
-rw-r--r--crypto.h12
-rw-r--r--test_brandt.c104
-rw-r--r--test_crypto.c4
6 files changed, 101 insertions, 102 deletions
diff --git a/brandt.c b/brandt.c
index 2e6a5ed..dd66e0c 100644
--- a/brandt.c
+++ b/brandt.c
@@ -77,7 +77,6 @@ BRANDT_bidder_start (struct BRANDT_Auction *auction,
77 return; 77 return;
78 } 78 }
79 79
80 weprintf("broadcasting msg_init %p from bidder %d", buf, i);
81 auction->bcast (auction->closure, buf, buflen); 80 auction->bcast (auction->closure, buf, buflen);
82 gcry_mpi_set_bit (auction->round_progress, auction->i); 81 gcry_mpi_set_bit (auction->round_progress, auction->i);
83 free (buf); 82 free (buf);
@@ -88,8 +87,8 @@ static void
88seller_start (void *arg) 87seller_start (void *arg)
89{ 88{
90 struct BRANDT_Auction *ad = (struct BRANDT_Auction *)arg; 89 struct BRANDT_Auction *ad = (struct BRANDT_Auction *)arg;
91 enum auction_type atype; 90 enum auction_type atype;
92 enum outcome_type outcome; 91 enum outcome_type outcome;
93 92
94 ad->task = NULL; 93 ad->task = NULL;
95 94
@@ -302,7 +301,7 @@ report_outcome (struct BRANDT_Auction *ad,
302 uint16_t reslen = 0; 301 uint16_t reslen = 0;
303 302
304 if (!handler_res[atype][outcome] || 303 if (!handler_res[atype][outcome] ||
305 !(res = handler_res[atype][outcome] (ad, &reslen))) 304 !(res = handler_res[atype][outcome] (ad, &reslen)))
306 ad->result (ad->closure, NULL, 0); 305 ad->result (ad->closure, NULL, 0);
307 else 306 else
308 ad->result (ad->closure, res, reslen); 307 ad->result (ad->closure, res, reslen);
@@ -341,7 +340,7 @@ advance_round (struct BRANDT_Auction *ad,
341 { 340 {
342 /* all bidders msg_decrypt received, broadcast combined msg_decrypt */ 341 /* all bidders msg_decrypt received, broadcast combined msg_decrypt */
343 if (!handler_out[atype][outcome][ad->cur_round] || 342 if (!handler_out[atype][outcome][ad->cur_round] ||
344 !(buf = handler_out[atype][outcome][ad->cur_round](ad, &buflen))) 343 !(buf = handler_out[atype][outcome][ad->cur_round](ad, &buflen)))
345 { 344 {
346 weprintf ("failed to create msg %d buffer as seller", 345 weprintf ("failed to create msg %d buffer as seller",
347 ad->cur_round); 346 ad->cur_round);
@@ -371,7 +370,7 @@ advance_round (struct BRANDT_Auction *ad,
371 370
372 /* create next message buffer */ 371 /* create next message buffer */
373 if (!handler_out[atype][outcome][ad->cur_round] || 372 if (!handler_out[atype][outcome][ad->cur_round] ||
374 !(buf = handler_out[atype][outcome][ad->cur_round](ad, &buflen))) 373 !(buf = handler_out[atype][outcome][ad->cur_round](ad, &buflen)))
375 { 374 {
376 weprintf ("failed to create msg %d buffer as bidder", ad->cur_round); 375 weprintf ("failed to create msg %d buffer as bidder", ad->cur_round);
377 return; 376 return;
@@ -404,7 +403,6 @@ BRANDT_got_message (struct BRANDT_Auction *auction,
404 /** \todo: cache out of order messages instead of discarding */ 403 /** \todo: cache out of order messages instead of discarding */
405 if (ntohl (head->msg_type) != round || ntohl (head->prot_version) != 0) 404 if (ntohl (head->msg_type) != round || ntohl (head->prot_version) != 0)
406 { 405 {
407 weprintf ("%d", auction->i);
408 weprintf ("got unexpected message, ignoring..."); 406 weprintf ("got unexpected message, ignoring...");
409 return; 407 return;
410 } 408 }
@@ -427,7 +425,6 @@ BRANDT_got_message (struct BRANDT_Auction *auction,
427 return; 425 return;
428 } 426 }
429 gcry_mpi_set_bit (auction->round_progress, sender); 427 gcry_mpi_set_bit (auction->round_progress, sender);
430 DM(auction->round_progress);
431 428
432 advance_round (auction, atype, outcome); 429 advance_round (auction, atype, outcome);
433} 430}
diff --git a/brandt.h b/brandt.h
index 3ed48b6..2017a6b 100644
--- a/brandt.h
+++ b/brandt.h
@@ -29,8 +29,7 @@
29#include <gnunet/gnunet_util_lib.h> 29#include <gnunet/gnunet_util_lib.h>
30 30
31/** Enumeration of all possible status reports for a single bidder */ 31/** Enumeration of all possible status reports for a single bidder */
32enum BRANDT_BidderStatus 32enum BRANDT_BidderStatus {
33{
34 BRANDT_bidder_won, 33 BRANDT_bidder_won,
35}; 34};
36 35
@@ -41,8 +40,7 @@ struct BRANDT_Auction;
41 * An array of this struct is given to the application by the BRANDT_CbResult() 40 * An array of this struct is given to the application by the BRANDT_CbResult()
42 * callback. One instance represents the status of a single bidder. 41 * callback. One instance represents the status of a single bidder.
43 */ 42 */
44struct BRANDT_Result 43struct BRANDT_Result {
45{
46 /** Id of the bidder this instance refers to */ 44 /** Id of the bidder this instance refers to */
47 uint16_t bidder; 45 uint16_t bidder;
48 46
diff --git a/crypto.c b/crypto.c
index eb7e944..600fbb8 100644
--- a/crypto.c
+++ b/crypto.c
@@ -816,12 +816,12 @@ quit:
816void 816void
817fp_pub_prep_outcome (struct BRANDT_Auction *ad) 817fp_pub_prep_outcome (struct BRANDT_Auction *ad)
818{ 818{
819 gcry_mpi_t coeff = gcry_mpi_copy (GCRYMPI_CONST_ONE); 819 gcry_mpi_t coeff = gcry_mpi_copy (GCRYMPI_CONST_ONE);
820 gcry_mpi_point_t tmp = gcry_mpi_point_new (0); 820 gcry_mpi_point_t tmp = gcry_mpi_point_new (0);
821 gcry_mpi_point_t *tlta1; 821 gcry_mpi_point_t *tlta1;
822 gcry_mpi_point_t *tltb1; 822 gcry_mpi_point_t *tltb1;
823 gcry_mpi_point_t **tlta2; 823 gcry_mpi_point_t **tlta2;
824 gcry_mpi_point_t **tltb2; 824 gcry_mpi_point_t **tltb2;
825 825
826 ad->gamma2 = smc_init2 (ad->n, ad->k); 826 ad->gamma2 = smc_init2 (ad->n, ad->k);
827 brandt_assert (ad->gamma2); 827 brandt_assert (ad->gamma2);
@@ -1045,7 +1045,7 @@ quit:
1045void 1045void
1046fp_pub_prep_decryption (struct BRANDT_Auction *ad) 1046fp_pub_prep_decryption (struct BRANDT_Auction *ad)
1047{ 1047{
1048 gcry_mpi_point_t tmp = gcry_mpi_point_new (0); 1048 gcry_mpi_point_t tmp = gcry_mpi_point_new (0);
1049 1049
1050 ad->phi2 = smc_init2 (ad->n, ad->k); 1050 ad->phi2 = smc_init2 (ad->n, ad->k);
1051 brandt_assert (ad->phi2); 1051 brandt_assert (ad->phi2);
@@ -1162,15 +1162,16 @@ quit:
1162} 1162}
1163 1163
1164 1164
1165struct BRANDT_Result *fp_pub_determine_outcome (struct BRANDT_Auction *ad, 1165struct BRANDT_Result *
1166 uint16_t *len) 1166fp_pub_determine_outcome (struct BRANDT_Auction *ad,
1167 uint16_t *len)
1167{ 1168{
1168 struct BRANDT_Result *ret; 1169 struct BRANDT_Result *ret;
1169 int32_t price = -1; 1170 int32_t price = -1;
1170 int32_t winner = -1; 1171 int32_t winner = -1;
1171 int dlogi = -1; 1172 int dlogi = -1;
1172 gcry_mpi_point_t sum_gamma = gcry_mpi_point_new (0); 1173 gcry_mpi_point_t sum_gamma = gcry_mpi_point_new (0);
1173 gcry_mpi_point_t sum_phi = gcry_mpi_point_new (0); 1174 gcry_mpi_point_t sum_phi = gcry_mpi_point_new (0);
1174 1175
1175 brandt_assert (ad); 1176 brandt_assert (ad);
1176 1177
@@ -1208,7 +1209,7 @@ struct BRANDT_Result *fp_pub_determine_outcome (struct BRANDT_Auction *ad,
1208 if (-1 == winner || -1 == price) 1209 if (-1 == winner || -1 == price)
1209 return NULL; 1210 return NULL;
1210 1211
1211 ret = GNUNET_new(struct BRANDT_Result); 1212 ret = GNUNET_new (struct BRANDT_Result);
1212 ret->bidder = winner; 1213 ret->bidder = winner;
1213 ret->price = price; 1214 ret->price = price;
1214 ret->status = BRANDT_bidder_won; 1215 ret->status = BRANDT_bidder_won;
@@ -1221,14 +1222,14 @@ struct BRANDT_Result *fp_pub_determine_outcome (struct BRANDT_Auction *ad,
1221void 1222void
1222fp_priv_prep_outcome (struct BRANDT_Auction *ad) 1223fp_priv_prep_outcome (struct BRANDT_Auction *ad)
1223{ 1224{
1224 gcry_mpi_point_t tmpa = gcry_mpi_point_new (0); 1225 gcry_mpi_point_t tmpa = gcry_mpi_point_new (0);
1225 gcry_mpi_point_t tmpb = gcry_mpi_point_new (0); 1226 gcry_mpi_point_t tmpb = gcry_mpi_point_new (0);
1226 gcry_mpi_point_t *tlta1; 1227 gcry_mpi_point_t *tlta1;
1227 gcry_mpi_point_t *tltb1; 1228 gcry_mpi_point_t *tltb1;
1228 gcry_mpi_point_t **tlta2; 1229 gcry_mpi_point_t **tlta2;
1229 gcry_mpi_point_t **tltb2; 1230 gcry_mpi_point_t **tltb2;
1230 gcry_mpi_point_t **tlta3; 1231 gcry_mpi_point_t **tlta3;
1231 gcry_mpi_point_t **tltb3; 1232 gcry_mpi_point_t **tltb3;
1232 1233
1233 ad->gamma3 = smc_init3 (ad->n, ad->n, ad->k); 1234 ad->gamma3 = smc_init3 (ad->n, ad->n, ad->k);
1234 brandt_assert (ad->gamma3); 1235 brandt_assert (ad->gamma3);
@@ -1452,7 +1453,7 @@ quit:
1452void 1453void
1453fp_priv_prep_decryption (struct BRANDT_Auction *ad) 1454fp_priv_prep_decryption (struct BRANDT_Auction *ad)
1454{ 1455{
1455 gcry_mpi_point_t tmp = gcry_mpi_point_new (0); 1456 gcry_mpi_point_t tmp = gcry_mpi_point_new (0);
1456 1457
1457 ad->phi3 = smc_init3 (ad->n, ad->n, ad->k); 1458 ad->phi3 = smc_init3 (ad->n, ad->n, ad->k);
1458 brandt_assert (ad->phi3); 1459 brandt_assert (ad->phi3);
@@ -1682,10 +1683,10 @@ fp_priv_recv_decryption_bidder (struct BRANDT_Auction *ad,
1682 ec_point_parse (phi, (struct ec_mpi *)cur); 1683 ec_point_parse (phi, (struct ec_mpi *)cur);
1683 proof2 = (struct proof_2dle *)(cur + sizeof (struct ec_mpi)); 1684 proof2 = (struct proof_2dle *)(cur + sizeof (struct ec_mpi));
1684 if (smc_zkp_2dle_check (phi, 1685 if (smc_zkp_2dle_check (phi,
1685 ad->y[h], 1686 ad->y[h],
1686 ad->phi3[h][i][j], 1687 ad->phi3[h][i][j],
1687 ec_gen, 1688 ec_gen,
1688 proof2)) 1689 proof2))
1689 { 1690 {
1690 weprintf ("wrong zkp2 for phi, y received from seller"); 1691 weprintf ("wrong zkp2 for phi, y received from seller");
1691 goto quit; 1692 goto quit;
@@ -1717,8 +1718,9 @@ fp_priv_recv_decryption (struct BRANDT_Auction *ad,
1717} 1718}
1718 1719
1719 1720
1720struct BRANDT_Result *fp_priv_determine_outcome (struct BRANDT_Auction *ad, 1721struct BRANDT_Result *
1721 uint16_t *len) 1722fp_priv_determine_outcome (struct BRANDT_Auction *ad,
1723 uint16_t *len)
1722{ 1724{
1723 struct BRANDT_Result *ret; 1725 struct BRANDT_Result *ret;
1724 int32_t price = -1; 1726 int32_t price = -1;
@@ -1762,7 +1764,7 @@ struct BRANDT_Result *fp_priv_determine_outcome (struct BRANDT_Auction *ad,
1762 if (-1 == winner || -1 == price) 1764 if (-1 == winner || -1 == price)
1763 return NULL; 1765 return NULL;
1764 1766
1765 ret = GNUNET_new(struct BRANDT_Result); 1767 ret = GNUNET_new (struct BRANDT_Result);
1766 ret->bidder = winner; 1768 ret->bidder = winner;
1767 ret->price = price; 1769 ret->price = price;
1768 ret->status = BRANDT_bidder_won; 1770 ret->status = BRANDT_bidder_won;
diff --git a/crypto.h b/crypto.h
index 16aa536..e9338f4 100644
--- a/crypto.h
+++ b/crypto.h
@@ -176,14 +176,14 @@ typedef void
176 176
177typedef int 177typedef int
178(*MsgIn)(struct BRANDT_Auction *ad, 178(*MsgIn)(struct BRANDT_Auction *ad,
179 const unsigned char *buf, 179 const unsigned char *buf,
180 size_t buflen, 180 size_t buflen,
181 uint16_t sender); 181 uint16_t sender);
182 182
183 183
184typedef unsigned char * 184typedef unsigned char *
185(*MsgOut)(struct BRANDT_Auction *ad, 185(*MsgOut)(struct BRANDT_Auction *ad,
186 size_t *buflen); 186 size_t *buflen);
187 187
188 188
189/** 189/**
@@ -317,9 +317,9 @@ static const MsgOut handler_out[auction_last][outcome_last][msg_last] = {
317 * of 0 means a private outcome, while a value of 1 means public outcome. 317 * of 0 means a private outcome, while a value of 1 means public outcome.
318 */ 318 */
319static const Result handler_res[auction_last][outcome_last] = { 319static const Result handler_res[auction_last][outcome_last] = {
320 [auction_firstPrice] = { 320 [auction_firstPrice] = {
321 [outcome_private] = &fp_priv_determine_outcome, 321 [outcome_private] = &fp_priv_determine_outcome,
322 [outcome_public] = &fp_pub_determine_outcome, 322 [outcome_public] = &fp_pub_determine_outcome,
323 }, 323 },
324// [auction_mPlusFirstPrice] = { 324// [auction_mPlusFirstPrice] = {
325// [outcome_private] = , 325// [outcome_private] = ,
diff --git a/test_brandt.c b/test_brandt.c
index fb0f2c9..077f6f1 100644
--- a/test_brandt.c
+++ b/test_brandt.c
@@ -30,19 +30,18 @@
30#include "util.h" 30#include "util.h"
31 31
32 32
33struct msg 33struct msg {
34{ 34 uint16_t sender;
35 uint16_t sender; 35 uint16_t receiver;
36 uint16_t receiver; 36 void *buf;
37 void *buf; 37 size_t buf_len;
38 size_t buf_len;
39}; 38};
40 39
41 40
42static uint16_t *id; 41static uint16_t *id;
43static struct BRANDT_Auction **ad; 42static struct BRANDT_Auction **ad;
44static uint16_t bidders = 3; 43static uint16_t bidders = 3;
45static uint16_t prizes = 8; 44static uint16_t prizes = 8;
46 45
47 46
48static void 47static void
@@ -50,7 +49,7 @@ bidder_start (void *arg)
50{ 49{
51 uint16_t i = *(uint16_t *)arg; 50 uint16_t i = *(uint16_t *)arg;
52 51
53 weprintf("starting bidder %d", i); 52 weprintf ("starting bidder %d", i);
54 BRANDT_bidder_start (ad[i], i, bidders); 53 BRANDT_bidder_start (ad[i], i, bidders);
55} 54}
56 55
@@ -58,10 +57,11 @@ bidder_start (void *arg)
58static void 57static void
59transfer_message (void *arg) 58transfer_message (void *arg)
60{ 59{
61 struct msg *m = (struct msg *)arg; 60 struct msg *m = (struct msg *)arg;
62 struct msg_head *h = (struct msg_head *)m->buf; 61 struct msg_head *h = (struct msg_head *)m->buf;
63 62
64 weprintf("xfer msg %d %x from %d to %d", ntohl(h->msg_type), arg, m->sender, m->receiver); 63 weprintf ("xfer msg %d %x from %d to %d", ntohl (
64 h->msg_type), arg, m->sender, m->receiver);
65 BRANDT_got_message (ad[m->receiver], m->sender, m->buf, m->buf_len); 65 BRANDT_got_message (ad[m->receiver], m->sender, m->buf, m->buf_len);
66 free (arg); 66 free (arg);
67} 67}
@@ -71,6 +71,7 @@ static uint16_t
71cb_start (void *auction_closure) 71cb_start (void *auction_closure)
72{ 72{
73 uint16_t *s = (uint16_t *)auction_closure; 73 uint16_t *s = (uint16_t *)auction_closure;
74
74 if (!s || bidders != *s) 75 if (!s || bidders != *s)
75 { 76 {
76 weprintf ("start callback called from bidder"); 77 weprintf ("start callback called from bidder");
@@ -89,7 +90,7 @@ cb_broadcast (void *auction_closure,
89 const void *msg, 90 const void *msg,
90 size_t msg_len) 91 size_t msg_len)
91{ 92{
92 uint16_t *s = (uint16_t *)auction_closure; 93 uint16_t *s = (uint16_t *)auction_closure;
93 struct msg *m; 94 struct msg *m;
94 95
95 for (uint16_t i = 0; i <= bidders; i++) 96 for (uint16_t i = 0; i <= bidders; i++)
@@ -113,7 +114,7 @@ cb_unicast (void *auction_closure,
113 const void *msg, 114 const void *msg,
114 size_t msg_len) 115 size_t msg_len)
115{ 116{
116 uint16_t *s = (uint16_t *)auction_closure; 117 uint16_t *s = (uint16_t *)auction_closure;
117 struct msg *m; 118 struct msg *m;
118 119
119 m = GNUNET_new (struct msg); 120 m = GNUNET_new (struct msg);
@@ -139,37 +140,38 @@ cb_result (void *auction_closure,
139 weprintf ("result determined by agent %d: none", *s); 140 weprintf ("result determined by agent %d: none", *s);
140 141
141 for (uint16_t i = 0; i < results_len; i++) 142 for (uint16_t i = 0; i < results_len; i++)
142 weprintf ("result determined by agent %d: bidder %d got status %d with price %d", 143 weprintf (
143 *s, 144 "result determined by agent %d: bidder %d got status %d with price %d",
144 results[i].bidder, 145 *s,
145 results[i].status, 146 results[i].bidder,
146 results[i].price); 147 results[i].status,
148 results[i].price);
147} 149}
148 150
149 151
150static void 152static void
151run_new_join (void *arg) 153run_new_join (void *arg)
152{ 154{
153 int *ret = arg; 155 int *ret = arg;
154 const char description[] = "test description for test_new_join"; 156 const char description[] = "test description for test_new_join";
155 void *desc; 157 void *desc;
156 size_t desc_len; 158 size_t desc_len;
157 159
158 ad = GNUNET_new_array (bidders + 1, struct BRANDT_Auction *); 160 ad = GNUNET_new_array (bidders + 1, struct BRANDT_Auction *);
159 161
160 ad[bidders] = BRANDT_new (&cb_result, 162 ad[bidders] = BRANDT_new (&cb_result,
161 &cb_broadcast, 163 &cb_broadcast,
162 &cb_start, 164 &cb_start,
163 &id[bidders], 165 &id[bidders],
164 &desc, 166 &desc,
165 &desc_len, 167 &desc_len,
166 description, 168 description,
167 sizeof (description), 169 sizeof (description),
168 GNUNET_TIME_absolute_get (), 170 GNUNET_TIME_absolute_get (),
169 GNUNET_TIME_UNIT_MINUTES, 171 GNUNET_TIME_UNIT_MINUTES,
170 prizes, /* amount of possible prizes */ 172 prizes, /* amount of possible prizes */
171 0, /* m */ 173 0, /* m */
172 1); /* outcome public */ 174 1); /* outcome public */
173 if (!ad[bidders]) 175 if (!ad[bidders])
174 { 176 {
175 weprintf ("BRANDT_new() failed."); 177 weprintf ("BRANDT_new() failed.");
@@ -179,14 +181,14 @@ run_new_join (void *arg)
179 for (uint16_t i = 0; i < bidders; i++) 181 for (uint16_t i = 0; i < bidders; i++)
180 { 182 {
181 ad[i] = BRANDT_join (&cb_result, 183 ad[i] = BRANDT_join (&cb_result,
182 &cb_broadcast, 184 &cb_broadcast,
183 &cb_unicast, 185 &cb_unicast,
184 &id[i], 186 &id[i],
185 desc, 187 desc,
186 desc_len, 188 desc_len,
187 description, 189 description,
188 sizeof (description), 190 sizeof (description),
189 3); /* bid */ 191 3); /* bid */
190 if (!ad[i]) 192 if (!ad[i])
191 { 193 {
192 weprintf ("BRANDT_join() failed."); 194 weprintf ("BRANDT_join() failed.");
@@ -194,14 +196,14 @@ run_new_join (void *arg)
194 } 196 }
195 197
196 if (ad[bidders]->k != ad[i]->k || 198 if (ad[bidders]->k != ad[i]->k ||
197 ad[bidders]->m != ad[i]->m || 199 ad[bidders]->m != ad[i]->m ||
198 ad[bidders]->outcome_public != ad[i]->outcome_public || 200 ad[bidders]->outcome_public != ad[i]->outcome_public ||
199 ad[bidders]->time_start.abs_value_us 201 ad[bidders]->time_start.abs_value_us
200 != ad[i]->time_start.abs_value_us || 202 != ad[i]->time_start.abs_value_us ||
201 ad[bidders]->time_round.rel_value_us 203 ad[bidders]->time_round.rel_value_us
202 != ad[i]->time_round.rel_value_us || 204 != ad[i]->time_round.rel_value_us ||
203 !ad[bidders]->seller_mode || /* todo: split out */ 205 !ad[bidders]->seller_mode || /* todo: split out */
204 ad[i]->seller_mode) 206 ad[i]->seller_mode)
205 { 207 {
206 weprintf ("error/mismatch in basic auction data"); 208 weprintf ("error/mismatch in basic auction data");
207 _exit (1); 209 _exit (1);
diff --git a/test_crypto.c b/test_crypto.c
index 2a04c1d..cfc6160 100644
--- a/test_crypto.c
+++ b/test_crypto.c
@@ -199,7 +199,7 @@ test_setup_auction_data ()
199 199
200/** 200/**
201 * compute round @a index of the protocol specified by @a type and @a oc 201 * compute round @a index of the protocol specified by @a type and @a oc
202 * 202 *
203 * @param[in] type auction type 203 * @param[in] type auction type
204 * @param[in] oc outcome type 204 * @param[in] oc outcome type
205 * @param[in] index round index 205 * @param[in] index round index
@@ -310,7 +310,7 @@ test_all_auctions ()
310 310
311 for (size_t oc = 0; oc < outcome_last; oc++) 311 for (size_t oc = 0; oc < outcome_last; oc++)
312 { 312 {
313 if (!test_setup_auction_data() || !test_auction (atype, oc)) 313 if (!test_setup_auction_data () || !test_auction (atype, oc))
314 { 314 {
315 cleanup_auction_data (); 315 cleanup_auction_data ();
316 return 0; 316 return 0;