I managed to get it to compile in Visual Studio. 32bit right now because 64bit OpenSSL seems to be giving me some linker trouble (_ prefix on the BN_* functions). Haven't had the time to look at that yet.
We can only appeal to spia to make a version without openssl/gmp dependencies, which would be just perfect.
I'm trying to verify the correctness of a secret key (basically, check if not zero and below a certain number, as can be seen in the Satoshi client) using this library, specifically, this function:
/** Verify an ECDSA secret key.
* Returns: 1: secret key is valid
* 0: secret key is invalid
* In: seckey: pointer to a 32-byte secret key
*/
int secp256k1_ecdsa_seckey_verify(const unsigned char *seckey) {
secp256k1_num_t sec;
secp256k1_num_init(&sec);
secp256k1_num_set_bin(&sec, seckey, 32);
int ret = secp256k1_num_is_zero(&sec) ||
(secp256k1_num_cmp(&sec, &secp256k1_ge_consts->order) >= 0);
secp256k1_num_free(&sec);
return ret;
}
Please note, in all functions in this library, 0 == bad, 1 == good.
I'm finding three issues. The first one is, secp256k1_num_is_zero returns 1 if it's zero, else, it returns 0.
In the comment above, it states that 1 == valid. So it should be doing !secp256k1_num_is_zero(&sec).
Second, it's doing an ||, but both tests should be 1, so that should be &&.
And third, he &sec is compared to &secp256k1_ge_consts->order (which is the same as the upper bound number in the Satoshi client, it's basically doing a > b, and then testing if a (&sec) is larger or equal to b. But it should be doing ... < 0 at the end, since a should be less than b.
It looks like the whole thing is inverted and the return value should be 0 == good an 1 == bad.