0
0
Fork 0
mirror of https://github.com/bitcoin/bitcoin.git synced 2025-02-04 10:07:27 -05:00
bitcoin-bitcoin-core/src/secp256k1.cpp

39 lines
868 B
C++
Raw Normal View History

2013-03-16 15:51:55 +01:00
#include "num.cpp"
#include "field.cpp"
#include "group.cpp"
#include "ecmult.cpp"
#include "ecdsa.cpp"
namespace secp256k1 {
int VerifyECDSA(const unsigned char *msg, int msglen, const unsigned char *sig, int siglen, const unsigned char *pubkey, int pubkeylen) {
2013-03-24 10:38:35 +01:00
int ret = -3;
secp256k1_num_t m;
secp256k1_num_init(&m);
2013-03-16 15:51:55 +01:00
Signature s;
GroupElemJac q;
2013-03-24 10:38:35 +01:00
secp256k1_num_set_bin(&m, msg, msglen);
if (!ParsePubKey(q, pubkey, pubkeylen)) {
ret = -1;
goto end;
}
2013-03-16 15:51:55 +01:00
if (!s.Parse(sig, siglen)) {
fprintf(stderr, "Can't parse signature: ");
for (int i=0; i<siglen; i++) fprintf(stderr,"%02x", sig[i]);
fprintf(stderr, "\n");
2013-03-24 10:38:35 +01:00
ret = -2;
goto end;
}
if (!s.Verify(q, m)) {
ret = 0;
goto end;
2013-03-16 15:51:55 +01:00
}
2013-03-24 10:38:35 +01:00
ret = 1;
end:
secp256k1_num_free(&m);
return ret;
2013-03-16 15:51:55 +01:00
}
2013-03-18 02:41:01 +01:00
2013-03-24 10:38:35 +01:00
}