summaryrefslogtreecommitdiff
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.c161
1 files changed, 82 insertions, 79 deletions
diff --git a/src/util/perf_crypto_ecc_dlog.c b/src/util/perf_crypto_ecc_dlog.c
index b09a6ed6f..106b07026 100644
--- a/src/util/perf_crypto_ecc_dlog.c
+++ b/src/util/perf_crypto_ecc_dlog.c
@@ -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,99 @@ 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))
87 { 93 {
88 fprintf(stderr, "."); 94 gcry_mpi_set_ui (fact, x);
89 x = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, 95 gcry_mpi_sub (fact, n, fact);
90 MAX_FACT); 96 x = -x;
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 {
108 fprintf(stderr,
109 "DLOG failed for value %d (%d)\n",
110 x,
111 iret);
112 GNUNET_assert(0);
113 }
114 } 97 }
115 gcry_mpi_release(fact); 98 else
116 gcry_mpi_release(n); 99 {
117 gcry_mpi_point_release(g); 100 gcry_mpi_set_ui (fact, x);
118 gcry_mpi_point_release(q); 101 }
119 gcry_ctx_release(ctx); 102 gcry_mpi_ec_mul (q, fact, g, ctx);
120 fprintf(stderr, "\n"); 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 }
114 }
115 gcry_mpi_release (fact);
116 gcry_mpi_release (n);
117 gcry_mpi_point_release (g);
118 gcry_mpi_point_release (q);
119 gcry_ctx_release (ctx);
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 (
136 "1.6.0"); 136 "libgcrypt has not the expected version (version %s is required).\n"),
137 return 0; 137 "1.6.0");
138 } 138 return 0;
139 if (getenv("GNUNET_GCRYPT_DEBUG")) 139 }
140 gcry_control(GCRYCTL_SET_DEBUG_FLAGS, 1u, 0); 140 if (getenv ("GNUNET_GCRYPT_DEBUG"))
141 GNUNET_log_setup("perf-crypto-ecc-dlog", 141 gcry_control (GCRYCTL_SET_DEBUG_FLAGS, 1u, 0);
142 "WARNING", 142 GNUNET_log_setup ("perf-crypto-ecc-dlog",
143 NULL); 143 "WARNING",
144 start = GNUNET_TIME_absolute_get(); 144 NULL);
145 edc = GNUNET_CRYPTO_ecc_dlog_prepare(MAX_FACT, 145 start = GNUNET_TIME_absolute_get ();
146 MAX_MEM); 146 edc = GNUNET_CRYPTO_ecc_dlog_prepare (MAX_FACT,
147 printf("DLOG precomputation 1M/1K took %s\n", 147 MAX_MEM);
148 GNUNET_STRINGS_relative_time_to_string(GNUNET_TIME_absolute_get_duration(start), 148 printf ("DLOG precomputation 1M/1K took %s\n",
149 GNUNET_YES)); 149 GNUNET_STRINGS_relative_time_to_string (
150 GAUGER("UTIL", "ECC DLOG initialization", 150 GNUNET_TIME_absolute_get_duration (start),
151 GNUNET_TIME_absolute_get_duration 151 GNUNET_YES));
152 (start).rel_value_us / 1000LL, "ms/op"); 152 GAUGER ("UTIL", "ECC DLOG initialization",
153 start = GNUNET_TIME_absolute_get(); 153 GNUNET_TIME_absolute_get_duration
154 (start).rel_value_us / 1000LL, "ms/op");
155 start = GNUNET_TIME_absolute_get ();
154 /* first do a baseline run without the DLOG */ 156 /* first do a baseline run without the DLOG */
155 test_dlog(edc, GNUNET_NO); 157 test_dlog (edc, GNUNET_NO);
156 delta = GNUNET_TIME_absolute_get_duration(start); 158 delta = GNUNET_TIME_absolute_get_duration (start);
157 start = GNUNET_TIME_absolute_get(); 159 start = GNUNET_TIME_absolute_get ();
158 test_dlog(edc, GNUNET_YES); 160 test_dlog (edc, GNUNET_YES);
159 delta = GNUNET_TIME_relative_subtract(GNUNET_TIME_absolute_get_duration(start), 161 delta = GNUNET_TIME_relative_subtract (GNUNET_TIME_absolute_get_duration (
160 delta); 162 start),
161 printf("%u DLOG calculations took %s\n", 163 delta);
162 TEST_ITER, 164 printf ("%u DLOG calculations took %s\n",
163 GNUNET_STRINGS_relative_time_to_string(delta, 165 TEST_ITER,
164 GNUNET_YES)); 166 GNUNET_STRINGS_relative_time_to_string (delta,
165 GAUGER("UTIL", "ECC DLOG operations", 167 GNUNET_YES));
166 delta.rel_value_us / 1000LL / TEST_ITER, 168 GAUGER ("UTIL", "ECC DLOG operations",
167 "ms/op"); 169 delta.rel_value_us / 1000LL / TEST_ITER,
168 170 "ms/op");
169 GNUNET_CRYPTO_ecc_dlog_release(edc); 171
172 GNUNET_CRYPTO_ecc_dlog_release (edc);
170 return 0; 173 return 0;
171} 174}
172 175