diff options
author | Markus Teich <markus.teich@stusta.mhn.de> | 2016-09-08 19:17:15 +0200 |
---|---|---|
committer | Markus Teich <markus.teich@stusta.mhn.de> | 2016-09-08 19:17:15 +0200 |
commit | 14546eccb205aa844657d2c350c83f6be1289b67 (patch) | |
tree | 8d081850e2ca5dd44b1e03d7ed39a61c487c9725 /brandt.c | |
parent | f294cd3a85c084490a10ae6ac9c1dab4c60a7678 (diff) | |
download | libbrandt-14546eccb205aa844657d2c350c83f6be1289b67.tar.gz libbrandt-14546eccb205aa844657d2c350c83f6be1289b67.zip |
test_brandt nearly done
Diffstat (limited to 'brandt.c')
-rw-r--r-- | brandt.c | 95 |
1 files changed, 57 insertions, 38 deletions
@@ -287,6 +287,7 @@ BRANDT_destroy (struct BRANDT_Auction *auction) | |||
287 | smc_free3 (auction->delta3, auction->n, auction->n, auction->k); | 287 | smc_free3 (auction->delta3, auction->n, auction->n, auction->k); |
288 | smc_free2 (auction->phi2, auction->n, auction->k); | 288 | smc_free2 (auction->phi2, auction->n, auction->k); |
289 | smc_free3 (auction->phi3, auction->n, auction->n, auction->k); | 289 | smc_free3 (auction->phi3, auction->n, auction->n, auction->k); |
290 | free (auction->phiproofs3); | ||
290 | smc_free1 (auction->tmpa1, auction->k); | 291 | smc_free1 (auction->tmpa1, auction->k); |
291 | smc_free1 (auction->tmpb1, auction->k); | 292 | smc_free1 (auction->tmpb1, auction->k); |
292 | } | 293 | } |
@@ -304,56 +305,75 @@ advance_round (struct BRANDT_Auction *ad, | |||
304 | 305 | ||
305 | /* if we did not got the current round message from all participants, don't | 306 | /* if we did not got the current round message from all participants, don't |
306 | * advance to the next round yet. Early return, since we have to wait for | 307 | * advance to the next round yet. Early return, since we have to wait for |
307 | * the other participants messages. */ | 308 | * the other participants messages. In the msg_decrypt round as a bidder we |
309 | * only need the one message from the seller. */ | ||
308 | for (uint16_t i = 0; i < ad->n; i++) | 310 | for (uint16_t i = 0; i < ad->n; i++) |
309 | if (!gcry_mpi_test_bit (ad->round_progress, i)) | 311 | if (!gcry_mpi_test_bit (ad->round_progress, i) && |
312 | (ad->seller_mode || msg_decrypt != ad->cur_round)) | ||
310 | return; | 313 | return; |
311 | 314 | ||
312 | /* current round finished, clear round progress and advance to next one */ | 315 | /* Do not advance to the next round if we are the seller and got all |
313 | gcry_mpi_clear_highbit (ad->round_progress, 0); | 316 | * msg_decrypt messages from the bidders. We need to broadcast our combined |
314 | if (msg_last == ++(ad->cur_round)) | 317 | * msg_decrypt message back to the sellers first */ |
318 | if (!ad->seller_mode || msg_decrypt != ad->cur_round) | ||
315 | { | 319 | { |
316 | /* done with all rounds, determine outcome here */ | 320 | /* clear old round progress and advance to next one */ |
317 | if (!handler_res[atype][outcome] || | 321 | gcry_mpi_clear_highbit (ad->round_progress, 0); |
318 | !(res = handler_res[atype][outcome] (ad, &reslen))) | 322 | ad->cur_round++; |
319 | { | ||
320 | /** \todo */ | ||
321 | weprintf ("wow fail result"); | ||
322 | /** \todo: call result with null pointer here? */ | ||
323 | return; | ||
324 | } | ||
325 | 323 | ||
326 | ad->result (ad->closure, res, reslen); | 324 | /* prepare next round. */ |
327 | return; | 325 | if (handler_prep[atype][outcome][ad->cur_round]) |
328 | } | 326 | handler_prep[atype][outcome][ad->cur_round] (ad); |
329 | 327 | ||
330 | if (handler_prep[atype][outcome][ad->cur_round]) | ||
331 | handler_prep[atype][outcome][ad->cur_round] (ad); | ||
332 | |||
333 | if (ad->seller_mode) | ||
334 | { | ||
335 | /** \todo: setup round timeout trigger */ | 328 | /** \todo: setup round timeout trigger */ |
336 | return; | 329 | if (ad->seller_mode) |
330 | { | ||
331 | } | ||
337 | } | 332 | } |
338 | 333 | ||
339 | if (!handler_out[atype][outcome][ad->cur_round] || | 334 | /* send next message if we are not done yet */ |
340 | !(buf = handler_out[atype][outcome][ad->cur_round](ad, &buflen))) | 335 | if ((!ad->seller_mode && msg_last > ad->cur_round) || |
336 | (ad->seller_mode && msg_decrypt == ad->cur_round && | ||
337 | gcry_mpi_test_bit (ad->round_progress, 0))) | ||
341 | { | 338 | { |
342 | /** \todo */ | 339 | if (!handler_out[atype][outcome][ad->cur_round] || |
343 | weprintf ("wow fail out"); | 340 | !(buf = handler_out[atype][outcome][ad->cur_round](ad, &buflen))) |
344 | return; | 341 | { |
345 | } | 342 | weprintf ("failed to create message %d buffer", ad->cur_round); |
343 | return; | ||
344 | } | ||
346 | 345 | ||
347 | /* last message only sent to seller, others are broadcasted */ | 346 | /* msg_decrypt unicast to seller or broadcast from seller. |
348 | if (msg_decrypt == ad->cur_round) | 347 | * All other messages are broadcasted */ |
349 | { | 348 | if (msg_decrypt == ad->cur_round && !ad->seller_mode) |
350 | if (0 == ad->ucast (ad->closure, buf, buflen)) | 349 | { |
351 | gcry_mpi_set_bit (ad->round_progress, ad->i); | 350 | if (0 == ad->ucast (ad->closure, buf, buflen)) |
351 | gcry_mpi_set_bit (ad->round_progress, ad->i); | ||
352 | } | ||
353 | else | ||
354 | { | ||
355 | if (!ad->seller_mode && 0 == ad->bcast (ad->closure, buf, buflen)) | ||
356 | gcry_mpi_set_bit (ad->round_progress, ad->i); | ||
357 | } | ||
352 | } | 358 | } |
353 | else | 359 | |
360 | if (msg_last == ad->cur_round || | ||
361 | (msg_decrypt == ad->cur_round && ad->seller_mode && | ||
362 | gcry_mpi_test_bit (ad->round_progress, 0))) | ||
354 | { | 363 | { |
355 | if (0 == ad->bcast (ad->closure, buf, buflen)) | 364 | /* done with all rounds, determine outcome here */ |
356 | gcry_mpi_set_bit (ad->round_progress, ad->i); | 365 | if (!handler_res[atype][outcome] || |
366 | !(res = handler_res[atype][outcome] (ad, &reslen))) | ||
367 | { | ||
368 | weprintf ("failed to determine result"); | ||
369 | /** \todo: call result with null pointer here? */ | ||
370 | return; | ||
371 | } | ||
372 | |||
373 | ad->result (ad->closure, res, reslen); | ||
374 | /* seller still needs to broadcast the decryption to all bidders */ | ||
375 | if (!ad->seller_mode) | ||
376 | return; | ||
357 | } | 377 | } |
358 | } | 378 | } |
359 | 379 | ||
@@ -400,6 +420,5 @@ BRANDT_got_message (struct BRANDT_Auction *auction, | |||
400 | gcry_mpi_set_bit (auction->round_progress, sender); | 420 | gcry_mpi_set_bit (auction->round_progress, sender); |
401 | DM(auction->round_progress); | 421 | DM(auction->round_progress); |
402 | 422 | ||
403 | /** \todo: seller_mode and new task for round timing */ | ||
404 | advance_round (auction, atype, outcome); | 423 | advance_round (auction, atype, outcome); |
405 | } | 424 | } |