diff --git a/Makefile.am b/Makefile.am index 0e413cb3eb9..a9df7d50469 100644 --- a/Makefile.am +++ b/Makefile.am @@ -46,7 +46,7 @@ noinst_PROGRAMS = if USE_BENCHMARK noinst_PROGRAMS += bench bench_SOURCES = src/bench.c -bench_LDADD = libsecp256k1_common.la $(SECP_LIBS) +bench_LDADD = libsecp256k1.la $(SECP_LIBS) bench_LDFLAGS = -static endif diff --git a/src/bench.c b/src/bench.c index a7e2eed5af7..b7ff4a6f4c6 100644 --- a/src/bench.c +++ b/src/bench.c @@ -4,61 +4,24 @@ #include -#include "num_impl.h" -#include "field_impl.h" -#include "group_impl.h" -#include "ecmult_impl.h" -#include "ecdsa_impl.h" +#include "include/secp256k1.h" #include "util_impl.h" -void random_num_order(secp256k1_num_t *num) { - do { - unsigned char b32[32]; - secp256k1_rand256(b32); - secp256k1_num_set_bin(num, b32, 32); - if (secp256k1_num_is_zero(num)) - continue; - if (secp256k1_num_cmp(num, &secp256k1_ge_consts->order) >= 0) - continue; - break; - } while(1); -} - int main() { - secp256k1_fe_start(); - secp256k1_ge_start(); - secp256k1_ecmult_start(); + secp256k1_start(SECP256K1_START_VERIFY); - secp256k1_fe_t x; - const secp256k1_num_t *order = &secp256k1_ge_consts->order; - secp256k1_num_t r, s, m; - secp256k1_num_init(&r); - secp256k1_num_init(&s); - secp256k1_num_init(&m); - secp256k1_ecdsa_sig_t sig; - secp256k1_ecdsa_sig_init(&sig); - secp256k1_fe_set_hex(&x, "a357ae915c4a65281309edf20504740f0eb3343990216b4f81063cb65f2f7e0f", 64); - int cnt = 0; int good = 0; + unsigned char pubkey[33] = {0x02,0x1f,0x98,0xb7,0x3c,0xbd,0xd4,0x06,0xf3,0x49,0xa9,0x6c,0x2d,0xcb,0x7a,0xf7,0x01,0xe0,0xbd,0x07,0xdf,0xe9,0x17,0xae,0x0e,0x43,0x85,0x63,0xf0,0xff,0x7b,0xab,0x2f}; for (int i=0; i<1000000; i++) { - random_num_order(&r); - random_num_order(&s); - random_num_order(&m); - secp256k1_ecdsa_sig_set_rs(&sig, &r, &s); - secp256k1_ge_t pubkey; secp256k1_ge_set_xo(&pubkey, &x, 1); - if (secp256k1_ge_is_valid(&pubkey)) { - cnt++; - good += secp256k1_ecdsa_sig_verify(&sig, &pubkey, &m); - } - } - printf("%i/%i\n", good, cnt); - secp256k1_num_free(&r); - secp256k1_num_free(&s); - secp256k1_num_free(&m); - secp256k1_ecdsa_sig_free(&sig); + unsigned char msg[32]; + secp256k1_rand256(msg); + unsigned char sig[72] = {0x30, 0x44, 0x02, 0x20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x02, 0x20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; + secp256k1_rand256(sig + 4); + secp256k1_rand256(sig + 38); + good += secp256k1_ecdsa_verify(msg, 32, sig, 72, pubkey, 33); + } + printf("%i\n", good); - secp256k1_ecmult_stop(); - secp256k1_ge_stop(); - secp256k1_fe_stop(); + secp256k1_stop(); return 0; }