aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile.am6
-rw-r--r--brandt.c28
-rw-r--r--brandt.h4
-rw-r--r--configure.ac15
-rw-r--r--crypto.c16
-rw-r--r--crypto.h11
-rw-r--r--platform.h44
-rw-r--r--test_brandt.c124
-rw-r--r--test_crypto.c5
9 files changed, 199 insertions, 54 deletions
diff --git a/Makefile.am b/Makefile.am
index c23bec4..977a4d0 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -16,9 +16,13 @@ libbrandt_la_LDFLAGS = \
16 -version-info 0:0:0 16 -version-info 0:0:0
17 17
18check_PROGRAMS = \ 18check_PROGRAMS = \
19 test_crypto 19 test_crypto \
20 test_brandt
20 21
21test_crypto_SOURCES = test_crypto.c 22test_crypto_SOURCES = test_crypto.c
22test_crypto_LDADD = libbrandt.la -lgcrypt -lgpg-error -lgnunetutil 23test_crypto_LDADD = libbrandt.la -lgcrypt -lgpg-error -lgnunetutil
23 24
25test_brandt_SOURCES = test_brandt.c
26test_brandt_LDADD = libbrandt.la -lgcrypt -lgpg-error -lgnunetutil
27
24TESTS = $(check_PROGRAMS) 28TESTS = $(check_PROGRAMS)
diff --git a/brandt.c b/brandt.c
index 1af19b9..03337c4 100644
--- a/brandt.c
+++ b/brandt.c
@@ -20,7 +20,8 @@
20 * @author Markus Teich 20 * @author Markus Teich
21 */ 21 */
22 22
23#include "brandt_config.h" 23#include "platform.h"
24
24#include "crypto.h" 25#include "crypto.h"
25#include "internals.h" 26#include "internals.h"
26#include "util.h" 27#include "util.h"
@@ -52,7 +53,7 @@ BRANDT_init (struct GNUNET_CRYPTO_EccDlogContext *dlogctx)
52static void 53static void
53start_auction (void *arg) 54start_auction (void *arg)
54{ 55{
55 struct BRANDT_Auction *ad = (struct BRANDT_Auction *)arg; 56// struct BRANDT_Auction *ad = (struct BRANDT_Auction *)arg;
56 57
57 /* \todo: broadcast start message to all participants */ 58 /* \todo: broadcast start message to all participants */
58} 59}
@@ -64,18 +65,18 @@ BRANDT_new (BRANDT_CbBroadcast broadcast,
64 void *auction_closure, 65 void *auction_closure,
65 void **auction_desc, 66 void **auction_desc,
66 size_t *auction_desc_len, 67 size_t *auction_desc_len,
68 const void *description,
69 uint32_t description_len,
67 struct GNUNET_TIME_Absolute time_start, 70 struct GNUNET_TIME_Absolute time_start,
68 struct GNUNET_TIME_Relative time_round, 71 struct GNUNET_TIME_Relative time_round,
69 void *description,
70 uint32_t description_len,
71 uint16_t num_prices, 72 uint16_t num_prices,
72 uint16_t m, 73 uint16_t m,
73 int outcome_public) 74 int outcome_public)
74{ 75{
75 struct BRANDT_Auction *ret = GNUNET_new (struct BRANDT_Auction); 76 struct BRANDT_Auction *ret = GNUNET_new (struct BRANDT_Auction);
76 struct BRANDT_DescrP *desc = GNUNET_new (struct BRANDT_DescrP); 77 struct BRANDT_DescrP *desc = GNUNET_new (struct BRANDT_DescrP);
77 struct GNUNET_TIME_Relative until_start;
78 struct GNUNET_HashContext *hc = GNUNET_CRYPTO_hash_context_start (); 78 struct GNUNET_HashContext *hc = GNUNET_CRYPTO_hash_context_start ();
79 struct GNUNET_TIME_Relative until_start;
79 80
80 desc->time_start = GNUNET_TIME_absolute_hton (time_start); 81 desc->time_start = GNUNET_TIME_absolute_hton (time_start);
81 desc->time_round = GNUNET_TIME_relative_hton (time_round); 82 desc->time_round = GNUNET_TIME_relative_hton (time_round);
@@ -220,7 +221,22 @@ BRANDT_join (BRANDT_CbBroadcast broadcast,
220void 221void
221BRANDT_destroy (struct BRANDT_Auction *auction) 222BRANDT_destroy (struct BRANDT_Auction *auction)
222{ 223{
223 GNUNET_SCHEDULER_cancel (auction->task); 224 if (auction->task)
225 GNUNET_SCHEDULER_cancel (auction->task);
226 gcry_mpi_release (auction->round_progress);
227 gcry_mpi_release (auction->x);
228 smc_free1 (auction->y, auction->n);
229 gcry_mpi_point_release (auction->Y);
230 smc_free2 (auction->alpha, auction->n, auction->k);
231 smc_free2 (auction->beta, auction->n, auction->k);
232 smc_free2 (auction->gamma2, auction->n, auction->k);
233 smc_free3 (auction->gamma3, auction->n, auction->n, auction->k);
234 smc_free2 (auction->delta2, auction->n, auction->k);
235 smc_free3 (auction->delta3, auction->n, auction->n, auction->k);
236 smc_free2 (auction->phi2, auction->n, auction->k);
237 smc_free3 (auction->phi3, auction->n, auction->n, auction->k);
238 smc_free1 (auction->tmpa1, auction->k);
239 smc_free1 (auction->tmpb1, auction->k);
224} 240}
225 241
226 242
diff --git a/brandt.h b/brandt.h
index ad98663..dad324a 100644
--- a/brandt.h
+++ b/brandt.h
@@ -187,10 +187,10 @@ BRANDT_new (BRANDT_CbBroadcast broadcast,
187 void *auction_closure, 187 void *auction_closure,
188 void **auction_desc, 188 void **auction_desc,
189 size_t *auction_desc_len, 189 size_t *auction_desc_len,
190 const void *description,
191 uint32_t description_len,
190 struct GNUNET_TIME_Absolute time_start, 192 struct GNUNET_TIME_Absolute time_start,
191 struct GNUNET_TIME_Relative time_round, 193 struct GNUNET_TIME_Relative time_round,
192 void *description,
193 uint32_t description_len,
194 uint16_t num_prices, 194 uint16_t num_prices,
195 uint16_t m, 195 uint16_t m,
196 int outcome_public); 196 int outcome_public);
diff --git a/configure.ac b/configure.ac
index 8c0ba72..a15859a 100644
--- a/configure.ac
+++ b/configure.ac
@@ -22,8 +22,13 @@ CC=$(echo "${CC}" | sed 's/-std=gnu99/-std=c99/')
22CPP=$(echo "${CPP}" | sed 's/-std=gnu99/-std=c99/') 22CPP=$(echo "${CPP}" | sed 's/-std=gnu99/-std=c99/')
23 23
24# Checks for typedefs, structures, and compiler characteristics. 24# Checks for typedefs, structures, and compiler characteristics.
25AC_TYPE_PID_T
25AC_TYPE_SIZE_T 26AC_TYPE_SIZE_T
26AC_TYPE_UINT16_T 27AC_TYPE_UINT16_T
28AC_TYPE_UINT32_T
29AC_TYPE_UINT64_T
30AC_TYPE_INTMAX_T
31AC_TYPE_UINTMAX_T
27 32
28# Checks for libraries. 33# Checks for libraries.
29AC_SEARCH_LIBS([gcry_check_version], [gcrypt], [], [AC_MSG_ERROR([unable to find the gcry_check_version() function from libgcrypt])]) 34AC_SEARCH_LIBS([gcry_check_version], [gcrypt], [], [AC_MSG_ERROR([unable to find the gcry_check_version() function from libgcrypt])])
@@ -105,16 +110,6 @@ AC_ARG_ENABLE(linker-hardening,
105 LDFLAGS="$LDFLAGS -z relro -z now" 110 LDFLAGS="$LDFLAGS -z relro -z now"
106fi]) 111fi])
107 112
108# Checks for typedefs, structures, and compiler characteristics.
109AC_TYPE_PID_T
110AC_TYPE_SIZE_T
111AC_TYPE_UINT16_T
112AC_TYPE_UINT32_T
113AC_TYPE_UINT64_T
114AC_TYPE_INTMAX_T
115AC_TYPE_UINTMAX_T
116
117
118AC_CONFIG_FILES([ 113AC_CONFIG_FILES([
119Makefile 114Makefile
120doc/Makefile 115doc/Makefile
diff --git a/crypto.c b/crypto.c
index 4b6419a..64d4920 100644
--- a/crypto.c
+++ b/crypto.c
@@ -20,15 +20,15 @@
20 * @author Markus Teich 20 * @author Markus Teich
21 */ 21 */
22 22
23#include "brandt_config.h" 23#include "platform.h"
24 24
25#include <arpa/inet.h>
26#include <gcrypt.h> 25#include <gcrypt.h>
27 26
28#include "crypto.h" 27#include "crypto.h"
29#include "internals.h" 28#include "internals.h"
30#include "util.h" 29#include "util.h"
31 30
31
32#define CURVE "Ed25519" 32#define CURVE "Ed25519"
33 33
34 34
@@ -377,7 +377,7 @@ ec_point_parse (gcry_mpi_point_t dst, const struct ec_mpi *src)
377 * @param[in,out] dst The 1 dimensional array to clean up 377 * @param[in,out] dst The 1 dimensional array to clean up
378 * @param[in] size1 size of the first dimension 378 * @param[in] size1 size of the first dimension
379 */ 379 */
380static void 380void
381smc_free1 (gcry_mpi_point_t *dst, uint16_t size1) 381smc_free1 (gcry_mpi_point_t *dst, uint16_t size1)
382{ 382{
383 if (NULL == dst) 383 if (NULL == dst)
@@ -399,7 +399,7 @@ smc_free1 (gcry_mpi_point_t *dst, uint16_t size1)
399 * @return a pointer to the array or NULL on error. 399 * @return a pointer to the array or NULL on error.
400 * If not used anymore use smc_free2 to reclaim the memory. 400 * If not used anymore use smc_free2 to reclaim the memory.
401 */ 401 */
402static gcry_mpi_point_t * 402gcry_mpi_point_t *
403smc_init1 (uint16_t size1) 403smc_init1 (uint16_t size1)
404{ 404{
405 gcry_mpi_point_t *ret; 405 gcry_mpi_point_t *ret;
@@ -427,7 +427,7 @@ smc_init1 (uint16_t size1)
427 * @param[in] size1 size of the first dimension 427 * @param[in] size1 size of the first dimension
428 * @param[in] size2 size of the second dimension 428 * @param[in] size2 size of the second dimension
429 */ 429 */
430static void 430void
431smc_free2 (gcry_mpi_point_t **dst, uint16_t size1, uint16_t size2) 431smc_free2 (gcry_mpi_point_t **dst, uint16_t size1, uint16_t size2)
432{ 432{
433 if (NULL == dst) 433 if (NULL == dst)
@@ -451,7 +451,7 @@ smc_free2 (gcry_mpi_point_t **dst, uint16_t size1, uint16_t size2)
451 * @return a pointer to the array or NULL on error. 451 * @return a pointer to the array or NULL on error.
452 * If not used anymore use smc_free2 to reclaim the memory. 452 * If not used anymore use smc_free2 to reclaim the memory.
453 */ 453 */
454static gcry_mpi_point_t ** 454gcry_mpi_point_t **
455smc_init2 (uint16_t size1, uint16_t size2) 455smc_init2 (uint16_t size1, uint16_t size2)
456{ 456{
457 gcry_mpi_point_t **ret; 457 gcry_mpi_point_t **ret;
@@ -490,7 +490,7 @@ smc_init2 (uint16_t size1, uint16_t size2)
490 * @param[in] size2 size of the second dimension 490 * @param[in] size2 size of the second dimension
491 * @param[in] size3 size of the third dimension 491 * @param[in] size3 size of the third dimension
492 */ 492 */
493static void 493void
494smc_free3 (gcry_mpi_point_t ***dst, 494smc_free3 (gcry_mpi_point_t ***dst,
495 uint16_t size1, 495 uint16_t size1,
496 uint16_t size2, 496 uint16_t size2,
@@ -519,7 +519,7 @@ smc_free3 (gcry_mpi_point_t ***dst,
519 * @return a pointer to the array or NULL on error. 519 * @return a pointer to the array or NULL on error.
520 * If not used anymore use smc_free3 to reclaim the memory. 520 * If not used anymore use smc_free3 to reclaim the memory.
521 */ 521 */
522static gcry_mpi_point_t *** 522gcry_mpi_point_t ***
523smc_init3 (uint16_t size1, uint16_t size2, uint16_t size3) 523smc_init3 (uint16_t size1, uint16_t size2, uint16_t size3)
524{ 524{
525 gcry_mpi_point_t ***ret; 525 gcry_mpi_point_t ***ret;
diff --git a/crypto.h b/crypto.h
index ebdcd61..9cb5405 100644
--- a/crypto.h
+++ b/crypto.h
@@ -26,7 +26,6 @@
26#include <gcrypt.h> 26#include <gcrypt.h>
27#include <stdint.h> 27#include <stdint.h>
28 28
29#include "platform.h"
30#include <gnunet/gnunet_util_lib.h> 29#include <gnunet/gnunet_util_lib.h>
31 30
32#include "internals.h" 31#include "internals.h"
@@ -42,6 +41,16 @@ struct ec_mpi {
42 unsigned char data[256 / 8]; 41 unsigned char data[256 / 8];
43}; 42};
44 43
44gcry_mpi_point_t *smc_init1 (uint16_t size1);
45gcry_mpi_point_t **smc_init2 (uint16_t size1, uint16_t size2);
46gcry_mpi_point_t ***smc_init3 (uint16_t size1, uint16_t size2, uint16_t size3);
47void smc_free1 (gcry_mpi_point_t *dst, uint16_t size1);
48void smc_free2 (gcry_mpi_point_t **dst, uint16_t size1, uint16_t size2);
49void smc_free3 (gcry_mpi_point_t ***dst,
50 uint16_t size1,
51 uint16_t size2,
52 uint16_t size3);
53
45void ec_point_copy (gcry_mpi_point_t dst, const gcry_mpi_point_t src); 54void ec_point_copy (gcry_mpi_point_t dst, const gcry_mpi_point_t src);
46int ec_point_cmp (const gcry_mpi_point_t a, const gcry_mpi_point_t b); 55int ec_point_cmp (const gcry_mpi_point_t a, const gcry_mpi_point_t b);
47void ec_skey_create (gcry_mpi_t skey); 56void ec_skey_create (gcry_mpi_t skey);
diff --git a/platform.h b/platform.h
index 8a1b305..e47c28c 100644
--- a/platform.h
+++ b/platform.h
@@ -1,24 +1,25 @@
1/* 1/* This file is part of libbrandt.
2 This file is part of TALER 2 * Copyright (C) 2016 GNUnet e.V.
3 Copyright (C) 2014 Chrisitan Grothoff (and other contributing authors) 3 *
4 4 * libbrandt is free software: you can redistribute it and/or modify it under
5 TALER is free software; you can redistribute it and/or modify it under the 5 * the terms of the GNU General Public License as published by the Free Software
6 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 Foundation; either version 3, or (at your option) any later version. 7 * version.
8 8 *
9 TALER is distributed in the hope that it will be useful, but WITHOUT ANY 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 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. 11 * A PARTICULAR PURPOSE. See the GNU General Public License for more details.
12 12 *
13 You should have received a copy of the GNU General Public License along with 13 * You should have received a copy of the GNU General Public License along with
14 TALER; see the file COPYING. If not, If not, see <http://www.gnu.org/licenses/> 14 * libbrandt. If not, see <http://www.gnu.org/licenses/>.
15*/ 15 */
16 16
17/** 17/**
18 * @file platform.h 18 * @file platform.h
19 * @brief This file contains the includes and definitions which are used by the 19 * @brief This file was adapted from TALER and contains some magic
20 * rest of the modules 20 * configuration. It should be included in every compilation as the first
21 * @author Sree Harsha Totakura <sreeharsha@totakura.in> 21 * include directive, since it sets up defines which are used in other includes.
22 * @author Markus Teich
22 */ 23 */
23 24
24#ifndef PLATFORM_H_ 25#ifndef PLATFORM_H_
@@ -29,11 +30,8 @@
29# define HAVE_USED_CONFIG_H 30# define HAVE_USED_CONFIG_H
30# ifdef HAVE_CONFIG_H 31# ifdef HAVE_CONFIG_H
31# include "brandt_config.h" 32# include "brandt_config.h"
32# endif 33# endif /* ifdef HAVE_CONFIG_H */
33#endif 34#endif /* ifndef HAVE_USED_CONFIG_H */
34
35/* Include the features available for GNU source */
36#define _GNU_SOURCE
37 35
38/* Include GNUnet's platform file */ 36/* Include GNUnet's platform file */
39#include <gnunet/platform.h> 37#include <gnunet/platform.h>
diff --git a/test_brandt.c b/test_brandt.c
new file mode 100644
index 0000000..d61700b
--- /dev/null
+++ b/test_brandt.c
@@ -0,0 +1,124 @@
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 test_brandt.c
19 * @brief testing API functions.
20 * @author Markus Teich
21 */
22
23#include "platform.h"
24
25#include <gnunet/gnunet_util_lib.h>
26
27#include "brandt.h"
28#include "crypto.h"
29#include "test.h"
30#include "util.h"
31
32
33static void
34run_new_join (void *arg)
35{
36 int *ret = arg;
37 const char description[] = "test description for test_new_join";
38 struct BRANDT_Auction *ad_seller;
39 struct BRANDT_Auction *ad_bidder;
40 void *desc;
41 size_t desc_len;
42
43 ad_seller = BRANDT_new (NULL,
44 NULL,
45 NULL,
46 &desc,
47 &desc_len,
48 description,
49 sizeof (description),
50 GNUNET_TIME_absolute_get (),
51 GNUNET_TIME_UNIT_MINUTES,
52 8,
53 0,
54 1);
55 if (!ad_seller)
56 {
57 weprintf ("BRANDT_new() failed.");
58 *ret = 0;
59 return;
60 }
61
62
63 ad_bidder = BRANDT_join (NULL,
64 NULL,
65 NULL,
66 NULL,
67 desc,
68 desc_len,
69 description,
70 sizeof (description));
71 if (!ad_bidder)
72 {
73 weprintf ("BRANDT_join() failed.");
74 *ret = 0;
75 return;
76 }
77
78 BRANDT_destroy (ad_seller);
79 BRANDT_destroy (ad_bidder);
80
81 *ret = 1;
82}
83
84
85static int
86test_new_join ()
87{
88 int ret = 0;
89
90 GNUNET_SCHEDULER_run (&run_new_join, &ret);
91 return ret;
92}
93
94
95/*
96 static void
97 cleanup_auction_data ()
98 {
99 for (uint16_t i = 0; i < bidders; i++)
100 {
101 }
102 free (ad);
103 }
104 */
105
106
107int
108main (int argc, char *argv[])
109{
110 int repeat = 1;
111 struct GNUNET_CRYPTO_EccDlogContext *edc;
112
113 edc = GNUNET_CRYPTO_ecc_dlog_prepare (1024, 16);
114 BRANDT_init (edc);
115
116 RUN (test_new_join);
117
118 for (tests_run = 0; tests_run < repeat; tests_run++)
119 {
120 }
121
122 GNUNET_CRYPTO_ecc_dlog_release (edc);
123 return ret;
124}
diff --git a/test_crypto.c b/test_crypto.c
index d30f19d..2d1eb30 100644
--- a/test_crypto.c
+++ b/test_crypto.c
@@ -20,13 +20,11 @@
20 * @author Markus Teich 20 * @author Markus Teich
21 */ 21 */
22 22
23#include "brandt_config.h" 23#include "platform.h"
24 24
25/* For testing static functions and variables we include the whole source */ 25/* For testing static functions and variables we include the whole source */
26#include "crypto.c" 26#include "crypto.c"
27 27
28#include "brandt.h"
29#include "crypto.h"
30#include "test.h" 28#include "test.h"
31 29
32 30
@@ -198,6 +196,7 @@ test_setup_auction_data ()
198 return 1; 196 return 1;
199} 197}
200 198
199
201/* 200/*
202 */ 201 */
203#define ROUND(type, oc, index) do { \ 202#define ROUND(type, oc, index) do { \