mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-14 22:02:37 -03:00
Misc. Warning and cosmetic error cleanups.
This fixes a cosmetic precedence bug in the tests along with some type warnings. It also adds a dummy cast to the CHECK macro to avoid hundreds of statement with no effect warnings on compilers that warn about such things.
This commit is contained in:
parent
0ce80ef47e
commit
9974d8693e
2 changed files with 13 additions and 13 deletions
22
src/tests.c
22
src/tests.c
|
@ -701,7 +701,7 @@ void test_ecdsa_end_to_end() {
|
||||||
|
|
||||||
// Construct and verify corresponding public key.
|
// Construct and verify corresponding public key.
|
||||||
CHECK(secp256k1_ec_seckey_verify(privkey) == 1);
|
CHECK(secp256k1_ec_seckey_verify(privkey) == 1);
|
||||||
char pubkey[65]; int pubkeylen = 65;
|
unsigned char pubkey[65]; int pubkeylen = 65;
|
||||||
CHECK(secp256k1_ec_pubkey_create(pubkey, &pubkeylen, privkey, secp256k1_rand32() % 2) == 1);
|
CHECK(secp256k1_ec_pubkey_create(pubkey, &pubkeylen, privkey, secp256k1_rand32() % 2) == 1);
|
||||||
CHECK(secp256k1_ec_pubkey_verify(pubkey, pubkeylen));
|
CHECK(secp256k1_ec_pubkey_verify(pubkey, pubkeylen));
|
||||||
|
|
||||||
|
@ -720,7 +720,7 @@ void test_ecdsa_end_to_end() {
|
||||||
int ret2 = secp256k1_ec_pubkey_tweak_add(pubkey, pubkeylen, rnd);
|
int ret2 = secp256k1_ec_pubkey_tweak_add(pubkey, pubkeylen, rnd);
|
||||||
CHECK(ret1 == ret2);
|
CHECK(ret1 == ret2);
|
||||||
if (ret1 == 0) return;
|
if (ret1 == 0) return;
|
||||||
char pubkey2[65]; int pubkeylen2 = 65;
|
unsigned char pubkey2[65]; int pubkeylen2 = 65;
|
||||||
CHECK(secp256k1_ec_pubkey_create(pubkey2, &pubkeylen2, privkey, pubkeylen == 33) == 1);
|
CHECK(secp256k1_ec_pubkey_create(pubkey2, &pubkeylen2, privkey, pubkeylen == 33) == 1);
|
||||||
CHECK(memcmp(pubkey, pubkey2, pubkeylen) == 0);
|
CHECK(memcmp(pubkey, pubkey2, pubkeylen) == 0);
|
||||||
}
|
}
|
||||||
|
@ -733,13 +733,13 @@ void test_ecdsa_end_to_end() {
|
||||||
int ret2 = secp256k1_ec_pubkey_tweak_mul(pubkey, pubkeylen, rnd);
|
int ret2 = secp256k1_ec_pubkey_tweak_mul(pubkey, pubkeylen, rnd);
|
||||||
CHECK(ret1 == ret2);
|
CHECK(ret1 == ret2);
|
||||||
if (ret1 == 0) return;
|
if (ret1 == 0) return;
|
||||||
char pubkey2[65]; int pubkeylen2 = 65;
|
unsigned char pubkey2[65]; int pubkeylen2 = 65;
|
||||||
CHECK(secp256k1_ec_pubkey_create(pubkey2, &pubkeylen2, privkey, pubkeylen == 33) == 1);
|
CHECK(secp256k1_ec_pubkey_create(pubkey2, &pubkeylen2, privkey, pubkeylen == 33) == 1);
|
||||||
CHECK(memcmp(pubkey, pubkey2, pubkeylen) == 0);
|
CHECK(memcmp(pubkey, pubkey2, pubkeylen) == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sign.
|
// Sign.
|
||||||
unsigned char signature[72]; unsigned int signaturelen = 72;
|
unsigned char signature[72]; int signaturelen = 72;
|
||||||
while(1) {
|
while(1) {
|
||||||
unsigned char rnd[32];
|
unsigned char rnd[32];
|
||||||
secp256k1_rand256_test(rnd);
|
secp256k1_rand256_test(rnd);
|
||||||
|
@ -754,7 +754,7 @@ void test_ecdsa_end_to_end() {
|
||||||
CHECK(secp256k1_ecdsa_verify(message, 32, signature, signaturelen, pubkey, pubkeylen) != 1);
|
CHECK(secp256k1_ecdsa_verify(message, 32, signature, signaturelen, pubkey, pubkeylen) != 1);
|
||||||
|
|
||||||
// Compact sign.
|
// Compact sign.
|
||||||
unsigned char csignature[64]; unsigned int recid = 0;
|
unsigned char csignature[64]; int recid = 0;
|
||||||
while(1) {
|
while(1) {
|
||||||
unsigned char rnd[32];
|
unsigned char rnd[32];
|
||||||
secp256k1_rand256_test(rnd);
|
secp256k1_rand256_test(rnd);
|
||||||
|
@ -763,7 +763,7 @@ void test_ecdsa_end_to_end() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Recover.
|
// Recover.
|
||||||
unsigned char recpubkey[65]; unsigned recpubkeylen = 0;
|
unsigned char recpubkey[65]; int recpubkeylen = 0;
|
||||||
CHECK(secp256k1_ecdsa_recover_compact(message, 32, csignature, recpubkey, &recpubkeylen, pubkeylen == 33, recid) == 1);
|
CHECK(secp256k1_ecdsa_recover_compact(message, 32, csignature, recpubkey, &recpubkeylen, pubkeylen == 33, recid) == 1);
|
||||||
CHECK(recpubkeylen == pubkeylen);
|
CHECK(recpubkeylen == pubkeylen);
|
||||||
CHECK(memcmp(pubkey, recpubkey, pubkeylen) == 0);
|
CHECK(memcmp(pubkey, recpubkey, pubkeylen) == 0);
|
||||||
|
@ -809,7 +809,7 @@ void test_ecdsa_openssl() {
|
||||||
EC_KEY *ec_key = get_openssl_key(&key);
|
EC_KEY *ec_key = get_openssl_key(&key);
|
||||||
CHECK(ec_key);
|
CHECK(ec_key);
|
||||||
unsigned char signature[80];
|
unsigned char signature[80];
|
||||||
int sigsize = 80;
|
unsigned int sigsize = 80;
|
||||||
CHECK(ECDSA_sign(0, message, sizeof(message), signature, &sigsize, ec_key));
|
CHECK(ECDSA_sign(0, message, sizeof(message), signature, &sigsize, ec_key));
|
||||||
secp256k1_ecdsa_sig_t sig;
|
secp256k1_ecdsa_sig_t sig;
|
||||||
CHECK(secp256k1_ecdsa_sig_parse(&sig, signature, sigsize));
|
CHECK(secp256k1_ecdsa_sig_parse(&sig, signature, sigsize));
|
||||||
|
@ -820,9 +820,9 @@ void test_ecdsa_openssl() {
|
||||||
CHECK(!secp256k1_ecdsa_sig_verify(&sig, &q, &msg_num));
|
CHECK(!secp256k1_ecdsa_sig_verify(&sig, &q, &msg_num));
|
||||||
|
|
||||||
random_sign(&sig, &key, &msg, NULL);
|
random_sign(&sig, &key, &msg, NULL);
|
||||||
sigsize = 80;
|
int secp_sigsize = 80;
|
||||||
CHECK(secp256k1_ecdsa_sig_serialize(signature, &sigsize, &sig));
|
CHECK(secp256k1_ecdsa_sig_serialize(signature, &secp_sigsize, &sig));
|
||||||
CHECK(ECDSA_verify(0, message, sizeof(message), signature, sigsize, ec_key) == 1);
|
CHECK(ECDSA_verify(0, message, sizeof(message), signature, secp_sigsize, ec_key) == 1);
|
||||||
|
|
||||||
EC_KEY_free(ec_key);
|
EC_KEY_free(ec_key);
|
||||||
}
|
}
|
||||||
|
@ -885,7 +885,7 @@ int main(int argc, char **argv) {
|
||||||
run_ecdsa_openssl();
|
run_ecdsa_openssl();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
printf("random run = %llu\n", (unsigned long long)secp256k1_rand32() + (unsigned long long)secp256k1_rand32() << 32);
|
printf("random run = %llu\n", (unsigned long long)secp256k1_rand32() + ((unsigned long long)secp256k1_rand32() << 32));
|
||||||
|
|
||||||
// shutdown
|
// shutdown
|
||||||
secp256k1_stop();
|
secp256k1_stop();
|
||||||
|
|
|
@ -34,14 +34,14 @@
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
#define DEBUG_CHECK CHECK
|
#define DEBUG_CHECK CHECK
|
||||||
#else
|
#else
|
||||||
#define DEBUG_CHECK(cond) do { (cond); } while(0)
|
#define DEBUG_CHECK(cond) do { (void)(cond); } while(0)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Like DEBUG_CHECK(), but when VERIFY is defined instead of NDEBUG not defined.
|
// Like DEBUG_CHECK(), but when VERIFY is defined instead of NDEBUG not defined.
|
||||||
#ifdef VERIFY
|
#ifdef VERIFY
|
||||||
#define VERIFY_CHECK CHECK
|
#define VERIFY_CHECK CHECK
|
||||||
#else
|
#else
|
||||||
#define VERIFY_CHECK(cond) do { (cond); } while(0)
|
#define VERIFY_CHECK(cond) do { (void)(cond); } while(0)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/** Seed the pseudorandom number generator. */
|
/** Seed the pseudorandom number generator. */
|
||||||
|
|
Loading…
Reference in a new issue