aboutsummaryrefslogtreecommitdiff
path: root/src/util/perf_crypto_ecc_dlog.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/util/perf_crypto_ecc_dlog.c')
-rw-r--r--src/util/perf_crypto_ecc_dlog.c168
1 files changed, 84 insertions, 84 deletions
diff --git a/src/util/perf_crypto_ecc_dlog.c b/src/util/perf_crypto_ecc_dlog.c
index 2729241e2..b09a6ed6f 100644
--- a/src/util/perf_crypto_ecc_dlog.c
+++ b/src/util/perf_crypto_ecc_dlog.c
@@ -11,13 +11,13 @@
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 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/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19 19
20*/ 20 */
21/** 21/**
22 * @file util/perf_crypto_ecc_dlog.c 22 * @file util/perf_crypto_ecc_dlog.c
23 * @brief benchmark for ECC DLOG calculation 23 * @brief benchmark for ECC DLOG calculation
@@ -49,12 +49,12 @@
49 49
50/** 50/**
51 * How many values do we test? 51 * How many values do we test?
52 */ 52 */
53#define TEST_ITER 10 53#define TEST_ITER 10
54 54
55/** 55/**
56 * Range of values to use for MATH tests. 56 * Range of values to use for MATH tests.
57 */ 57 */
58#define MATH_MAX 500000 58#define MATH_MAX 500000
59 59
60 60
@@ -65,8 +65,8 @@
65 * @param do_dlog #GNUNET_YES if we want to actually do the bencharked operation 65 * @param do_dlog #GNUNET_YES if we want to actually do the bencharked operation
66 */ 66 */
67static void 67static void
68test_dlog (struct GNUNET_CRYPTO_EccDlogContext *edc, 68test_dlog(struct GNUNET_CRYPTO_EccDlogContext *edc,
69 int do_dlog) 69 int do_dlog)
70{ 70{
71 gcry_mpi_t fact; 71 gcry_mpi_t fact;
72 gcry_mpi_t n; 72 gcry_mpi_t n;
@@ -77,96 +77,96 @@ test_dlog (struct GNUNET_CRYPTO_EccDlogContext *edc,
77 int x; 77 int x;
78 int iret; 78 int iret;
79 79
80 GNUNET_assert (0 == gcry_mpi_ec_new (&ctx, NULL, CURVE)); 80 GNUNET_assert(0 == gcry_mpi_ec_new(&ctx, NULL, CURVE));
81 g = gcry_mpi_ec_get_point ("g", ctx, 0); 81 g = gcry_mpi_ec_get_point("g", ctx, 0);
82 GNUNET_assert (NULL != g); 82 GNUNET_assert(NULL != g);
83 n = gcry_mpi_ec_get_mpi ("n", ctx, 0); 83 n = gcry_mpi_ec_get_mpi("n", ctx, 0);
84 q = gcry_mpi_point_new (0); 84 q = gcry_mpi_point_new(0);
85 fact = gcry_mpi_new (0); 85 fact = gcry_mpi_new(0);
86 for (i=0;i<TEST_ITER;i++) 86 for (i = 0; i < TEST_ITER; i++)
87 {
88 fprintf (stderr, ".");
89 x = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
90 MAX_FACT);
91 if (0 == GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
92 2))
93 {
94 gcry_mpi_set_ui (fact, x);
95 gcry_mpi_sub (fact, n, fact);
96 x = - x;
97 }
98 else
99 {
100 gcry_mpi_set_ui (fact, x);
101 }
102 gcry_mpi_ec_mul (q, fact, g, ctx);
103 if ( (GNUNET_YES == do_dlog) &&
104 (x !=
105 (iret = GNUNET_CRYPTO_ecc_dlog (edc,
106 q))) )
107 { 87 {
108 fprintf (stderr, 88 fprintf(stderr, ".");
109 "DLOG failed for value %d (%d)\n", 89 x = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK,
110 x, 90 MAX_FACT);
111 iret); 91 if (0 == GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK,
112 GNUNET_assert (0); 92 2))
93 {
94 gcry_mpi_set_ui(fact, x);
95 gcry_mpi_sub(fact, n, fact);
96 x = -x;
97 }
98 else
99 {
100 gcry_mpi_set_ui(fact, x);
101 }
102 gcry_mpi_ec_mul(q, fact, g, ctx);
103 if ((GNUNET_YES == do_dlog) &&
104 (x !=
105 (iret = GNUNET_CRYPTO_ecc_dlog(edc,
106 q))))
107 {
108 fprintf(stderr,
109 "DLOG failed for value %d (%d)\n",
110 x,
111 iret);
112 GNUNET_assert(0);
113 }
113 } 114 }
114 } 115 gcry_mpi_release(fact);
115 gcry_mpi_release (fact); 116 gcry_mpi_release(n);
116 gcry_mpi_release (n); 117 gcry_mpi_point_release(g);
117 gcry_mpi_point_release (g); 118 gcry_mpi_point_release(q);
118 gcry_mpi_point_release (q); 119 gcry_ctx_release(ctx);
119 gcry_ctx_release (ctx); 120 fprintf(stderr, "\n");
120 fprintf (stderr, "\n");
121} 121}
122 122
123 123
124int 124int
125main (int argc, char *argv[]) 125main(int argc, char *argv[])
126{ 126{
127 struct GNUNET_CRYPTO_EccDlogContext *edc; 127 struct GNUNET_CRYPTO_EccDlogContext *edc;
128 struct GNUNET_TIME_Absolute start; 128 struct GNUNET_TIME_Absolute start;
129 struct GNUNET_TIME_Relative delta; 129 struct GNUNET_TIME_Relative delta;
130 130
131 if (! gcry_check_version ("1.6.0")) 131 if (!gcry_check_version("1.6.0"))
132 { 132 {
133 fprintf (stderr, 133 fprintf(stderr,
134 _ 134 _
135 ("libgcrypt has not the expected version (version %s is required).\n"), 135 ("libgcrypt has not the expected version (version %s is required).\n"),
136 "1.6.0"); 136 "1.6.0");
137 return 0; 137 return 0;
138 } 138 }
139 if (getenv ("GNUNET_GCRYPT_DEBUG")) 139 if (getenv("GNUNET_GCRYPT_DEBUG"))
140 gcry_control (GCRYCTL_SET_DEBUG_FLAGS, 1u , 0); 140 gcry_control(GCRYCTL_SET_DEBUG_FLAGS, 1u, 0);
141 GNUNET_log_setup ("perf-crypto-ecc-dlog", 141 GNUNET_log_setup("perf-crypto-ecc-dlog",
142 "WARNING", 142 "WARNING",
143 NULL); 143 NULL);
144 start = GNUNET_TIME_absolute_get (); 144 start = GNUNET_TIME_absolute_get();
145 edc = GNUNET_CRYPTO_ecc_dlog_prepare (MAX_FACT, 145 edc = GNUNET_CRYPTO_ecc_dlog_prepare(MAX_FACT,
146 MAX_MEM); 146 MAX_MEM);
147 printf ("DLOG precomputation 1M/1K took %s\n", 147 printf("DLOG precomputation 1M/1K took %s\n",
148 GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_duration (start), 148 GNUNET_STRINGS_relative_time_to_string(GNUNET_TIME_absolute_get_duration(start),
149 GNUNET_YES)); 149 GNUNET_YES));
150 GAUGER ("UTIL", "ECC DLOG initialization", 150 GAUGER("UTIL", "ECC DLOG initialization",
151 GNUNET_TIME_absolute_get_duration 151 GNUNET_TIME_absolute_get_duration
152 (start).rel_value_us / 1000LL, "ms/op"); 152 (start).rel_value_us / 1000LL, "ms/op");
153 start = GNUNET_TIME_absolute_get (); 153 start = GNUNET_TIME_absolute_get();
154 /* first do a baseline run without the DLOG */ 154 /* first do a baseline run without the DLOG */
155 test_dlog (edc, GNUNET_NO); 155 test_dlog(edc, GNUNET_NO);
156 delta = GNUNET_TIME_absolute_get_duration (start); 156 delta = GNUNET_TIME_absolute_get_duration(start);
157 start = GNUNET_TIME_absolute_get (); 157 start = GNUNET_TIME_absolute_get();
158 test_dlog (edc, GNUNET_YES); 158 test_dlog(edc, GNUNET_YES);
159 delta = GNUNET_TIME_relative_subtract (GNUNET_TIME_absolute_get_duration (start), 159 delta = GNUNET_TIME_relative_subtract(GNUNET_TIME_absolute_get_duration(start),
160 delta); 160 delta);
161 printf ("%u DLOG calculations took %s\n", 161 printf("%u DLOG calculations took %s\n",
162 TEST_ITER, 162 TEST_ITER,
163 GNUNET_STRINGS_relative_time_to_string (delta, 163 GNUNET_STRINGS_relative_time_to_string(delta,
164 GNUNET_YES)); 164 GNUNET_YES));
165 GAUGER ("UTIL", "ECC DLOG operations", 165 GAUGER("UTIL", "ECC DLOG operations",
166 delta.rel_value_us / 1000LL / TEST_ITER, 166 delta.rel_value_us / 1000LL / TEST_ITER,
167 "ms/op"); 167 "ms/op");
168 168
169 GNUNET_CRYPTO_ecc_dlog_release (edc); 169 GNUNET_CRYPTO_ecc_dlog_release(edc);
170 return 0; 170 return 0;
171} 171}
172 172