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
|
|
|
}
|