Make bench use external interface

pull/11871/head
Pieter Wuille 10 years ago
parent b00982fdbd
commit bae6a42be4

@ -46,7 +46,7 @@ noinst_PROGRAMS =
if USE_BENCHMARK if USE_BENCHMARK
noinst_PROGRAMS += bench noinst_PROGRAMS += bench
bench_SOURCES = src/bench.c bench_SOURCES = src/bench.c
bench_LDADD = libsecp256k1_common.la $(SECP_LIBS) bench_LDADD = libsecp256k1.la $(SECP_LIBS)
bench_LDFLAGS = -static bench_LDFLAGS = -static
endif endif

@ -4,61 +4,24 @@
#include <stdio.h> #include <stdio.h>
#include "num_impl.h" #include "include/secp256k1.h"
#include "field_impl.h"
#include "group_impl.h"
#include "ecmult_impl.h"
#include "ecdsa_impl.h"
#include "util_impl.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() { int main() {
secp256k1_fe_start(); secp256k1_start(SECP256K1_START_VERIFY);
secp256k1_ge_start();
secp256k1_ecmult_start();
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; 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++) { for (int i=0; i<1000000; i++) {
random_num_order(&r); unsigned char msg[32];
random_num_order(&s); secp256k1_rand256(msg);
random_num_order(&m); 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_ecdsa_sig_set_rs(&sig, &r, &s); secp256k1_rand256(sig + 4);
secp256k1_ge_t pubkey; secp256k1_ge_set_xo(&pubkey, &x, 1); secp256k1_rand256(sig + 38);
if (secp256k1_ge_is_valid(&pubkey)) { good += secp256k1_ecdsa_verify(msg, 32, sig, 72, pubkey, 33);
cnt++;
good += secp256k1_ecdsa_sig_verify(&sig, &pubkey, &m);
}
} }
printf("%i/%i\n", good, cnt); printf("%i\n", good);
secp256k1_num_free(&r);
secp256k1_num_free(&s);
secp256k1_num_free(&m);
secp256k1_ecdsa_sig_free(&sig);
secp256k1_ecmult_stop(); secp256k1_stop();
secp256k1_ge_stop();
secp256k1_fe_stop();
return 0; return 0;
} }

Loading…
Cancel
Save