|
11 | 11 | #include "util.h"
|
12 | 12 | #include "bench.h"
|
13 | 13 |
|
| 14 | +void help(int default_iters) { |
| 15 | + printf("Benchmarks the following algorithms:\n"); |
| 16 | + printf(" - ECDSA signing/verification\n"); |
| 17 | + |
| 18 | +#ifdef ENABLE_MODULE_ECDH |
| 19 | + printf(" - ECDH key exchange (optional module)\n"); |
| 20 | +#endif |
| 21 | + |
| 22 | +#ifdef ENABLE_MODULE_RECOVERY |
| 23 | + printf(" - Public key recovery (optional module)\n"); |
| 24 | +#endif |
| 25 | + |
| 26 | +#ifdef ENABLE_MODULE_SCHNORRSIG |
| 27 | + printf(" - Schnorr signatures (optional module)\n"); |
| 28 | +#endif |
| 29 | + |
| 30 | + printf("\n"); |
| 31 | + printf("The default number of iterations for each benchmark is %d. This can be\n", default_iters); |
| 32 | + printf("customized using the SECP256K1_BENCH_ITERS environment variable.\n"); |
| 33 | + printf("\n"); |
| 34 | + printf("Usage: ./bench [args]\n"); |
| 35 | + printf("By default, all benchmarks will be run.\n"); |
| 36 | + printf("args:\n"); |
| 37 | + printf(" help : display this help and exit\n"); |
| 38 | + printf(" ecdsa : all ECDSA algorithms--sign, verify, recovery (if enabled)\n"); |
| 39 | + printf(" ecdsa_sign : ECDSA siging algorithm\n"); |
| 40 | + printf(" ecdsa_verify : ECDSA verification algorithm\n"); |
| 41 | + |
| 42 | +#ifdef ENABLE_MODULE_RECOVERY |
| 43 | + printf(" ecdsa_recover : ECDSA public key recovery algorithm\n"); |
| 44 | +#endif |
| 45 | + |
| 46 | +#ifdef ENABLE_MODULE_ECDH |
| 47 | + printf(" ecdh : ECDH key exchange algorithm\n"); |
| 48 | +#endif |
| 49 | + |
| 50 | +#ifdef ENABLE_MODULE_SCHNORRSIG |
| 51 | + printf(" schnorrsig : all Schnorr signature algorithms (sign, verify)\n"); |
| 52 | + printf(" schnorrsig_sign : Schnorr sigining algorithm\n"); |
| 53 | + printf(" schnorrsig_verify : Schnorr verification algorithm\n"); |
| 54 | +#endif |
| 55 | + |
| 56 | + printf("\n"); |
| 57 | +} |
| 58 | + |
14 | 59 | typedef struct {
|
15 | 60 | secp256k1_context *ctx;
|
16 | 61 | unsigned char msg[32];
|
@@ -95,7 +140,52 @@ int main(int argc, char** argv) {
|
95 | 140 | bench_verify_data data;
|
96 | 141 |
|
97 | 142 | int d = argc == 1;
|
98 |
| - int iters = get_iters(20000); |
| 143 | + int default_iters = 20000; |
| 144 | + int iters = get_iters(default_iters); |
| 145 | + |
| 146 | + /* Check for invalid user arguments */ |
| 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]); |
| 150 | + int invalid_args = have_invalid_args(argc, argv, valid_args, valid_args_size); |
| 151 | + |
| 152 | + if (argc > 1) { |
| 153 | + if (have_flag(argc, argv, "-h") |
| 154 | + || have_flag(argc, argv, "--help") |
| 155 | + || have_flag(argc, argv, "help")) { |
| 156 | + help(default_iters); |
| 157 | + return 0; |
| 158 | + } else if (invalid_args) { |
| 159 | + fprintf(stderr, "./bench: unrecognized argument.\n\n"); |
| 160 | + help(default_iters); |
| 161 | + return 1; |
| 162 | + } |
| 163 | + } |
| 164 | + |
| 165 | +/* Check if the user tries to benchmark optional module without building it */ |
| 166 | +#ifndef ENABLE_MODULE_ECDH |
| 167 | + if (have_flag(argc, argv, "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 |
| 175 | + if (have_flag(argc, argv, "recover") || have_flag(argc, argv, "ecdsa_recover")) { |
| 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 |
| 183 | + if (have_flag(argc, argv, "schnorrsig") || have_flag(argc, argv, "schnorrsig_sign") || have_flag(argc, argv, "schnorrsig_verify")) { |
| 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 |
99 | 189 |
|
100 | 190 | /* ECDSA verification benchmark */
|
101 | 191 | data.ctx = secp256k1_context_create(SECP256K1_CONTEXT_SIGN | SECP256K1_CONTEXT_VERIFY);
|
|
0 commit comments