diff options
Diffstat (limited to 'src/util/perf_crypto_ecc_dlog.c')
-rw-r--r-- | src/util/perf_crypto_ecc_dlog.c | 183 |
1 files changed, 0 insertions, 183 deletions
diff --git a/src/util/perf_crypto_ecc_dlog.c b/src/util/perf_crypto_ecc_dlog.c deleted file mode 100644 index f32ffbd67..000000000 --- a/src/util/perf_crypto_ecc_dlog.c +++ /dev/null | |||
@@ -1,183 +0,0 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | Copyright (C) 2015 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 | * @file util/perf_crypto_ecc_dlog.c | ||
23 | * @brief benchmark for ECC DLOG calculation | ||
24 | * @author Christian Grothoff | ||
25 | */ | ||
26 | #include "platform.h" | ||
27 | #include "gnunet_util_lib.h" | ||
28 | #include <gcrypt.h> | ||
29 | #include <gauger.h> | ||
30 | |||
31 | |||
32 | /** | ||
33 | * Name of the curve we are using. Note that we have hard-coded | ||
34 | * structs that use 256 bits, so using a bigger curve will require | ||
35 | * changes that break stuff badly. The name of the curve given here | ||
36 | * must be agreed by all peers and be supported by libgcrypt. | ||
37 | */ | ||
38 | #define CURVE "Ed25519" | ||
39 | |||
40 | /** | ||
41 | * Maximum value we benchmark dlog for. | ||
42 | */ | ||
43 | #define MAX_FACT (1024 * 1024) | ||
44 | |||
45 | /** | ||
46 | * Maximum memory to use, sqrt(MAX_FACT) is a good choice. | ||
47 | */ | ||
48 | #define MAX_MEM 1024 | ||
49 | |||
50 | /** | ||
51 | * How many values do we test? | ||
52 | */ | ||
53 | #define TEST_ITER 10 | ||
54 | |||
55 | |||
56 | /** | ||
57 | * Do some DLOG operations for testing. | ||
58 | * | ||
59 | * @param edc context for ECC operations | ||
60 | * @param do_dlog true if we want to actually do the bencharked operation | ||
61 | */ | ||
62 | static void | ||
63 | test_dlog (struct GNUNET_CRYPTO_EccDlogContext *edc, | ||
64 | bool do_dlog) | ||
65 | { | ||
66 | for (unsigned int i = 0; i < TEST_ITER; i++) | ||
67 | { | ||
68 | struct GNUNET_CRYPTO_EccScalar fact; | ||
69 | struct GNUNET_CRYPTO_EccScalar n; | ||
70 | struct GNUNET_CRYPTO_EccPoint q; | ||
71 | int x; | ||
72 | |||
73 | fprintf (stderr, "."); | ||
74 | x = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, | ||
75 | MAX_FACT); | ||
76 | memset (&n, | ||
77 | 0, | ||
78 | sizeof (n)); | ||
79 | for (unsigned int j = 0; j < x; j++) | ||
80 | sodium_increment (n.v, | ||
81 | sizeof (n.v)); | ||
82 | if (0 == GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, | ||
83 | 2)) | ||
84 | { | ||
85 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
86 | "Trying negative %d\n", | ||
87 | -x); | ||
88 | crypto_core_ed25519_scalar_negate (fact.v, | ||
89 | n.v); | ||
90 | x = -x; | ||
91 | } | ||
92 | else | ||
93 | { | ||
94 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
95 | "Trying positive %d\n", | ||
96 | x); | ||
97 | fact = n; | ||
98 | } | ||
99 | if (0 == x) | ||
100 | { | ||
101 | /* libsodium does not like to multiply with zero; make sure | ||
102 | 'q' is a valid point (g) first, then use q = q - q to get | ||
103 | the product with zero */ | ||
104 | sodium_increment (fact.v, | ||
105 | sizeof (fact.v)); | ||
106 | GNUNET_assert (0 == | ||
107 | crypto_scalarmult_ed25519_base_noclamp (q.v, | ||
108 | fact.v)); | ||
109 | GNUNET_assert ( | ||
110 | 0 == | ||
111 | crypto_core_ed25519_sub (q.v, | ||
112 | q.v, | ||
113 | q.v)); | ||
114 | } | ||
115 | else | ||
116 | GNUNET_assert (0 == | ||
117 | crypto_scalarmult_ed25519_base_noclamp (q.v, | ||
118 | fact.v)); | ||
119 | if (do_dlog) | ||
120 | { | ||
121 | int iret; | ||
122 | |||
123 | if (x != | ||
124 | (iret = GNUNET_CRYPTO_ecc_dlog (edc, | ||
125 | &q))) | ||
126 | { | ||
127 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
128 | "DLOG failed for value %d (got: %d)\n", | ||
129 | x, | ||
130 | iret); | ||
131 | GNUNET_assert (0); | ||
132 | } | ||
133 | } | ||
134 | } | ||
135 | fprintf (stderr, | ||
136 | "\n"); | ||
137 | } | ||
138 | |||
139 | |||
140 | int | ||
141 | main (int argc, char *argv[]) | ||
142 | { | ||
143 | struct GNUNET_CRYPTO_EccDlogContext *edc; | ||
144 | struct GNUNET_TIME_Absolute start; | ||
145 | struct GNUNET_TIME_Relative delta; | ||
146 | |||
147 | GNUNET_log_setup ("perf-crypto-ecc-dlog", | ||
148 | "WARNING", | ||
149 | NULL); | ||
150 | start = GNUNET_TIME_absolute_get (); | ||
151 | edc = GNUNET_CRYPTO_ecc_dlog_prepare (MAX_FACT, | ||
152 | MAX_MEM); | ||
153 | printf ("DLOG precomputation 1M/1K took %s\n", | ||
154 | GNUNET_STRINGS_relative_time_to_string ( | ||
155 | GNUNET_TIME_absolute_get_duration (start), | ||
156 | GNUNET_YES)); | ||
157 | GAUGER ("UTIL", "ECC DLOG initialization", | ||
158 | GNUNET_TIME_absolute_get_duration | ||
159 | (start).rel_value_us / 1000LL, "ms/op"); | ||
160 | start = GNUNET_TIME_absolute_get (); | ||
161 | /* first do a baseline run without the DLOG */ | ||
162 | test_dlog (edc, false); | ||
163 | delta = GNUNET_TIME_absolute_get_duration (start); | ||
164 | start = GNUNET_TIME_absolute_get (); | ||
165 | test_dlog (edc, true); | ||
166 | delta = GNUNET_TIME_relative_subtract (GNUNET_TIME_absolute_get_duration ( | ||
167 | start), | ||
168 | delta); | ||
169 | printf ("%u DLOG calculations took %s\n", | ||
170 | TEST_ITER, | ||
171 | GNUNET_STRINGS_relative_time_to_string (delta, | ||
172 | GNUNET_YES)); | ||
173 | GAUGER ("UTIL", | ||
174 | "ECC DLOG operations", | ||
175 | delta.rel_value_us / 1000LL / TEST_ITER, | ||
176 | "ms/op"); | ||
177 | |||
178 | GNUNET_CRYPTO_ecc_dlog_release (edc); | ||
179 | return 0; | ||
180 | } | ||
181 | |||
182 | |||
183 | /* end of perf_crypto_ecc_dlog.c */ | ||