mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-03-16 18:39:59 +01:00
Fifth step in converting to C: ecdsa
This commit is contained in:
@@ -6,8 +6,6 @@
|
||||
#include "ecmult.cpp"
|
||||
#include "ecdsa.cpp"
|
||||
|
||||
using namespace secp256k1;
|
||||
|
||||
int main() {
|
||||
secp256k1_num_start();
|
||||
secp256k1_fe_start();
|
||||
@@ -20,7 +18,8 @@ int main() {
|
||||
secp256k1_num_init(&r);
|
||||
secp256k1_num_init(&s);
|
||||
secp256k1_num_init(&m);
|
||||
Signature sig;
|
||||
secp256k1_ecdsa_sig_t sig;
|
||||
secp256k1_ecdsa_sig_init(&sig);
|
||||
secp256k1_fe_set_hex(&x, "a357ae915c4a65281309edf20504740f0eb3343990216b4f81063cb65f2f7e0f", 64);
|
||||
int cnt = 0;
|
||||
int good = 0;
|
||||
@@ -28,17 +27,18 @@ int main() {
|
||||
secp256k1_num_set_rand(&r, order);
|
||||
secp256k1_num_set_rand(&s, order);
|
||||
secp256k1_num_set_rand(&m, order);
|
||||
sig.SetRS(r,s);
|
||||
secp256k1_ecdsa_sig_set_rs(&sig, &r, &s);
|
||||
secp256k1_gej_t pubkey; secp256k1_gej_set_xo(&pubkey, &x, 1);
|
||||
if (secp256k1_gej_is_valid(&pubkey)) {
|
||||
cnt++;
|
||||
good += sig.Verify(pubkey, m);
|
||||
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);
|
||||
|
||||
secp256k1_ecmult_stop();
|
||||
secp256k1_ge_stop();
|
||||
|
||||
Reference in New Issue
Block a user