From fe7b13889217f4268d87d3712cb9ffe265e6a4e2 Mon Sep 17 00:00:00 2001 From: Markus Teich Date: Tue, 16 Aug 2016 20:58:20 +0200 Subject: [PATCH] some stuff - finish BRANDT_destroy() - fix include mess related to platform.h and brandt_config.h - add first brandt.c testcase --- Makefile.am | 6 ++- brandt.c | 28 +++++++++--- brandt.h | 4 +- configure.ac | 15 ++---- crypto.c | 16 +++---- crypto.h | 11 ++++- platform.h | 44 +++++++++--------- test_brandt.c | 124 ++++++++++++++++++++++++++++++++++++++++++++++++++ test_crypto.c | 5 +- 9 files changed, 199 insertions(+), 54 deletions(-) create mode 100644 test_brandt.c 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 = \ -version-info 0:0:0 check_PROGRAMS = \ - test_crypto + test_crypto \ + test_brandt test_crypto_SOURCES = test_crypto.c test_crypto_LDADD = libbrandt.la -lgcrypt -lgpg-error -lgnunetutil +test_brandt_SOURCES = test_brandt.c +test_brandt_LDADD = libbrandt.la -lgcrypt -lgpg-error -lgnunetutil + TESTS = $(check_PROGRAMS) diff --git a/brandt.c b/brandt.c index 1af19b9..03337c4 100644 --- a/brandt.c +++ b/brandt.c @@ -20,7 +20,8 @@ * @author Markus Teich */ -#include "brandt_config.h" +#include "platform.h" + #include "crypto.h" #include "internals.h" #include "util.h" @@ -52,7 +53,7 @@ BRANDT_init (struct GNUNET_CRYPTO_EccDlogContext *dlogctx) static void start_auction (void *arg) { - struct BRANDT_Auction *ad = (struct BRANDT_Auction *)arg; +// struct BRANDT_Auction *ad = (struct BRANDT_Auction *)arg; /* \todo: broadcast start message to all participants */ } @@ -64,18 +65,18 @@ BRANDT_new (BRANDT_CbBroadcast broadcast, void *auction_closure, void **auction_desc, size_t *auction_desc_len, + const void *description, + uint32_t description_len, struct GNUNET_TIME_Absolute time_start, struct GNUNET_TIME_Relative time_round, - void *description, - uint32_t description_len, uint16_t num_prices, uint16_t m, int outcome_public) { struct BRANDT_Auction *ret = GNUNET_new (struct BRANDT_Auction); struct BRANDT_DescrP *desc = GNUNET_new (struct BRANDT_DescrP); - struct GNUNET_TIME_Relative until_start; struct GNUNET_HashContext *hc = GNUNET_CRYPTO_hash_context_start (); + struct GNUNET_TIME_Relative until_start; desc->time_start = GNUNET_TIME_absolute_hton (time_start); desc->time_round = GNUNET_TIME_relative_hton (time_round); @@ -220,7 +221,22 @@ BRANDT_join (BRANDT_CbBroadcast broadcast, void BRANDT_destroy (struct BRANDT_Auction *auction) { - GNUNET_SCHEDULER_cancel (auction->task); + if (auction->task) + GNUNET_SCHEDULER_cancel (auction->task); + gcry_mpi_release (auction->round_progress); + gcry_mpi_release (auction->x); + smc_free1 (auction->y, auction->n); + gcry_mpi_point_release (auction->Y); + smc_free2 (auction->alpha, auction->n, auction->k); + smc_free2 (auction->beta, auction->n, auction->k); + smc_free2 (auction->gamma2, auction->n, auction->k); + smc_free3 (auction->gamma3, auction->n, auction->n, auction->k); + smc_free2 (auction->delta2, auction->n, auction->k); + smc_free3 (auction->delta3, auction->n, auction->n, auction->k); + smc_free2 (auction->phi2, auction->n, auction->k); + smc_free3 (auction->phi3, auction->n, auction->n, auction->k); + smc_free1 (auction->tmpa1, auction->k); + smc_free1 (auction->tmpb1, auction->k); } 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, void *auction_closure, void **auction_desc, size_t *auction_desc_len, + const void *description, + uint32_t description_len, struct GNUNET_TIME_Absolute time_start, struct GNUNET_TIME_Relative time_round, - void *description, - uint32_t description_len, uint16_t num_prices, uint16_t m, 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/') CPP=$(echo "${CPP}" | sed 's/-std=gnu99/-std=c99/') # Checks for typedefs, structures, and compiler characteristics. +AC_TYPE_PID_T AC_TYPE_SIZE_T AC_TYPE_UINT16_T +AC_TYPE_UINT32_T +AC_TYPE_UINT64_T +AC_TYPE_INTMAX_T +AC_TYPE_UINTMAX_T # Checks for libraries. AC_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, LDFLAGS="$LDFLAGS -z relro -z now" fi]) -# Checks for typedefs, structures, and compiler characteristics. -AC_TYPE_PID_T -AC_TYPE_SIZE_T -AC_TYPE_UINT16_T -AC_TYPE_UINT32_T -AC_TYPE_UINT64_T -AC_TYPE_INTMAX_T -AC_TYPE_UINTMAX_T - - AC_CONFIG_FILES([ Makefile doc/Makefile diff --git a/crypto.c b/crypto.c index 4b6419a..64d4920 100644 --- a/crypto.c +++ b/crypto.c @@ -20,15 +20,15 @@ * @author Markus Teich */ -#include "brandt_config.h" +#include "platform.h" -#include #include #include "crypto.h" #include "internals.h" #include "util.h" + #define CURVE "Ed25519" @@ -377,7 +377,7 @@ ec_point_parse (gcry_mpi_point_t dst, const struct ec_mpi *src) * @param[in,out] dst The 1 dimensional array to clean up * @param[in] size1 size of the first dimension */ -static void +void smc_free1 (gcry_mpi_point_t *dst, uint16_t size1) { if (NULL == dst) @@ -399,7 +399,7 @@ smc_free1 (gcry_mpi_point_t *dst, uint16_t size1) * @return a pointer to the array or NULL on error. * If not used anymore use smc_free2 to reclaim the memory. */ -static gcry_mpi_point_t * +gcry_mpi_point_t * smc_init1 (uint16_t size1) { gcry_mpi_point_t *ret; @@ -427,7 +427,7 @@ smc_init1 (uint16_t size1) * @param[in] size1 size of the first dimension * @param[in] size2 size of the second dimension */ -static void +void smc_free2 (gcry_mpi_point_t **dst, uint16_t size1, uint16_t size2) { if (NULL == dst) @@ -451,7 +451,7 @@ smc_free2 (gcry_mpi_point_t **dst, uint16_t size1, uint16_t size2) * @return a pointer to the array or NULL on error. * If not used anymore use smc_free2 to reclaim the memory. */ -static gcry_mpi_point_t ** +gcry_mpi_point_t ** smc_init2 (uint16_t size1, uint16_t size2) { gcry_mpi_point_t **ret; @@ -490,7 +490,7 @@ smc_init2 (uint16_t size1, uint16_t size2) * @param[in] size2 size of the second dimension * @param[in] size3 size of the third dimension */ -static void +void smc_free3 (gcry_mpi_point_t ***dst, uint16_t size1, uint16_t size2, @@ -519,7 +519,7 @@ smc_free3 (gcry_mpi_point_t ***dst, * @return a pointer to the array or NULL on error. * If not used anymore use smc_free3 to reclaim the memory. */ -static gcry_mpi_point_t *** +gcry_mpi_point_t *** smc_init3 (uint16_t size1, uint16_t size2, uint16_t size3) { 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 @@ #include #include -#include "platform.h" #include #include "internals.h" @@ -42,6 +41,16 @@ struct ec_mpi { unsigned char data[256 / 8]; }; +gcry_mpi_point_t *smc_init1 (uint16_t size1); +gcry_mpi_point_t **smc_init2 (uint16_t size1, uint16_t size2); +gcry_mpi_point_t ***smc_init3 (uint16_t size1, uint16_t size2, uint16_t size3); +void smc_free1 (gcry_mpi_point_t *dst, uint16_t size1); +void smc_free2 (gcry_mpi_point_t **dst, uint16_t size1, uint16_t size2); +void smc_free3 (gcry_mpi_point_t ***dst, + uint16_t size1, + uint16_t size2, + uint16_t size3); + void ec_point_copy (gcry_mpi_point_t dst, const gcry_mpi_point_t src); int ec_point_cmp (const gcry_mpi_point_t a, const gcry_mpi_point_t b); void 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 @@ -/* - This file is part of TALER - Copyright (C) 2014 Chrisitan Grothoff (and other contributing authors) - - TALER is free software; you can redistribute it and/or modify it under the - terms of the GNU General Public License as published by the Free Software - Foundation; either version 3, or (at your option) any later version. - - TALER is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR - A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along with - TALER; see the file COPYING. If not, If not, see -*/ +/* This file is part of libbrandt. + * Copyright (C) 2016 GNUnet e.V. + * + * libbrandt is free software: you can redistribute it and/or modify it under + * the terms of the GNU General Public License as published by the Free Software + * Foundation, either version 3 of the License, or (at your option) any later + * version. + * + * libbrandt is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + * A PARTICULAR PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with + * libbrandt. If not, see . + */ /** * @file platform.h - * @brief This file contains the includes and definitions which are used by the - * rest of the modules - * @author Sree Harsha Totakura + * @brief This file was adapted from TALER and contains some magic + * configuration. It should be included in every compilation as the first + * include directive, since it sets up defines which are used in other includes. + * @author Markus Teich */ #ifndef PLATFORM_H_ @@ -29,11 +30,8 @@ # define HAVE_USED_CONFIG_H # ifdef HAVE_CONFIG_H # include "brandt_config.h" -# endif -#endif - -/* Include the features available for GNU source */ -#define _GNU_SOURCE +# endif /* ifdef HAVE_CONFIG_H */ +#endif /* ifndef HAVE_USED_CONFIG_H */ /* Include GNUnet's platform file */ #include 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 @@ +/* This file is part of libbrandt. + * Copyright (C) 2016 GNUnet e.V. + * + * libbrandt is free software: you can redistribute it and/or modify it under + * the terms of the GNU General Public License as published by the Free Software + * Foundation, either version 3 of the License, or (at your option) any later + * version. + * + * libbrandt is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + * A PARTICULAR PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with + * libbrandt. If not, see . + */ + +/** + * @file test_brandt.c + * @brief testing API functions. + * @author Markus Teich + */ + +#include "platform.h" + +#include + +#include "brandt.h" +#include "crypto.h" +#include "test.h" +#include "util.h" + + +static void +run_new_join (void *arg) +{ + int *ret = arg; + const char description[] = "test description for test_new_join"; + struct BRANDT_Auction *ad_seller; + struct BRANDT_Auction *ad_bidder; + void *desc; + size_t desc_len; + + ad_seller = BRANDT_new (NULL, + NULL, + NULL, + &desc, + &desc_len, + description, + sizeof (description), + GNUNET_TIME_absolute_get (), + GNUNET_TIME_UNIT_MINUTES, + 8, + 0, + 1); + if (!ad_seller) + { + weprintf ("BRANDT_new() failed."); + *ret = 0; + return; + } + + + ad_bidder = BRANDT_join (NULL, + NULL, + NULL, + NULL, + desc, + desc_len, + description, + sizeof (description)); + if (!ad_bidder) + { + weprintf ("BRANDT_join() failed."); + *ret = 0; + return; + } + + BRANDT_destroy (ad_seller); + BRANDT_destroy (ad_bidder); + + *ret = 1; +} + + +static int +test_new_join () +{ + int ret = 0; + + GNUNET_SCHEDULER_run (&run_new_join, &ret); + return ret; +} + + +/* + static void + cleanup_auction_data () + { + for (uint16_t i = 0; i < bidders; i++) + { + } + free (ad); + } + */ + + +int +main (int argc, char *argv[]) +{ + int repeat = 1; + struct GNUNET_CRYPTO_EccDlogContext *edc; + + edc = GNUNET_CRYPTO_ecc_dlog_prepare (1024, 16); + BRANDT_init (edc); + + RUN (test_new_join); + + for (tests_run = 0; tests_run < repeat; tests_run++) + { + } + + GNUNET_CRYPTO_ecc_dlog_release (edc); + return ret; +} 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 @@ * @author Markus Teich */ -#include "brandt_config.h" +#include "platform.h" /* For testing static functions and variables we include the whole source */ #include "crypto.c" -#include "brandt.h" -#include "crypto.h" #include "test.h" @@ -198,6 +196,7 @@ test_setup_auction_data () return 1; } + /* */ #define ROUND(type, oc, index) do { \