aboutsummaryrefslogtreecommitdiff
path: root/src/lib/util/perf_crypto_hash.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/util/perf_crypto_hash.c')
-rw-r--r--src/lib/util/perf_crypto_hash.c115
1 files changed, 115 insertions, 0 deletions
diff --git a/src/lib/util/perf_crypto_hash.c b/src/lib/util/perf_crypto_hash.c
new file mode 100644
index 000000000..4e37ef758
--- /dev/null
+++ b/src/lib/util/perf_crypto_hash.c
@@ -0,0 +1,115 @@
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2002, 2003, 2004, 2006 GNUnet e.V.
4
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 SPDX-License-Identifier: AGPL3.0-or-later
19 */
20
21/**
22 * @author Christian Grothoff
23 * @file util/perf_crypto_hash.c
24 * @brief measure performance of hash function
25 */
26
27#include "platform.h"
28#include "gnunet_util_lib.h"
29#include <gauger.h>
30#include <gcrypt.h>
31
32
33static void
34perfHash ()
35{
36 struct GNUNET_HashCode hc;
37 unsigned int i;
38 char buf[64 * 1024];
39
40 memset (buf, 1, sizeof(buf));
41 for (i = 0; i < 1024; i++)
42 GNUNET_CRYPTO_hash (buf, sizeof(buf), &hc);
43}
44
45
46static void
47perfHashSmall ()
48{
49 struct GNUNET_HashCode hc;
50 unsigned int i;
51 char buf[64];
52
53 memset (buf, 1, sizeof(buf));
54 for (i = 0; i < 1024; i++)
55 GNUNET_CRYPTO_hash (buf, sizeof(buf), &hc);
56}
57
58
59static void
60perfHKDF ()
61{
62 unsigned int i;
63 char res[128];
64 char buf[128];
65 char skm[64];
66
67 memset (buf, 1, sizeof(buf));
68 memset (skm, 2, sizeof(skm));
69 for (i = 0; i < 1024; i++)
70 GNUNET_CRYPTO_hkdf (res, sizeof(res),
71 GCRY_MD_SHA512, GCRY_MD_SHA256,
72 buf, sizeof(buf),
73 skm, sizeof(skm),
74 "test", (size_t) 4,
75 NULL, 0);
76}
77
78
79int
80main (int argc, char *argv[])
81{
82 struct GNUNET_TIME_Absolute start;
83
84 start = GNUNET_TIME_absolute_get ();
85 perfHashSmall ();
86 printf ("1024x 64-byte Hash perf took %s\n",
87 GNUNET_STRINGS_relative_time_to_string (
88 GNUNET_TIME_absolute_get_duration (start),
89 GNUNET_YES));
90
91 start = GNUNET_TIME_absolute_get ();
92 perfHash ();
93 printf ("1024x 64k Hash perf took %s\n",
94 GNUNET_STRINGS_relative_time_to_string (
95 GNUNET_TIME_absolute_get_duration (start),
96 GNUNET_YES));
97 GAUGER ("UTIL", "Cryptographic hashing",
98 64 * 1024 / (1
99 + GNUNET_TIME_absolute_get_duration
100 (start).rel_value_us / 1000LL), "kb/ms");
101 start = GNUNET_TIME_absolute_get ();
102 perfHKDF ();
103 printf ("HKDF perf took %s\n",
104 GNUNET_STRINGS_relative_time_to_string (
105 GNUNET_TIME_absolute_get_duration (start),
106 GNUNET_YES));
107 GAUGER ("UTIL", "Cryptographic HKDF",
108 64 * 1024 / (1
109 + GNUNET_TIME_absolute_get_duration
110 (start).rel_value_us / 1000LL), "kb/ms");
111 return 0;
112}
113
114
115/* end of perf_crypto_hash.c */