From af99085b7163fdded4dfad94fd2a98231bc12209 Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Sat, 18 Aug 2018 15:10:39 +0200 Subject: benchmark collection awk scripts --- contrib/benchmark/collect_ops.awk | 45 +++++++++++++++++++++++++++++ contrib/benchmark/collect_urls.awk | 47 ++++++++++++++++++++++++++++++ src/util/benchmark.c | 59 +++++++++++++++++++++++++++++++++----- src/util/benchmark.h | 59 ++++++++++++++++++++++++++++++++------ src/util/crypto_ecc.c | 59 +++++++++++++++++++++++++++++++++++--- src/util/crypto_hash.c | 13 +++++++++ src/util/crypto_hkdf.c | 4 +++ src/util/crypto_rsa.c | 21 ++++++++++++++ 8 files changed, 287 insertions(+), 20 deletions(-) create mode 100644 contrib/benchmark/collect_ops.awk create mode 100644 contrib/benchmark/collect_urls.awk diff --git a/contrib/benchmark/collect_ops.awk b/contrib/benchmark/collect_ops.awk new file mode 100644 index 000000000..b34fcc723 --- /dev/null +++ b/contrib/benchmark/collect_ops.awk @@ -0,0 +1,45 @@ +# This file is part of GNUnet +# Copyright (C) 2018 GNUnet e.V. +# +# GNUnet is free software: you can redistribute it and/or modify it +# under the terms of the GNU Affero General Public License as published +# by the Free Software Foundation, either version 3 of the License, 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 +# Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . + + +# Aggregate benchmarking data from multiple threads/processes +# generated by util/benchmark.c. +# +# Can be used as +# awk -f collect_ops.awk gnunet-benchmark-ops-*.txt + + +# records are of the following form: +# op count time_us +{ + op[$2]["count"] += $4; + op[$2]["time_us"] += $6; +} + +function avg(s, c) { + if (c == 0) { + return 0; + } else { + return s / c; + } +} + +END { + for (x in op) { + print "op", x, "count", op[x]["count"], "time_us", op[x]["time_us"], \ + "time_avg_us", avg(op[x]["time_us"], op[x]["count"]); + } +} diff --git a/contrib/benchmark/collect_urls.awk b/contrib/benchmark/collect_urls.awk new file mode 100644 index 000000000..27424b2b8 --- /dev/null +++ b/contrib/benchmark/collect_urls.awk @@ -0,0 +1,47 @@ +# records are of the following form: +# This file is part of GNUnet +# Copyright (C) 2018 GNUnet e.V. +# +# GNUnet is free software: you can redistribute it and/or modify it +# under the terms of the GNU Affero General Public License as published +# by the Free Software Foundation, either version 3 of the License, 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 +# Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . + + +# Aggregate benchmarking data from multiple threads/processes +# generated by util/benchmark.c. +# +# Can be used as +# awk -f collect_ops.awk gnunet-benchmark-ops-*.txt +# url status count time_us + +{ + url[$2][$4]["count"] += $6; + url[$2][$4]["time_us"] += $8; +} + +function avg(s, c) { + if (c == 0) { + return 0; + } else { + return s / c; + } +} + +END { + for (x in url) { + for (y in url[x]) { + print "url", x, "status", y, \ + "count", url[x][y]["count"], "time_us", url[x][y]["time_us"], \ + "time_avg_us", avg(url[x][y]["time_us"], url[x][y]["count"]); + } + } +} diff --git a/src/util/benchmark.c b/src/util/benchmark.c index daed7cd2b..f832931ee 100644 --- a/src/util/benchmark.c +++ b/src/util/benchmark.c @@ -50,9 +50,22 @@ write_benchmark_data (struct BenchmarkData *bd) struct GNUNET_DISK_FileHandle *fh; pid_t pid = getpid (); pid_t tid = syscall (SYS_gettid); + char *benchmark_dir; char *s; - GNUNET_asprintf (&s, "gnunet-benchmark-%llu-%llu.txt", + benchmark_dir = getenv ("GNUNET_BENCHMARK_DIR"); + + if (NULL == benchmark_dir) + return; + + if (GNUNET_OK != GNUNET_DISK_directory_create (benchmark_dir)) + { + GNUNET_break (0); + return; + } + + GNUNET_asprintf (&s, "%s/gnunet-benchmark-ops-%llu-%llu.txt", + benchmark_dir, (unsigned long long) pid, (unsigned long long) tid); @@ -65,14 +78,46 @@ write_benchmark_data (struct BenchmarkData *bd) GNUNET_assert (NULL != fh); GNUNET_free (s); - GNUNET_asprintf (&s, "eddsa_sign_count %llu", - (unsigned long long) bd->eddsa_sign_count); - GNUNET_assert (GNUNET_SYSERR != GNUNET_DISK_file_write_blocking (fh, s, strlen (s))); - GNUNET_free (s); +#define WRITE_BENCHMARK_OP(opname) do { \ + GNUNET_asprintf (&s, "op " #opname " count %llu time_us %llu\n", \ + (unsigned long long) bd->opname##_count, \ + (unsigned long long) bd->opname##_time.rel_value_us); \ + GNUNET_assert (GNUNET_SYSERR != GNUNET_DISK_file_write_blocking (fh, s, strlen (s))); \ + GNUNET_free (s); \ +} while (0) + + WRITE_BENCHMARK_OP (ecc_ecdh); + WRITE_BENCHMARK_OP (ecdh_eddsa); + WRITE_BENCHMARK_OP (ecdhe_key_create); + WRITE_BENCHMARK_OP (ecdhe_key_get_public); + WRITE_BENCHMARK_OP (ecdsa_ecdh); + WRITE_BENCHMARK_OP (ecdsa_key_create); + WRITE_BENCHMARK_OP (ecdsa_key_get_public); + WRITE_BENCHMARK_OP (ecdsa_sign); + WRITE_BENCHMARK_OP (ecdsa_verify); + WRITE_BENCHMARK_OP (eddsa_ecdh); + WRITE_BENCHMARK_OP (eddsa_key_create); + WRITE_BENCHMARK_OP (eddsa_key_get_public); + WRITE_BENCHMARK_OP (eddsa_sign); + WRITE_BENCHMARK_OP (eddsa_verify); + WRITE_BENCHMARK_OP (hash); + WRITE_BENCHMARK_OP (hash_context_finish); + WRITE_BENCHMARK_OP (hash_context_read); + WRITE_BENCHMARK_OP (hash_context_start); + WRITE_BENCHMARK_OP (hkdf); + WRITE_BENCHMARK_OP (rsa_blind); + WRITE_BENCHMARK_OP (rsa_private_key_create); + WRITE_BENCHMARK_OP (rsa_private_key_get_public); + WRITE_BENCHMARK_OP (rsa_sign_blinded); + WRITE_BENCHMARK_OP (rsa_unblind); + WRITE_BENCHMARK_OP (rsa_verify); + +#undef WRITE_BENCHMARK_OP GNUNET_assert (GNUNET_OK == GNUNET_DISK_file_close (fh)); - GNUNET_asprintf (&s, "gnunet-benchmark-urls-%llu-%llu.txt", + GNUNET_asprintf (&s, "%s/gnunet-benchmark-urls-%llu-%llu.txt", + benchmark_dir, (unsigned long long) pid, (unsigned long long) tid); @@ -137,7 +182,7 @@ thread_destructor (void *cls) * Initialize the thread-local variable key for benchmark data. */ static void -make_key() +make_key () { (void) pthread_key_create (&key, &thread_destructor); } diff --git a/src/util/benchmark.h b/src/util/benchmark.h index 6e00906c4..145d7cee7 100644 --- a/src/util/benchmark.h +++ b/src/util/benchmark.h @@ -33,6 +33,25 @@ */ #define MAX_BENCHMARK_URL_LEN 128 +#if ENABLE_BENCHMARK +#define BENCHMARK_START(opname) \ + struct GNUNET_TIME_Absolute _benchmark_##opname##_start = GNUNET_TIME_absolute_get () +#define BENCHMARK_END(opname) do { \ + { \ + struct GNUNET_TIME_Absolute _benchmark_##opname##_end = GNUNET_TIME_absolute_get (); \ + struct BenchmarkData *bd = get_benchmark_data (); \ + bd->opname##_count++; \ + bd->opname##_time = \ + GNUNET_TIME_relative_add (bd->opname##_time, \ + GNUNET_TIME_absolute_get_difference (_benchmark_##opname##_start, \ + _benchmark_##opname##_end)); \ + } \ +} while (0) +#else +#define BENCHMARK_START(opname) do { } while (0) +#define BENCHMARK_END(opname) do { } while (0) +#endif + /** * Struct for benchmark data for one URL. @@ -70,20 +89,40 @@ struct UrlRequestData struct GNUNET_TIME_Relative time_min; }; +#define GNUNET_DECLARE_BENCHMARK_OP(opname) \ + uint64_t opname##_count; \ + struct GNUNET_TIME_Relative opname##_time + /** * Thread-local struct for benchmarking data. */ struct BenchmarkData { - /** - * Number of eddsa_sign operations. - */ - uint64_t eddsa_sign_count; - - /** - * Time spent in eddsa_sign. - */ - struct GNUNET_TIME_Relative eddsa_sign_time; + GNUNET_DECLARE_BENCHMARK_OP (ecc_ecdh); + GNUNET_DECLARE_BENCHMARK_OP (ecdh_eddsa); + GNUNET_DECLARE_BENCHMARK_OP (ecdhe_key_create); + GNUNET_DECLARE_BENCHMARK_OP (ecdhe_key_get_public); + GNUNET_DECLARE_BENCHMARK_OP (ecdsa_ecdh); + GNUNET_DECLARE_BENCHMARK_OP (ecdsa_key_create); + GNUNET_DECLARE_BENCHMARK_OP (ecdsa_key_get_public); + GNUNET_DECLARE_BENCHMARK_OP (ecdsa_sign); + GNUNET_DECLARE_BENCHMARK_OP (ecdsa_verify); + GNUNET_DECLARE_BENCHMARK_OP (eddsa_ecdh); + GNUNET_DECLARE_BENCHMARK_OP (eddsa_key_create); + GNUNET_DECLARE_BENCHMARK_OP (eddsa_key_get_public); + GNUNET_DECLARE_BENCHMARK_OP (eddsa_sign); + GNUNET_DECLARE_BENCHMARK_OP (eddsa_verify); + GNUNET_DECLARE_BENCHMARK_OP (hash); + GNUNET_DECLARE_BENCHMARK_OP (hash_context_finish); + GNUNET_DECLARE_BENCHMARK_OP (hash_context_read); + GNUNET_DECLARE_BENCHMARK_OP (hash_context_start); + GNUNET_DECLARE_BENCHMARK_OP (hkdf); + GNUNET_DECLARE_BENCHMARK_OP (rsa_blind); + GNUNET_DECLARE_BENCHMARK_OP (rsa_private_key_create); + GNUNET_DECLARE_BENCHMARK_OP (rsa_private_key_get_public); + GNUNET_DECLARE_BENCHMARK_OP (rsa_sign_blinded); + GNUNET_DECLARE_BENCHMARK_OP (rsa_unblind); + GNUNET_DECLARE_BENCHMARK_OP (rsa_verify); struct UrlRequestData *urd; @@ -92,6 +131,8 @@ struct BenchmarkData unsigned int urd_capacity; }; +#undef GNUNET_DECLARE_BENCHMARK_OP + /** * Acquire the benchmark data for the current thread, allocate if necessary. diff --git a/src/util/crypto_ecc.c b/src/util/crypto_ecc.c index ca2aa40ad..9902f276d 100644 --- a/src/util/crypto_ecc.c +++ b/src/util/crypto_ecc.c @@ -226,6 +226,8 @@ GNUNET_CRYPTO_ecdsa_key_get_public (const struct GNUNET_CRYPTO_EcdsaPrivateKey * gcry_ctx_t ctx; gcry_mpi_t q; + BENCHMARK_START (ecdsa_key_get_public); + sexp = decode_private_ecdsa_key (priv); GNUNET_assert (NULL != sexp); GNUNET_assert (0 == gcry_mpi_ec_new (&ctx, sexp, NULL)); @@ -235,6 +237,8 @@ GNUNET_CRYPTO_ecdsa_key_get_public (const struct GNUNET_CRYPTO_EcdsaPrivateKey * GNUNET_CRYPTO_mpi_print_unsigned (pub->q_y, sizeof (pub->q_y), q); gcry_mpi_release (q); gcry_ctx_release (ctx); + + BENCHMARK_END (ecdsa_key_get_public); } @@ -252,6 +256,8 @@ GNUNET_CRYPTO_eddsa_key_get_public (const struct GNUNET_CRYPTO_EddsaPrivateKey * gcry_ctx_t ctx; gcry_mpi_t q; + BENCHMARK_START (eddsa_key_get_public); + sexp = decode_private_eddsa_key (priv); GNUNET_assert (NULL != sexp); GNUNET_assert (0 == gcry_mpi_ec_new (&ctx, sexp, NULL)); @@ -261,6 +267,8 @@ GNUNET_CRYPTO_eddsa_key_get_public (const struct GNUNET_CRYPTO_EddsaPrivateKey * GNUNET_CRYPTO_mpi_print_unsigned (pub->q_y, sizeof (pub->q_y), q); gcry_mpi_release (q); gcry_ctx_release (ctx); + + BENCHMARK_END (eddsa_key_get_public); } @@ -278,6 +286,8 @@ GNUNET_CRYPTO_ecdhe_key_get_public (const struct GNUNET_CRYPTO_EcdhePrivateKey * gcry_ctx_t ctx; gcry_mpi_t q; + BENCHMARK_START (ecdhe_key_get_public); + sexp = decode_private_ecdhe_key (priv); GNUNET_assert (NULL != sexp); GNUNET_assert (0 == gcry_mpi_ec_new (&ctx, sexp, NULL)); @@ -287,6 +297,8 @@ GNUNET_CRYPTO_ecdhe_key_get_public (const struct GNUNET_CRYPTO_EcdhePrivateKey * GNUNET_CRYPTO_mpi_print_unsigned (pub->q_y, sizeof (pub->q_y), q); gcry_mpi_release (q); gcry_ctx_release (ctx); + + BENCHMARK_END (ecdhe_key_get_public); } @@ -556,6 +568,8 @@ GNUNET_CRYPTO_ecdhe_key_create2 (struct GNUNET_CRYPTO_EcdhePrivateKey *pk) gcry_mpi_t d; int rc; + BENCHMARK_START (ecdhe_key_create); + /* NOTE: For libgcrypt >= 1.7, we do not need the 'eddsa' flag here, but should also be harmless. For libgcrypt < 1.7, using 'eddsa' disables an expensive key testing routine. We do not want to run @@ -592,6 +606,9 @@ GNUNET_CRYPTO_ecdhe_key_create2 (struct GNUNET_CRYPTO_EcdhePrivateKey *pk) gcry_sexp_release (priv_sexp); GNUNET_CRYPTO_mpi_print_unsigned (pk->d, sizeof (pk->d), d); gcry_mpi_release (d); + + BENCHMARK_END (ecdhe_key_create); + return GNUNET_OK; } @@ -610,6 +627,8 @@ GNUNET_CRYPTO_ecdsa_key_create () gcry_mpi_t d; int rc; + BENCHMARK_START (ecdsa_key_create); + if (0 != (rc = gcry_sexp_build (&s_keyparam, NULL, "(genkey(ecc(curve \"" CURVE "\")" "(flags)))"))) @@ -642,6 +661,9 @@ GNUNET_CRYPTO_ecdsa_key_create () priv = GNUNET_new (struct GNUNET_CRYPTO_EcdsaPrivateKey); GNUNET_CRYPTO_mpi_print_unsigned (priv->d, sizeof (priv->d), d); gcry_mpi_release (d); + + BENCHMARK_END (ecdsa_key_create); + return priv; } @@ -659,6 +681,8 @@ GNUNET_CRYPTO_eddsa_key_create () gcry_mpi_t d; int rc; + BENCHMARK_START (eddsa_key_create); + #if CRYPTO_BUG again: #endif @@ -705,6 +729,8 @@ GNUNET_CRYPTO_eddsa_key_create () } #endif + BENCHMARK_END (eddsa_key_create); + return priv; } @@ -824,6 +850,8 @@ GNUNET_CRYPTO_ecdsa_sign (const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv, int rc; gcry_mpi_t rs[2]; + BENCHMARK_START (ecdsa_sign); + priv_sexp = decode_private_ecdsa_key (priv); data = data_to_ecdsa_value (purpose); if (0 != (rc = gcry_pk_sign (&sig_sexp, data, priv_sexp))) @@ -851,6 +879,9 @@ GNUNET_CRYPTO_ecdsa_sign (const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv, GNUNET_CRYPTO_mpi_print_unsigned (sig->s, sizeof (sig->s), rs[1]); gcry_mpi_release (rs[0]); gcry_mpi_release (rs[1]); + + BENCHMARK_END (ecdsa_sign); + return GNUNET_OK; } @@ -874,10 +905,7 @@ GNUNET_CRYPTO_eddsa_sign (const struct GNUNET_CRYPTO_EddsaPrivateKey *priv, int rc; gcry_mpi_t rs[2]; -#if ENABLE_BENCHMARK - struct BenchmarkData *bd = get_benchmark_data (); - bd->eddsa_sign_count++; -#endif + BENCHMARK_START (eddsa_sign); priv_sexp = decode_private_eddsa_key (priv); data = data_to_eddsa_value (purpose); @@ -906,6 +934,9 @@ GNUNET_CRYPTO_eddsa_sign (const struct GNUNET_CRYPTO_EddsaPrivateKey *priv, GNUNET_CRYPTO_mpi_print_unsigned (sig->s, sizeof (sig->s), rs[1]); gcry_mpi_release (rs[0]); gcry_mpi_release (rs[1]); + + BENCHMARK_END (eddsa_sign); + return GNUNET_OK; } @@ -930,6 +961,8 @@ GNUNET_CRYPTO_ecdsa_verify (uint32_t purpose, gcry_sexp_t pub_sexpr; int rc; + BENCHMARK_START (ecdsa_verify); + if (purpose != ntohl (validate->purpose)) return GNUNET_SYSERR; /* purpose mismatch */ @@ -960,8 +993,10 @@ GNUNET_CRYPTO_ecdsa_verify (uint32_t purpose, LOG (GNUNET_ERROR_TYPE_INFO, _("ECDSA signature verification failed at %s:%d: %s\n"), __FILE__, __LINE__, gcry_strerror (rc)); + BENCHMARK_END (ecdsa_verify); return GNUNET_SYSERR; } + BENCHMARK_END (ecdsa_verify); return GNUNET_OK; } @@ -987,6 +1022,8 @@ GNUNET_CRYPTO_eddsa_verify (uint32_t purpose, gcry_sexp_t pub_sexpr; int rc; + BENCHMARK_START (eddsa_verify); + if (purpose != ntohl (validate->purpose)) return GNUNET_SYSERR; /* purpose mismatch */ @@ -1017,8 +1054,10 @@ GNUNET_CRYPTO_eddsa_verify (uint32_t purpose, LOG (GNUNET_ERROR_TYPE_INFO, _("EdDSA signature verification failed at %s:%d: %s\n"), __FILE__, __LINE__, gcry_strerror (rc)); + BENCHMARK_END (eddsa_verify); return GNUNET_SYSERR; } + BENCHMARK_END (eddsa_verify); return GNUNET_OK; } @@ -1045,6 +1084,8 @@ GNUNET_CRYPTO_ecc_ecdh (const struct GNUNET_CRYPTO_EcdhePrivateKey *priv, unsigned char xbuf[256 / 8]; size_t rsize; + BENCHMARK_START (ecc_ecdh); + /* first, extract the q = dP value from the public key */ if (0 != gcry_sexp_build (&pub_sexpr, NULL, "(public-key(ecc(curve " CURVE ")(q %b)))", @@ -1088,6 +1129,7 @@ GNUNET_CRYPTO_ecc_ecdh (const struct GNUNET_CRYPTO_EcdhePrivateKey *priv, rsize, key_material); gcry_mpi_release (result_x); + BENCHMARK_END (ecc_ecdh); return GNUNET_OK; } @@ -1371,6 +1413,8 @@ GNUNET_CRYPTO_eddsa_ecdh (const struct GNUNET_CRYPTO_EddsaPrivateKey *priv, gcry_sexp_t pub_sexpr; int ret; + BENCHMARK_START (eddsa_ecdh); + /* first, extract the q = dP value from the public key */ if (0 != gcry_sexp_build (&pub_sexpr, NULL, "(public-key(ecc(curve " CURVE ")(q %b)))", @@ -1398,6 +1442,7 @@ GNUNET_CRYPTO_eddsa_ecdh (const struct GNUNET_CRYPTO_EddsaPrivateKey *priv, key_material); gcry_mpi_point_release (result); gcry_ctx_release (ctx); + BENCHMARK_END (eddsa_ecdh); return ret; } @@ -1424,6 +1469,8 @@ GNUNET_CRYPTO_ecdsa_ecdh (const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv, gcry_sexp_t pub_sexpr; int ret; + BENCHMARK_START (ecdsa_ecdh); + /* first, extract the q = dP value from the public key */ if (0 != gcry_sexp_build (&pub_sexpr, NULL, "(public-key(ecc(curve " CURVE ")(q %b)))", @@ -1448,6 +1495,7 @@ GNUNET_CRYPTO_ecdsa_ecdh (const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv, key_material); gcry_mpi_point_release (result); gcry_ctx_release (ctx); + BENCHMARK_END (ecdsa_ecdh); return ret; } @@ -1475,6 +1523,8 @@ GNUNET_CRYPTO_ecdh_eddsa (const struct GNUNET_CRYPTO_EcdhePrivateKey *priv, gcry_sexp_t pub_sexpr; int ret; + BENCHMARK_START (ecdh_eddsa); + /* first, extract the q = dP value from the public key */ if (0 != gcry_sexp_build (&pub_sexpr, NULL, "(public-key(ecc(curve " CURVE ")(q %b)))", @@ -1499,6 +1549,7 @@ GNUNET_CRYPTO_ecdh_eddsa (const struct GNUNET_CRYPTO_EcdhePrivateKey *priv, key_material); gcry_mpi_point_release (result); gcry_ctx_release (ctx); + BENCHMARK_END (ecdh_eddsa); return ret; } diff --git a/src/util/crypto_hash.c b/src/util/crypto_hash.c index fe1f58df7..cd36fbbd7 100644 --- a/src/util/crypto_hash.c +++ b/src/util/crypto_hash.c @@ -24,6 +24,7 @@ #include "platform.h" #include "gnunet_crypto_lib.h" #include "gnunet_strings_lib.h" +#include "benchmark.h" #include #define LOG(kind,...) GNUNET_log_from (kind, "util-crypto-hash", __VA_ARGS__) @@ -42,7 +43,9 @@ GNUNET_CRYPTO_hash (const void *block, size_t size, struct GNUNET_HashCode *ret) { + BENCHMARK_START (hash); gcry_md_hash_buffer (GCRY_MD_SHA512, ret, block, size); + BENCHMARK_END (hash); } @@ -442,11 +445,16 @@ GNUNET_CRYPTO_hash_context_start () { struct GNUNET_HashContext *hc; + BENCHMARK_START (hash_context_start); + hc = GNUNET_new (struct GNUNET_HashContext); GNUNET_assert (0 == gcry_md_open (&hc->hd, GCRY_MD_SHA512, 0)); + + BENCHMARK_END (hash_context_start); + return hc; } @@ -463,7 +471,9 @@ GNUNET_CRYPTO_hash_context_read (struct GNUNET_HashContext *hc, const void *buf, size_t size) { + BENCHMARK_START (hash_context_read); gcry_md_write (hc->hd, buf, size); + BENCHMARK_END (hash_context_read); } @@ -479,12 +489,15 @@ GNUNET_CRYPTO_hash_context_finish (struct GNUNET_HashContext *hc, { const void *res = gcry_md_read (hc->hd, 0); + BENCHMARK_START (hash_context_finish); + GNUNET_assert (NULL != res); if (NULL != r_hash) GNUNET_memcpy (r_hash, res, sizeof (struct GNUNET_HashCode)); GNUNET_CRYPTO_hash_context_abort (hc); + BENCHMARK_END (hash_context_finish); } diff --git a/src/util/crypto_hkdf.c b/src/util/crypto_hkdf.c index f04d3e675..6dae13840 100644 --- a/src/util/crypto_hkdf.c +++ b/src/util/crypto_hkdf.c @@ -52,6 +52,7 @@ #if GNUNET_BUILD #include "platform.h" +#include "benchmark.h" #include "gnunet_crypto_lib.h" #else #define GNUNET_NO 0 @@ -155,6 +156,8 @@ GNUNET_CRYPTO_hkdf_v (void *result, size_t out_len, int xtr_algo, int prf_algo, size_t ctx_len; va_list args; + BENCHMARK_START (hkdf); + if (0 == k) return GNUNET_SYSERR; if (GPG_ERR_NO_ERROR != @@ -265,6 +268,7 @@ hkdf_error: hkdf_ok: gcry_md_close (xtr); gcry_md_close (prf); + BENCHMARK_END (hkdf); return ret; } diff --git a/src/util/crypto_rsa.c b/src/util/crypto_rsa.c index 1225aba73..26c33d5f3 100644 --- a/src/util/crypto_rsa.c +++ b/src/util/crypto_rsa.c @@ -26,6 +26,7 @@ #include "platform.h" #include #include "gnunet_crypto_lib.h" +#include "benchmark.h" #define LOG(kind,...) GNUNET_log_from (kind, "util-crypto-rsa", __VA_ARGS__) @@ -149,6 +150,8 @@ GNUNET_CRYPTO_rsa_private_key_create (unsigned int len) gcry_sexp_t s_key; gcry_sexp_t s_keyparam; + BENCHMARK_START (rsa_private_key_create); + GNUNET_assert (0 == gcry_sexp_build (&s_keyparam, NULL, @@ -164,6 +167,7 @@ GNUNET_CRYPTO_rsa_private_key_create (unsigned int len) #endif ret = GNUNET_new (struct GNUNET_CRYPTO_RsaPrivateKey); ret->sexp = s_key; + BENCHMARK_END (rsa_private_key_create); return ret; } @@ -261,6 +265,8 @@ GNUNET_CRYPTO_rsa_private_key_get_public (const struct GNUNET_CRYPTO_RsaPrivateK int rc; gcry_sexp_t result; + BENCHMARK_START (rsa_private_key_get_public); + rc = key_from_sexp (ne, priv->sexp, "public-key", "ne"); if (0 != rc) rc = key_from_sexp (ne, priv->sexp, "private-key", "ne"); @@ -280,6 +286,7 @@ GNUNET_CRYPTO_rsa_private_key_get_public (const struct GNUNET_CRYPTO_RsaPrivateK gcry_mpi_release (ne[1]); pub = GNUNET_new (struct GNUNET_CRYPTO_RsaPublicKey); pub->sexp = result; + BENCHMARK_END (rsa_private_key_get_public); return pub; } @@ -736,6 +743,8 @@ GNUNET_CRYPTO_rsa_blind (const struct GNUNET_HashCode *hash, gcry_mpi_t data_r_e; int ret; + BENCHMARK_START (rsa_blind); + GNUNET_assert (buf != NULL && buf_size != NULL); ret = key_from_sexp (ne, pkey->sexp, "public-key", "ne"); if (0 != ret) @@ -778,6 +787,8 @@ GNUNET_CRYPTO_rsa_blind (const struct GNUNET_HashCode *hash, gcry_mpi_release (data_r_e); return GNUNET_YES; + BENCHMARK_END (rsa_blind); + rsa_gcd_validate_failure: /* We know the RSA key is malicious here, so warn the wallet. */ /* GNUNET_break_op (0); */ @@ -885,6 +896,8 @@ GNUNET_CRYPTO_rsa_sign_blinded (const struct GNUNET_CRYPTO_RsaPrivateKey *key, gcry_mpi_t v = NULL; struct GNUNET_CRYPTO_RsaSignature *sig; + BENCHMARK_START (rsa_sign_blinded); + GNUNET_assert (0 == gcry_mpi_scan (&v, GCRYMPI_FMT_USG, @@ -894,6 +907,7 @@ GNUNET_CRYPTO_rsa_sign_blinded (const struct GNUNET_CRYPTO_RsaPrivateKey *key, sig = rsa_sign_mpi (key, v); gcry_mpi_release (v); + BENCHMARK_END (rsa_sign_blinded); return sig; } @@ -1059,6 +1073,8 @@ GNUNET_CRYPTO_rsa_unblind (const struct GNUNET_CRYPTO_RsaSignature *sig, int ret; struct GNUNET_CRYPTO_RsaSignature *sret; + BENCHMARK_START (rsa_unblind); + ret = key_from_sexp (&n, pkey->sexp, "public-key", "n"); if (0 != ret) ret = key_from_sexp (&n, pkey->sexp, "rsa", "n"); @@ -1120,6 +1136,7 @@ GNUNET_CRYPTO_rsa_unblind (const struct GNUNET_CRYPTO_RsaSignature *sig, "(sig-val (rsa (s %M)))", ubsig)); gcry_mpi_release (ubsig); + BENCHMARK_END (rsa_unblind); return sret; } @@ -1142,6 +1159,8 @@ GNUNET_CRYPTO_rsa_verify (const struct GNUNET_HashCode *hash, gcry_mpi_t r; int rc; + BENCHMARK_START (rsa_verify); + r = rsa_full_domain_hash (pkey, hash); if (NULL == r) { GNUNET_break_op (0); @@ -1169,7 +1188,9 @@ GNUNET_CRYPTO_rsa_verify (const struct GNUNET_HashCode *hash, __LINE__, gcry_strerror (rc)); return GNUNET_SYSERR; + BENCHMARK_END (rsa_verify); } + BENCHMARK_END (rsa_verify); return GNUNET_OK; } -- cgit v1.2.3