X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=src%2Futil%2Fperf_crypto_asymmetric.c;h=91679afa5dd7da97f1f8d52f1460be4472aefe81;hb=0a715a462813496e7a1a03fd072a34eeb3c9e412;hp=a2cb3a6cef40aa7ea5a5565428e168ba61e9008b;hpb=d31e933a35007204ca4c7f98c209b4f7e14f9ecc;p=oweals%2Fgnunet.git diff --git a/src/util/perf_crypto_asymmetric.c b/src/util/perf_crypto_asymmetric.c index a2cb3a6ce..91679afa5 100644 --- a/src/util/perf_crypto_asymmetric.c +++ b/src/util/perf_crypto_asymmetric.c @@ -11,12 +11,12 @@ 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 . SPDX-License-Identifier: AGPL3.0-or-later -*/ + */ /** * @author Bart Polot @@ -31,8 +31,7 @@ static struct GNUNET_TIME_Absolute start; #define l 500 -struct TestSig -{ +struct TestSig { struct GNUNET_CRYPTO_EccSignaturePurpose purp; struct GNUNET_HashCode h; struct GNUNET_CRYPTO_EddsaSignature sig; @@ -40,26 +39,26 @@ struct TestSig static void -log_duration (const char *cryptosystem, - const char *description) +log_duration(const char *cryptosystem, + const char *description) { struct GNUNET_TIME_Relative t; char s[64]; - 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)); - GAUGER ("UTIL", s, t.rel_value_us, "us"); + 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)); + GAUGER("UTIL", s, t.rel_value_us, "us"); } int -main (int argc, char *argv[]) +main(int argc, char *argv[]) { int i; struct GNUNET_CRYPTO_EcdhePrivateKey *ecdhe[l]; @@ -70,60 +69,60 @@ main (int argc, char *argv[]) start = GNUNET_TIME_absolute_get(); for (i = 0; i < l; i++) - { - sig[i].purp.purpose = 0; - 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[i].h)); - } - log_duration ("", "Init"); + { + sig[i].purp.purpose = 0; + 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[i].h)); + } + log_duration("", "Init"); start = GNUNET_TIME_absolute_get(); for (i = 0; i < l; i++) eddsa[i] = GNUNET_CRYPTO_eddsa_key_create(); - log_duration ("EdDSA", "create key"); + log_duration("EdDSA", "create key"); 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 public"); + GNUNET_CRYPTO_eddsa_key_get_public(eddsa[i], &dspub[i]); + log_duration("EdDSA", "get public"); start = GNUNET_TIME_absolute_get(); for (i = 0; i < l; i++) - GNUNET_assert (GNUNET_OK == - GNUNET_CRYPTO_eddsa_sign (eddsa[i], - &sig[i].purp, - &sig[i].sig)); - log_duration ("EdDSA", "sign HashCode"); + 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_assert (GNUNET_OK == - GNUNET_CRYPTO_eddsa_verify (0, - &sig[i].purp, - &sig[i].sig, - &dspub[i])); - log_duration ("EdDSA", "verify HashCode"); + 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(); for (i = 0; i < l; i++) ecdhe[i] = GNUNET_CRYPTO_ecdhe_key_create(); - log_duration ("ECDH", "create key"); + log_duration("ECDH", "create key"); start = GNUNET_TIME_absolute_get(); for (i = 0; i < l; i++) - GNUNET_CRYPTO_ecdhe_key_get_public (ecdhe[i], &dhpub[i]); - log_duration ("ECDH", "get public"); + GNUNET_CRYPTO_ecdhe_key_get_public(ecdhe[i], &dhpub[i]); + log_duration("ECDH", "get public"); start = GNUNET_TIME_absolute_get(); - 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+1].h); - } - log_duration ("ECDH", "do DH"); + 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 + 1].h); + } + log_duration("ECDH", "do DH"); return 0; }