X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=src%2Futil%2Fperf_crypto_asymmetric.c;h=418d6dab39f7f5668d5bcab0aaaec2c6ffbc1029;hb=82e765caeb53a1de54676738169dab98ca76c47e;hp=cb4827509494deaab94da239e4e7e524f90e5543;hpb=868ceb365a817c5138e3668a78be08b28791f9b0;p=oweals%2Fgnunet.git diff --git a/src/util/perf_crypto_asymmetric.c b/src/util/perf_crypto_asymmetric.c index cb4827509..418d6dab3 100644 --- a/src/util/perf_crypto_asymmetric.c +++ b/src/util/perf_crypto_asymmetric.c @@ -1,6 +1,6 @@ /* This file is part of GNUnet. - Copyright (C) 2015 Christian Grothoff (and other contributing authors) + Copyright (C) 2015 GNUnet e.V. GNUnet is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published @@ -14,8 +14,8 @@ 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. + Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. */ /** @@ -27,30 +27,37 @@ #include "gnunet_util_lib.h" #include -struct GNUNET_TIME_Absolute start; -const int l = 50; +static struct GNUNET_TIME_Absolute start; -struct TestSig { +#define l 50 + +struct TestSig +{ struct GNUNET_CRYPTO_EccSignaturePurpose purp; struct GNUNET_HashCode h; struct GNUNET_CRYPTO_EddsaSignature sig; }; + static void -log_duration (const char *system, const char *description) +log_duration (const char *cryptosystem, + const char *description) { struct GNUNET_TIME_Relative t; char s[64]; - sprintf (s, "%6s %15s", system, description); + sprintf (s, "%6s %15s", cryptosystem, description); t = GNUNET_TIME_absolute_get_duration (start); t = GNUNET_TIME_relative_divide (t, l); - FPRINTF (stdout, "%s: %10s\n", s, - GNUNET_STRINGS_relative_time_to_string(t, GNUNET_NO)); - + FPRINTF (stdout, + "%s: %10s\n", + s, + GNUNET_STRINGS_relative_time_to_string (t, + GNUNET_NO)); GAUGER ("UTIL", s, t.rel_value_us, "us"); } + int main (int argc, char *argv[]) { @@ -68,7 +75,8 @@ main (int argc, char *argv[]) sig[i].purp.size = htonl (sizeof (struct GNUNET_CRYPTO_EccSignaturePurpose) + sizeof (struct GNUNET_HashCode)); GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK, - &sig[i].h, sizeof (&sig[0].h)); + &sig[i].h, + sizeof (sig[i].h)); } log_duration ("", "Init"); @@ -80,16 +88,23 @@ main (int argc, char *argv[]) start = GNUNET_TIME_absolute_get(); for (i = 0; i < l; i++) GNUNET_CRYPTO_eddsa_key_get_public (eddsa[i], &dspub[i]); - log_duration ("EdDSA", "get pubilc"); + log_duration ("EdDSA", "get public"); start = GNUNET_TIME_absolute_get(); for (i = 0; i < l; i++) - GNUNET_CRYPTO_eddsa_sign (eddsa[i], &sig[i].purp, &sig[i].sig); + GNUNET_assert (GNUNET_OK == + GNUNET_CRYPTO_eddsa_sign (eddsa[i], + &sig[i].purp, + &sig[i].sig)); log_duration ("EdDSA", "sign HashCode"); start = GNUNET_TIME_absolute_get(); for (i = 0; i < l; i++) - GNUNET_CRYPTO_eddsa_verify (0, &sig[i].purp, &sig[i].sig, &dspub[i]); + GNUNET_assert (GNUNET_OK == + GNUNET_CRYPTO_eddsa_verify (0, + &sig[i].purp, + &sig[i].sig, + &dspub[i])); log_duration ("EdDSA", "verify HashCode"); start = GNUNET_TIME_absolute_get(); @@ -103,10 +118,10 @@ main (int argc, char *argv[]) log_duration ("ECDH", "get public"); start = GNUNET_TIME_absolute_get(); - for (i = 0; i < l; i+=2) + for (i = 0; i < l - 1; i+=2) { GNUNET_CRYPTO_ecc_ecdh (ecdhe[i], &dhpub[i+1], &sig[i].h); - GNUNET_CRYPTO_ecc_ecdh (ecdhe[i+1], &dhpub[i], &sig[i+i].h); + GNUNET_CRYPTO_ecc_ecdh (ecdhe[i+1], &dhpub[i], &sig[i+1].h); } log_duration ("ECDH", "do DH");