diff options
author | Martin Schanzenbach <schanzen@gnunet.org> | 2023-10-18 13:37:38 +0200 |
---|---|---|
committer | Martin Schanzenbach <schanzen@gnunet.org> | 2023-10-18 13:37:38 +0200 |
commit | 9ef4abad615bea12d13be542b8ae5fbeb2dfee32 (patch) | |
tree | 8875a687e004d331c9ea6a1d511a328c72b88113 /src/util/perf_crypto_rsa.c | |
parent | e95236b3ed78cd597c15f34b89385295702b627f (diff) | |
download | gnunet-9ef4abad615bea12d13be542b8ae5fbeb2dfee32.tar.gz gnunet-9ef4abad615bea12d13be542b8ae5fbeb2dfee32.zip |
NEWS: Refactoring components under src/ into lib/, plugin/, cli/ and service/
This also includes a necessary API refactoring of crypto from IDENTITY
to UTIL.
Diffstat (limited to 'src/util/perf_crypto_rsa.c')
-rw-r--r-- | src/util/perf_crypto_rsa.c | 213 |
1 files changed, 0 insertions, 213 deletions
diff --git a/src/util/perf_crypto_rsa.c b/src/util/perf_crypto_rsa.c deleted file mode 100644 index ab9f362cf..000000000 --- a/src/util/perf_crypto_rsa.c +++ /dev/null | |||
@@ -1,213 +0,0 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | Copyright (C) 2014 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_rsa.c | ||
24 | * @brief measure performance of RSA signing | ||
25 | */ | ||
26 | |||
27 | #include "platform.h" | ||
28 | #include "gnunet_util_lib.h" | ||
29 | #include <gauger.h> | ||
30 | |||
31 | |||
32 | /** | ||
33 | * Evaluate RSA performance. | ||
34 | * | ||
35 | * @param len keylength to evaluate with | ||
36 | */ | ||
37 | static void | ||
38 | eval (unsigned int len) | ||
39 | { | ||
40 | struct GNUNET_TIME_Absolute start; | ||
41 | struct GNUNET_CRYPTO_RsaSignature *sig; | ||
42 | struct GNUNET_CRYPTO_RsaSignature *rsig; | ||
43 | struct GNUNET_CRYPTO_RsaPublicKey *public_key; | ||
44 | struct GNUNET_CRYPTO_RsaPrivateKey *private_key; | ||
45 | struct GNUNET_CRYPTO_RsaBlindingKeySecret bsec[10]; | ||
46 | unsigned int i; | ||
47 | char sbuf[128]; | ||
48 | void *bbuf; | ||
49 | size_t bbuf_len; | ||
50 | struct GNUNET_HashCode hc; | ||
51 | |||
52 | start = GNUNET_TIME_absolute_get (); | ||
53 | for (i = 0; i < 10; i++) | ||
54 | { | ||
55 | private_key = GNUNET_CRYPTO_rsa_private_key_create (len); | ||
56 | GNUNET_CRYPTO_rsa_private_key_free (private_key); | ||
57 | } | ||
58 | printf ("10x %u-key generation took %s\n", | ||
59 | len, | ||
60 | GNUNET_STRINGS_relative_time_to_string ( | ||
61 | GNUNET_TIME_absolute_get_duration (start), | ||
62 | GNUNET_YES)); | ||
63 | GNUNET_snprintf (sbuf, | ||
64 | sizeof(sbuf), | ||
65 | "RSA %u-key generation", | ||
66 | len); | ||
67 | GAUGER ("UTIL", sbuf, | ||
68 | 64 * 1024 / (1 | ||
69 | + GNUNET_TIME_absolute_get_duration | ||
70 | (start).rel_value_us / 1000LL), "keys/ms"); | ||
71 | private_key = GNUNET_CRYPTO_rsa_private_key_create (len); | ||
72 | public_key = GNUNET_CRYPTO_rsa_private_key_get_public (private_key); | ||
73 | for (i = 0; i < 10; i++) | ||
74 | GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK, | ||
75 | &bsec[i], sizeof(bsec[0])); | ||
76 | /* | ||
77 | start = GNUNET_TIME_absolute_get (); | ||
78 | for (i=0;i<10;i++) | ||
79 | rsa_blinding_key_derive(public_key, &bsec[i]); | ||
80 | printf ("10x %u-blinding key generation took %s\n", | ||
81 | len, | ||
82 | GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_duration (start), | ||
83 | GNUNET_YES)); | ||
84 | GNUNET_snprintf (sbuf, | ||
85 | sizeof (sbuf), | ||
86 | "RSA %u-blinding key generation", | ||
87 | len); | ||
88 | GAUGER ("UTIL", sbuf, | ||
89 | 64 * 1024 / (1 + | ||
90 | GNUNET_TIME_absolute_get_duration | ||
91 | (start).rel_value_us / 1000LL), "keys/ms"); | ||
92 | */ | ||
93 | start = GNUNET_TIME_absolute_get (); | ||
94 | GNUNET_CRYPTO_hash ("test", 4, &hc); | ||
95 | for (i = 0; i < 10; i++) | ||
96 | { | ||
97 | GNUNET_CRYPTO_rsa_blind (&hc, | ||
98 | &bsec[i], | ||
99 | public_key, | ||
100 | &bbuf, | ||
101 | &bbuf_len); | ||
102 | GNUNET_free (bbuf); | ||
103 | } | ||
104 | printf ("10x %u-blinding took %s\n", | ||
105 | len, | ||
106 | GNUNET_STRINGS_relative_time_to_string ( | ||
107 | GNUNET_TIME_absolute_get_duration (start), | ||
108 | GNUNET_YES)); | ||
109 | GNUNET_snprintf (sbuf, | ||
110 | sizeof(sbuf), | ||
111 | "RSA %u-blinding", | ||
112 | len); | ||
113 | GAUGER ("UTIL", | ||
114 | sbuf, | ||
115 | 64 * 1024 / (1 | ||
116 | + GNUNET_TIME_absolute_get_duration | ||
117 | (start).rel_value_us / 1000LL), "ops/ms"); | ||
118 | GNUNET_CRYPTO_rsa_blind (&hc, | ||
119 | &bsec[0], | ||
120 | public_key, | ||
121 | &bbuf, | ||
122 | &bbuf_len); | ||
123 | start = GNUNET_TIME_absolute_get (); | ||
124 | for (i = 0; i < 10; i++) | ||
125 | { | ||
126 | sig = GNUNET_CRYPTO_rsa_sign_blinded (private_key, | ||
127 | bbuf, | ||
128 | bbuf_len); | ||
129 | GNUNET_CRYPTO_rsa_signature_free (sig); | ||
130 | } | ||
131 | printf ("10x %u-signing took %s\n", | ||
132 | len, | ||
133 | GNUNET_STRINGS_relative_time_to_string ( | ||
134 | GNUNET_TIME_absolute_get_duration (start), | ||
135 | GNUNET_YES)); | ||
136 | GNUNET_snprintf (sbuf, | ||
137 | sizeof(sbuf), | ||
138 | "RSA %u-signing", | ||
139 | len); | ||
140 | GAUGER ("UTIL", | ||
141 | sbuf, | ||
142 | 64 * 1024 / (1 | ||
143 | + GNUNET_TIME_absolute_get_duration | ||
144 | (start).rel_value_us / 1000LL), "ops/ms"); | ||
145 | sig = GNUNET_CRYPTO_rsa_sign_blinded (private_key, | ||
146 | bbuf, | ||
147 | bbuf_len); | ||
148 | start = GNUNET_TIME_absolute_get (); | ||
149 | for (i = 0; i < 10; i++) | ||
150 | { | ||
151 | rsig = GNUNET_CRYPTO_rsa_unblind (sig, | ||
152 | &bsec[0], | ||
153 | public_key); | ||
154 | GNUNET_CRYPTO_rsa_signature_free (rsig); | ||
155 | } | ||
156 | printf ("10x %u-unblinding took %s\n", | ||
157 | len, | ||
158 | GNUNET_STRINGS_relative_time_to_string ( | ||
159 | GNUNET_TIME_absolute_get_duration (start), | ||
160 | GNUNET_YES)); | ||
161 | GNUNET_snprintf (sbuf, | ||
162 | sizeof(sbuf), | ||
163 | "RSA %u-unblinding", | ||
164 | len); | ||
165 | GAUGER ("UTIL", | ||
166 | sbuf, | ||
167 | 64 * 1024 / (1 | ||
168 | + GNUNET_TIME_absolute_get_duration | ||
169 | (start).rel_value_us / 1000LL), "ops/ms"); | ||
170 | rsig = GNUNET_CRYPTO_rsa_unblind (sig, | ||
171 | &bsec[0], | ||
172 | public_key); | ||
173 | start = GNUNET_TIME_absolute_get (); | ||
174 | for (i = 0; i < 10; i++) | ||
175 | { | ||
176 | GNUNET_assert (GNUNET_OK == | ||
177 | GNUNET_CRYPTO_rsa_verify (&hc, | ||
178 | rsig, | ||
179 | public_key)); | ||
180 | } | ||
181 | printf ("10x %u-verifying took %s\n", | ||
182 | len, | ||
183 | GNUNET_STRINGS_relative_time_to_string ( | ||
184 | GNUNET_TIME_absolute_get_duration (start), | ||
185 | GNUNET_YES)); | ||
186 | GNUNET_snprintf (sbuf, | ||
187 | sizeof(sbuf), | ||
188 | "RSA %u-verification", | ||
189 | len); | ||
190 | GAUGER ("UTIL", | ||
191 | sbuf, | ||
192 | 64 * 1024 / (1 | ||
193 | + GNUNET_TIME_absolute_get_duration | ||
194 | (start).rel_value_us / 1000LL), "ops/ms"); | ||
195 | GNUNET_CRYPTO_rsa_signature_free (sig); | ||
196 | GNUNET_CRYPTO_rsa_public_key_free (public_key); | ||
197 | GNUNET_CRYPTO_rsa_private_key_free (private_key); | ||
198 | GNUNET_free (bbuf); | ||
199 | } | ||
200 | |||
201 | |||
202 | int | ||
203 | main (int argc, char *argv[]) | ||
204 | { | ||
205 | eval (1024); | ||
206 | eval (2048); | ||
207 | eval (3072); | ||
208 | eval (4096); | ||
209 | return 0; | ||
210 | } | ||
211 | |||
212 | |||
213 | /* end of perf_crypto_rsa.c */ | ||