aboutsummaryrefslogtreecommitdiff
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
parenta9e4574c492207a840287e95e890c4b991849896 (diff)
downloadlibbrandt-0fc7fb86b84e16daeabaea1fea455e65cc48b66e.tar.gz
libbrandt-0fc7fb86b84e16daeabaea1fea455e65cc48b66e.zip
random fixes
-rw-r--r--brandt.c2
-rw-r--r--brandt.h1
-rw-r--r--crypto.c55
-rw-r--r--crypto.h6
-rw-r--r--internals.h1
-rw-r--r--test.h1
-rw-r--r--test_crypto.c10
-rw-r--r--util.c1
-rw-r--r--util.h22
9 files changed, 66 insertions, 33 deletions
diff --git a/brandt.c b/brandt.c
index 6a9f7c8..c5d5a61 100644
--- a/brandt.c
+++ b/brandt.c
@@ -17,6 +17,7 @@
17/** 17/**
18 * @file brandt.c 18 * @file brandt.c
19 * @brief \todo 19 * @brief \todo
20 * @author Markus Teich
20 */ 21 */
21#include <gcrypt.h> 22#include <gcrypt.h>
22 23
@@ -42,6 +43,5 @@ BRANDT_init ()
42 gcry_strerror (err)); 43 gcry_strerror (err));
43 44
44 gcry_control (GCRYCTL_INITIALIZATION_FINISHED, 0); 45 gcry_control (GCRYCTL_INITIALIZATION_FINISHED, 0);
45 brandt_rand_poll ();
46 brandt_crypto_init (); 46 brandt_crypto_init ();
47} 47}
diff --git a/brandt.h b/brandt.h
index a3ccc30..e66866d 100644
--- a/brandt.h
+++ b/brandt.h
@@ -17,6 +17,7 @@
17/** 17/**
18 * @file brandt.h 18 * @file brandt.h
19 * @brief This Header defines the external interface of libbrandt. 19 * @brief This Header defines the external interface of libbrandt.
20 * @author Markus Teich
20 */ 21 */
21 22
22#ifndef _BRANDT_BRANDT_H 23#ifndef _BRANDT_BRANDT_H
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);
diff --git a/crypto.h b/crypto.h
index d00a138..77e1848 100644
--- a/crypto.h
+++ b/crypto.h
@@ -17,6 +17,7 @@
17/** 17/**
18 * @file crypto.h 18 * @file crypto.h
19 * @brief Interface of the crypto primitives. 19 * @brief Interface of the crypto primitives.
20 * @author Markus Teich
20 */ 21 */
21 22
22#ifndef _BRANDT_CRYPTO_H 23#ifndef _BRANDT_CRYPTO_H
@@ -30,11 +31,6 @@
30void brandt_crypto_init (); 31void brandt_crypto_init ();
31 32
32 33
33/* --- RANDOM --- */
34
35void brandt_rand_poll ();
36
37
38/* --- HASHING --- */ 34/* --- HASHING --- */
39 35
40struct brandt_hash_code { 36struct brandt_hash_code {
diff --git a/internals.h b/internals.h
index 06ec88c..1e6eb18 100644
--- a/internals.h
+++ b/internals.h
@@ -17,6 +17,7 @@
17/** 17/**
18 * @file internals.h 18 * @file internals.h
19 * @brief This header contains library internal structs. 19 * @brief This header contains library internal structs.
20 * @author Markus Teich
20 */ 21 */
21 22
22#ifndef _BRANDT_INTERNALS_H 23#ifndef _BRANDT_INTERNALS_H
diff --git a/test.h b/test.h
index da9485e..9e93b25 100644
--- a/test.h
+++ b/test.h
@@ -17,6 +17,7 @@
17/** 17/**
18 * @file test.h 18 * @file test.h
19 * @brief Some helpers for running tests 19 * @brief Some helpers for running tests
20 * @author Markus Teich
20 */ 21 */
21#ifndef _BRANDT_TEST_H 22#ifndef _BRANDT_TEST_H
22#define _BRANDT_TEST_H 23#define _BRANDT_TEST_H
diff --git a/test_crypto.c b/test_crypto.c
index 33b9a9b..c0e9740 100644
--- a/test_crypto.c
+++ b/test_crypto.c
@@ -17,6 +17,7 @@
17/** 17/**
18 * @file test_crypto.c 18 * @file test_crypto.c
19 * @brief testing crypto and smc functions. 19 * @brief testing crypto and smc functions.
20 * @author Markus Teich
20 */ 21 */
21 22
22/* For testing static functions and variables we include the whole source */ 23/* For testing static functions and variables we include the whole source */
@@ -259,10 +260,13 @@ test_round1 ()
259void 260void
260cleanup_auction_data () 261cleanup_auction_data ()
261{ 262{
262 uint16_t i; 263 for (uint16_t i = 0; i < bidders; i++)
263
264 for (i = 0; i < bidders; i++)
265 { 264 {
265 for (uint16_t h = 0; h < bidders; h++)
266 gcry_mpi_point_release (ad[i].y[h]);
267
268 gcry_mpi_point_release (ad[i].Y);
269 gcry_mpi_release (ad[i].x);
266 free (ad[i].y); 270 free (ad[i].y);
267 smc_free2 (ad[i].alpha, ad[i].n, ad[i].k); 271 smc_free2 (ad[i].alpha, ad[i].n, ad[i].k);
268 smc_free2 (ad[i].beta, ad[i].n, ad[i].k); 272 smc_free2 (ad[i].beta, ad[i].n, ad[i].k);
diff --git a/util.c b/util.c
index 5eebd3c..2b44710 100644
--- a/util.c
+++ b/util.c
@@ -17,6 +17,7 @@
17/** 17/**
18 * @file util.c 18 * @file util.c
19 * @brief \todo 19 * @brief \todo
20 * @author Markus Teich
20 */ 21 */
21#include <stdarg.h> 22#include <stdarg.h>
22#include <stdio.h> 23#include <stdio.h>
diff --git a/util.h b/util.h
index 7e4df86..4af3f74 100644
--- a/util.h
+++ b/util.h
@@ -1,3 +1,25 @@
1/* This file is part of libbrandt.
2 * Copyright (C) 2016 GNUnet e.V.
3 *
4 * libbrandt is free software: you can redistribute it and/or modify it under
5 * the terms of the GNU General Public License as published by the Free Software
6 * Foundation, either version 3 of the License, or (at your option) any later
7 * version.
8 *
9 * libbrandt is distributed in the hope that it will be useful, but WITHOUT ANY
10 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
11 * A PARTICULAR PURPOSE. See the GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License along with
14 * libbrandt. If not, see <http://www.gnu.org/licenses/>.
15 */
16
17/**
18 * @file util.h
19 * @brief \todo
20 * @author Markus Teich
21 */
22
1#ifndef _BRANDT_UTIL_H 23#ifndef _BRANDT_UTIL_H
2#define _BRANDT_UTIL_H 24#define _BRANDT_UTIL_H
3 25