136 {
137 int i;
141
143 int default_iters = 20000;
145
146
147 char* valid_args[] = {"ecdsa", "verify", "ecdsa_verify", "sign", "ecdsa_sign", "ecdh", "recover",
148 "ecdsa_recover", "schnorrsig", "schnorrsig_verify", "schnorrsig_sign"};
149 size_t valid_args_size = sizeof(valid_args)/sizeof(valid_args[0]);
151
152 if (argc > 1) {
157 return 0;
158 } else if (invalid_args) {
159 fprintf(stderr, "./bench: unrecognized argument.\n\n");
161 return 1;
162 }
163 }
164
165
166#ifndef ENABLE_MODULE_ECDH
168 fprintf(stderr, "./bench: ECDH module not enabled.\n");
169 fprintf(stderr, "Use ./configure --enable-module-ecdh.\n\n");
170 return 1;
171 }
172#endif
173
174#ifndef ENABLE_MODULE_RECOVERY
176 fprintf(stderr, "./bench: Public key recovery module not enabled.\n");
177 fprintf(stderr, "Use ./configure --enable-module-recovery.\n\n");
178 return 1;
179 }
180#endif
181
182#ifndef ENABLE_MODULE_SCHNORRSIG
184 fprintf(stderr, "./bench: Schnorr signatures module not enabled.\n");
185 fprintf(stderr, "Use ./configure --enable-module-schnorrsig.\n\n");
186 return 1;
187 }
188#endif
189
190
192
193 for (i = 0; i < 32; i++) {
194 data.msg[i] = 1 + i;
195 }
196 for (i = 0; i < 32; i++) {
197 data.key[i] = 33 + i;
198 }
199 data.siglen = 72;
203 data.pubkeylen = 33;
205
207 if (d ||
have_flag(argc,
argv,
"ecdsa") ||
have_flag(argc,
argv,
"verify") ||
have_flag(argc,
argv,
"ecdsa_verify"))
run_benchmark(
"ecdsa_verify", bench_verify, NULL, NULL, &data, 10, iters);
208
210
211
213
214 if (d ||
have_flag(argc,
argv,
"ecdsa") ||
have_flag(argc,
argv,
"sign") ||
have_flag(argc,
argv,
"ecdsa_sign"))
run_benchmark(
"ecdsa_sign", bench_sign_run, bench_sign_setup, NULL, &data, 10, iters);
215
217
218#ifdef ENABLE_MODULE_ECDH
219
221#endif
222
223#ifdef ENABLE_MODULE_RECOVERY
224
226#endif
227
228#ifdef ENABLE_MODULE_SCHNORRSIG
229
231#endif
232
233 return 0;
234}
void help(int default_iters)
void print_output_table_header_row(void)
int have_flag(int argc, char **argv, char *flag)
int get_iters(int default_iters)
int have_invalid_args(int argc, char **argv, char **valid_args, size_t n)
void run_benchmark(char *name, void(*benchmark)(void *, int), void(*setup)(void *), void(*teardown)(void *, int), void *data, int count, int iter)
void run_ecdh_bench(int iters, int argc, char **argv)
void run_recovery_bench(int iters, int argc, char **argv)
void run_schnorrsig_bench(int iters, int argc, char **argv)
SECP256K1_API void secp256k1_context_destroy(secp256k1_context *ctx) SECP256K1_ARG_NONNULL(1)
#define SECP256K1_CONTEXT_SIGN
SECP256K1_API int secp256k1_ec_pubkey_serialize(const secp256k1_context *ctx, unsigned char *output, size_t *outputlen, const secp256k1_pubkey *pubkey, unsigned int flags) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(4)
SECP256K1_API secp256k1_context * secp256k1_context_create(unsigned int flags) SECP256K1_WARN_UNUSED_RESULT
SECP256K1_API int secp256k1_ecdsa_sign(const secp256k1_context *ctx, secp256k1_ecdsa_signature *sig, const unsigned char *msghash32, const unsigned char *seckey, secp256k1_nonce_function noncefp, const void *ndata) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(4)
SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_ec_pubkey_create(const secp256k1_context *ctx, secp256k1_pubkey *pubkey, const unsigned char *seckey) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3)
#define SECP256K1_EC_COMPRESSED
SECP256K1_API int secp256k1_ecdsa_signature_serialize_der(const secp256k1_context *ctx, unsigned char *output, size_t *outputlen, const secp256k1_ecdsa_signature *sig) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(4)
#define SECP256K1_CONTEXT_VERIFY