mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-26 11:13:23 -03:00
Merge pull request #95
79ad6d4
Remove some dead variables in the tests. (Gregory Maxwell)9974d86
Misc. Warning and cosmetic error cleanups. (Gregory Maxwell)
This commit is contained in:
commit
ef6f677679
2 changed files with 13 additions and 15 deletions
24
src/tests.c
24
src/tests.c
|
@ -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);
|
||||
|
@ -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));
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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));
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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();
|
||||
|
|
|
@ -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. */
|
||||
|
|
Loading…
Add table
Reference in a new issue