From 2b70eeaf2bce2c777198d91c5a8357c2426540a0 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Mon, 28 Sep 2015 13:22:21 +0000 Subject: [PATCH] add ecc dlog benchmark --- src/util/Makefile.am | 7 ++ src/util/perf_crypto_ecc_dlog.c | 173 ++++++++++++++++++++++++++++++++ 2 files changed, 180 insertions(+) create mode 100644 src/util/perf_crypto_ecc_dlog.c diff --git a/src/util/Makefile.am b/src/util/Makefile.am index 90a0717ab..896ef17eb 100644 --- a/src/util/Makefile.am +++ b/src/util/Makefile.am @@ -248,6 +248,7 @@ libgnunet_plugin_test_la_LDFLAGS = \ if HAVE_BENCHMARKS BENCHMARKS = \ perf_crypto_hash \ + perf_crypto_ecc_dlog \ perf_crypto_rsa \ perf_crypto_paillier \ perf_crypto_symmetric \ @@ -627,6 +628,12 @@ perf_crypto_hash_SOURCES = \ perf_crypto_hash_LDADD = \ libgnunetutil.la +perf_crypto_ecc_dlog_SOURCES = \ + perf_crypto_ecc_dlog.c +perf_crypto_ecc_dlog_LDADD = \ + libgnunetutil.la \ + -lgcrypt + perf_crypto_rsa_SOURCES = \ perf_crypto_rsa.c perf_crypto_rsa_LDADD = \ diff --git a/src/util/perf_crypto_ecc_dlog.c b/src/util/perf_crypto_ecc_dlog.c new file mode 100644 index 000000000..ad83e1fbc --- /dev/null +++ b/src/util/perf_crypto_ecc_dlog.c @@ -0,0 +1,173 @@ +/* + This file is part of GNUnet. + Copyright (C) 2015 Christian Grothoff (and other contributing authors) + + GNUnet 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. + + GNUnet 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 GNUnet; see the file COPYING. If not, write to the + Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. + +*/ +/** + * @file util/perf_crypto_ecc_dlog.c + * @brief benchmark for ECC DLOG calculation + * @author Christian Grothoff + */ +#include "platform.h" +#include "gnunet_util_lib.h" +#include +#include + + +/** + * Name of the curve we are using. Note that we have hard-coded + * structs that use 256 bits, so using a bigger curve will require + * changes that break stuff badly. The name of the curve given here + * must be agreed by all peers and be supported by libgcrypt. + */ +#define CURVE "Ed25519" + +/** + * Maximum value we benchmark dlog for. + */ +#define MAX_FACT (1024 * 1024) + +/** + * Maximum memory to use, sqrt(MAX_FACT) is a good choice. + */ +#define MAX_MEM 1024 + +/** + * How many values do we test? + */ +#define TEST_ITER 10 + +/** + * Range of values to use for MATH tests. + */ +#define MATH_MAX 500000 + + +/** + * Do some DLOG operations for testing. + * + * @param edc context for ECC operations + * @param do_dlog #GNUNET_YES if we want to actually do the bencharked operation + */ +static void +test_dlog (struct GNUNET_CRYPTO_EccDlogContext *edc, + int do_dlog) +{ + gcry_mpi_t fact; + gcry_mpi_t n; + gcry_ctx_t ctx; + gcry_mpi_point_t q; + gcry_mpi_point_t g; + unsigned int i; + int x; + int iret; + + GNUNET_assert (0 == gcry_mpi_ec_new (&ctx, NULL, CURVE)); + g = gcry_mpi_ec_get_point ("g", ctx, 0); + GNUNET_assert (NULL != g); + n = gcry_mpi_ec_get_mpi ("n", ctx, 0); + q = gcry_mpi_point_new (0); + fact = gcry_mpi_new (0); + for (i=0;i