aboutsummaryrefslogtreecommitdiff
path: root/crypto.c
diff options
context:
space:
mode:
authorMarkus Teich <markus.teich@stusta.mhn.de>2016-06-22 23:18:46 +0200
committerMarkus Teich <markus.teich@stusta.mhn.de>2016-06-22 23:18:46 +0200
commit0fc7fb86b84e16daeabaea1fea455e65cc48b66e (patch)
tree7843096e14d6fa8a8585152c7f8c03f9185f0a3d /crypto.c
parenta9e4574c492207a840287e95e890c4b991849896 (diff)
downloadlibbrandt-0fc7fb86b84e16daeabaea1fea455e65cc48b66e.tar.gz
libbrandt-0fc7fb86b84e16daeabaea1fea455e65cc48b66e.zip
random fixes
Diffstat (limited to 'crypto.c')
-rw-r--r--crypto.c55
1 files changed, 31 insertions, 24 deletions
diff --git a/crypto.c b/crypto.c
index d7aafef..b8e995e 100644
--- a/crypto.c
+++ b/crypto.c
@@ -17,6 +17,7 @@
17/** 17/**
18 * @file crypto.c 18 * @file crypto.c
19 * @brief Implementation of the crypto primitives. 19 * @brief Implementation of the crypto primitives.
20 * @author Markus Teich
20 */ 21 */
21 22
22 23
@@ -86,18 +87,6 @@ brandt_crypto_init ()
86} 87}
87 88
88 89
89/* --- RANDOM --- */
90
91void
92brandt_rand_poll ()
93{
94 static unsigned char rand_amount = 255;
95
96 if (!(rand_amount--))
97 gcry_fast_random_poll ();
98}
99
100
101/* --- HASHING --- */ 90/* --- HASHING --- */
102 91
103/** 92/**
@@ -299,8 +288,11 @@ mpi_parse (gcry_mpi_t dst, const struct ec_mpi *src)
299 gcry_mpi_t ret; 288 gcry_mpi_t ret;
300 gcry_error_t rc; 289 gcry_error_t rc;
301 290
302 rc = gcry_mpi_scan (&ret, GCRYMPI_FMT_USG, 291 rc = gcry_mpi_scan (&ret,
303 src, sizeof (struct ec_mpi), NULL); 292 GCRYMPI_FMT_USG,
293 src,
294 sizeof (struct ec_mpi),
295 NULL);
304 brandt_assert_gpgerr (rc); 296 brandt_assert_gpgerr (rc);
305 297
306 gcry_mpi_snatch (dst, ret); 298 gcry_mpi_snatch (dst, ret);
@@ -369,6 +361,7 @@ ec_point_parse (gcry_mpi_point_t dst, const struct ec_mpi *src)
369 brandt_assert (ret); 361 brandt_assert (ret);
370 gcry_ctx_release (ctx); 362 gcry_ctx_release (ctx);
371 gcry_mpi_ec_mul (dst, GCRYMPI_CONST_ONE, ret, ec_ctx); 363 gcry_mpi_ec_mul (dst, GCRYMPI_CONST_ONE, ret, ec_ctx);
364 gcry_mpi_point_release (ret);
372} 365}
373 366
374 367
@@ -382,7 +375,8 @@ ec_point_parse (gcry_mpi_point_t dst, const struct ec_mpi *src)
382static void 375static void
383smc_free2 (gcry_mpi_point_t **dst, uint16_t size1, uint16_t size2) 376smc_free2 (gcry_mpi_point_t **dst, uint16_t size1, uint16_t size2)
384{ 377{
385 uint16_t i, j; 378 uint16_t i;
379 uint16_t j;
386 380
387 if (NULL == dst) 381 if (NULL == dst)
388 return; 382 return;
@@ -406,7 +400,8 @@ smc_free2 (gcry_mpi_point_t **dst, uint16_t size1, uint16_t size2)
406static gcry_mpi_point_t ** 400static gcry_mpi_point_t **
407smc_init2 (uint16_t size1, uint16_t size2) 401smc_init2 (uint16_t size1, uint16_t size2)
408{ 402{
409 uint16_t i, j; 403 uint16_t i;
404 uint16_t j;
410 gcry_mpi_point_t **ret; 405 gcry_mpi_point_t **ret;
411 gcry_mpi_point_t *data; 406 gcry_mpi_point_t *data;
412 407
@@ -449,7 +444,9 @@ smc_free3 (gcry_mpi_point_t ***dst,
449 uint16_t size2, 444 uint16_t size2,
450 uint16_t size3) 445 uint16_t size3)
451{ 446{
452 uint16_t i, j, k; 447 uint16_t i;
448 uint16_t j;
449 uint16_t k;
453 450
454 if (NULL == dst) 451 if (NULL == dst)
455 return; 452 return;
@@ -475,7 +472,9 @@ smc_free3 (gcry_mpi_point_t ***dst,
475static gcry_mpi_point_t *** 472static gcry_mpi_point_t ***
476smc_init3 (uint16_t size1, uint16_t size2, uint16_t size3) 473smc_init3 (uint16_t size1, uint16_t size2, uint16_t size3)
477{ 474{
478 uint16_t i, j, k; 475 uint16_t i;
476 uint16_t j;
477 uint16_t k;
479 gcry_mpi_point_t ***ret; 478 gcry_mpi_point_t ***ret;
480 gcry_mpi_point_t **layer1; 479 gcry_mpi_point_t **layer1;
481 gcry_mpi_point_t *layer2; 480 gcry_mpi_point_t *layer2;
@@ -667,8 +666,12 @@ smc_encrypt_bid (struct AuctionData *ad, size_t *buflen)
667 for (j = 0; j < ad->k; j++) 666 for (j = 0; j < ad->k; j++)
668 { 667 {
669 proof3 = (struct proof_0og *)(cur + 2 * sizeof (struct ec_mpi)); 668 proof3 = (struct proof_0og *)(cur + 2 * sizeof (struct ec_mpi));
670 smc_zkp_0og (j == ad->b, ad->Y, r_part, 669 smc_zkp_0og (j == ad->b,
671 ad->alpha[ad->i][j], ad->beta[ad->i][j], proof3); 670 ad->Y,
671 r_part,
672 ad->alpha[ad->i][j],
673 ad->beta[ad->i][j],
674 proof3);
672 ec_point_serialize ((struct ec_mpi *)cur, ad->alpha[ad->i][j]); 675 ec_point_serialize ((struct ec_mpi *)cur, ad->alpha[ad->i][j]);
673 ec_point_serialize (&((struct ec_mpi *)cur)[1], ad->beta[ad->i][j]); 676 ec_point_serialize (&((struct ec_mpi *)cur)[1], ad->beta[ad->i][j]);
674 gcry_mpi_addm (r_sum, r_sum, r_part, ec_n); 677 gcry_mpi_addm (r_sum, r_sum, r_part, ec_n);
@@ -726,7 +729,10 @@ smc_recv_encrypted_bid (struct AuctionData *ad,
726 } 729 }
727 730
728 gcry_mpi_ec_sub (alpha_sum, alpha_sum, ec_gen, ec_ctx); 731 gcry_mpi_ec_sub (alpha_sum, alpha_sum, ec_gen, ec_ctx);
729 if (smc_zkp_2dle_check (alpha_sum, beta_sum, ad->Y, ec_gen, 732 if (smc_zkp_2dle_check (alpha_sum,
733 beta_sum,
734 ad->Y,
735 ec_gen,
730 (struct proof_2dle *)cur)) 736 (struct proof_2dle *)cur))
731 { 737 {
732 weprintf ("wrong zkp2 for alpha, beta received"); 738 weprintf ("wrong zkp2 for alpha, beta received");
@@ -757,7 +763,8 @@ quit:
757void 763void
758smc_compute_outcome (struct AuctionData *ad) 764smc_compute_outcome (struct AuctionData *ad)
759{ 765{
760 uint16_t i, j; 766 uint16_t i;
767 uint16_t j;
761 768
762 // create temporary table with partial sums 769 // create temporary table with partial sums
763 770
@@ -900,8 +907,8 @@ smc_zkp_2dle (gcry_mpi_point_t v,
900 gcry_mpi_t c = gcry_mpi_new (0); 907 gcry_mpi_t c = gcry_mpi_new (0);
901 gcry_mpi_t z = gcry_mpi_new (0); 908 gcry_mpi_t z = gcry_mpi_new (0);
902 909
903 rv = (NULL == v) ? rv = gcry_mpi_point_new (0) : v; 910 rv = (NULL == v) ? gcry_mpi_point_new (0) : v;
904 rw = (NULL == w) ? rw = gcry_mpi_point_new (0) : w; 911 rw = (NULL == w) ? gcry_mpi_point_new (0) : w;
905 912
906 /* v = x*g1 */ 913 /* v = x*g1 */
907 gcry_mpi_ec_mul (rv, x, g1, ec_ctx); 914 gcry_mpi_ec_mul (rv, x, g1, ec_ctx);