Skip to content

Commit

Permalink
Merge pull request bitcoin#95
Browse files Browse the repository at this point in the history
79ad6d4 Remove some dead variables in the tests. (Gregory Maxwell)
9974d86 Misc. Warning and cosmetic error cleanups. (Gregory Maxwell)
  • Loading branch information
sipa committed Nov 5, 2014
2 parents 985fd63 + 79ad6d4 commit ef6f677
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 15 deletions.
24 changes: 11 additions & 13 deletions src/tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -673,7 +673,6 @@ void random_sign(secp256k1_ecdsa_sig_t *sig, const secp256k1_scalar_t *key, cons
}

void test_ecdsa_sign_verify() {
const secp256k1_ge_consts_t *c = secp256k1_ge_consts;
secp256k1_scalar_t msg, key;
random_scalar_order_test(&msg);
random_scalar_order_test(&key);
Expand Down Expand Up @@ -709,7 +708,7 @@ void test_ecdsa_end_to_end() {

// Construct and verify corresponding public key.
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_verify(pubkey, pubkeylen));

Expand All @@ -728,7 +727,7 @@ void test_ecdsa_end_to_end() {
int ret2 = secp256k1_ec_pubkey_tweak_add(pubkey, pubkeylen, rnd);
CHECK(ret1 == ret2);
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(memcmp(pubkey, pubkey2, pubkeylen) == 0);
}
Expand All @@ -741,13 +740,13 @@ void test_ecdsa_end_to_end() {
int ret2 = secp256k1_ec_pubkey_tweak_mul(pubkey, pubkeylen, rnd);
CHECK(ret1 == ret2);
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(memcmp(pubkey, pubkey2, pubkeylen) == 0);
}

// Sign.
unsigned char signature[72]; unsigned int signaturelen = 72;
unsigned char signature[72]; int signaturelen = 72;
while(1) {
unsigned char rnd[32];
secp256k1_rand256_test(rnd);
Expand All @@ -762,7 +761,7 @@ void test_ecdsa_end_to_end() {
CHECK(secp256k1_ecdsa_verify(message, 32, signature, signaturelen, pubkey, pubkeylen) != 1);

// Compact sign.
unsigned char csignature[64]; unsigned int recid = 0;
unsigned char csignature[64]; int recid = 0;
while(1) {
unsigned char rnd[32];
secp256k1_rand256_test(rnd);
Expand All @@ -771,7 +770,7 @@ void test_ecdsa_end_to_end() {
}
}
// 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(recpubkeylen == pubkeylen);
CHECK(memcmp(pubkey, recpubkey, pubkeylen) == 0);
Expand Down Expand Up @@ -804,7 +803,6 @@ EC_KEY *get_openssl_key(const secp256k1_scalar_t *key) {
}

void test_ecdsa_openssl() {
const secp256k1_ge_consts_t *c = secp256k1_ge_consts;
secp256k1_scalar_t key, msg;
unsigned char message[32];
secp256k1_rand256_test(message);
Expand All @@ -817,7 +815,7 @@ void test_ecdsa_openssl() {
EC_KEY *ec_key = get_openssl_key(&key);
CHECK(ec_key);
unsigned char signature[80];
int sigsize = 80;
unsigned int sigsize = 80;
CHECK(ECDSA_sign(0, message, sizeof(message), signature, &sigsize, ec_key));
secp256k1_ecdsa_sig_t sig;
CHECK(secp256k1_ecdsa_sig_parse(&sig, signature, sigsize));
Expand All @@ -828,9 +826,9 @@ void test_ecdsa_openssl() {
CHECK(!secp256k1_ecdsa_sig_verify(&sig, &q, &msg_num));

random_sign(&sig, &key, &msg, NULL);
sigsize = 80;
CHECK(secp256k1_ecdsa_sig_serialize(signature, &sigsize, &sig));
CHECK(ECDSA_verify(0, message, sizeof(message), signature, sigsize, ec_key) == 1);
int secp_sigsize = 80;
CHECK(secp256k1_ecdsa_sig_serialize(signature, &secp_sigsize, &sig));
CHECK(ECDSA_verify(0, message, sizeof(message), signature, secp_sigsize, ec_key) == 1);

EC_KEY_free(ec_key);
}
Expand Down Expand Up @@ -893,7 +891,7 @@ int main(int argc, char **argv) {
run_ecdsa_openssl();
#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
secp256k1_stop();
Expand Down
4 changes: 2 additions & 2 deletions src/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@
#ifndef NDEBUG
#define DEBUG_CHECK CHECK
#else
#define DEBUG_CHECK(cond) do { (cond); } while(0)
#define DEBUG_CHECK(cond) do { (void)(cond); } while(0)
#endif

// Like DEBUG_CHECK(), but when VERIFY is defined instead of NDEBUG not defined.
#ifdef VERIFY
#define VERIFY_CHECK CHECK
#else
#define VERIFY_CHECK(cond) do { (cond); } while(0)
#define VERIFY_CHECK(cond) do { (void)(cond); } while(0)
#endif

/** Seed the pseudorandom number generator. */
Expand Down

0 comments on commit ef6f677

Please sign in to comment.