From b183b4112249215cd1bc439a77b23416a37e0282 Mon Sep 17 00:00:00 2001 From: Cory Fields Date: Tue, 1 Sep 2015 14:22:32 -0400 Subject: [PATCH] bugfix: "ARG_CHECK(ctx != NULL)" makes no sense Move all context checks to VERIFY_CHECK and be sure they come before all ARG_CHECKs. --- src/modules/recovery/main_impl.h | 4 ++-- src/modules/schnorr/main_impl.h | 10 +++++----- src/secp256k1.c | 20 ++++++++++---------- 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/modules/recovery/main_impl.h b/src/modules/recovery/main_impl.h index aa6f9a5198f..b76b831fdac 100644 --- a/src/modules/recovery/main_impl.h +++ b/src/modules/recovery/main_impl.h @@ -90,7 +90,7 @@ int secp256k1_ecdsa_sign_recoverable(const secp256k1_context_t* ctx, const unsig int ret = 0; int overflow = 0; unsigned int count = 0; - ARG_CHECK(ctx != NULL); + VERIFY_CHECK(ctx != NULL); ARG_CHECK(secp256k1_ecmult_gen_context_is_built(&ctx->ecmult_gen_ctx)); ARG_CHECK(msg32 != NULL); ARG_CHECK(signature != NULL); @@ -135,7 +135,7 @@ int secp256k1_ecdsa_recover(const secp256k1_context_t* ctx, const unsigned char secp256k1_scalar_t r, s; secp256k1_scalar_t m; int recid; - ARG_CHECK(ctx != NULL); + VERIFY_CHECK(ctx != NULL); ARG_CHECK(secp256k1_ecmult_context_is_built(&ctx->ecmult_ctx)); ARG_CHECK(msg32 != NULL); ARG_CHECK(signature != NULL); diff --git a/src/modules/schnorr/main_impl.h b/src/modules/schnorr/main_impl.h index f5250bffd09..de5a4d4cccb 100644 --- a/src/modules/schnorr/main_impl.h +++ b/src/modules/schnorr/main_impl.h @@ -24,7 +24,7 @@ int secp256k1_schnorr_sign(const secp256k1_context_t* ctx, const unsigned char * int ret = 0; int overflow = 0; unsigned int count = 0; - ARG_CHECK(ctx != NULL); + VERIFY_CHECK(ctx != NULL); ARG_CHECK(secp256k1_ecmult_gen_context_is_built(&ctx->ecmult_gen_ctx)); ARG_CHECK(msg32 != NULL); ARG_CHECK(sig64 != NULL); @@ -59,7 +59,7 @@ int secp256k1_schnorr_sign(const secp256k1_context_t* ctx, const unsigned char * int secp256k1_schnorr_verify(const secp256k1_context_t* ctx, const unsigned char *msg32, const unsigned char *sig64, const secp256k1_pubkey_t *pubkey) { secp256k1_ge_t q; - ARG_CHECK(ctx != NULL); + VERIFY_CHECK(ctx != NULL); ARG_CHECK(secp256k1_ecmult_context_is_built(&ctx->ecmult_ctx)); ARG_CHECK(msg32 != NULL); ARG_CHECK(sig64 != NULL); @@ -72,7 +72,7 @@ int secp256k1_schnorr_verify(const secp256k1_context_t* ctx, const unsigned char int secp256k1_schnorr_recover(const secp256k1_context_t* ctx, const unsigned char *msg32, const unsigned char *sig64, secp256k1_pubkey_t *pubkey) { secp256k1_ge_t q; - ARG_CHECK(ctx != NULL); + VERIFY_CHECK(ctx != NULL); ARG_CHECK(secp256k1_ecmult_context_is_built(&ctx->ecmult_ctx)); ARG_CHECK(msg32 != NULL); ARG_CHECK(sig64 != NULL); @@ -94,7 +94,7 @@ int secp256k1_schnorr_generate_nonce_pair(const secp256k1_context_t* ctx, const secp256k1_ge_t Q; secp256k1_scalar_t sec; - ARG_CHECK(ctx != NULL); + VERIFY_CHECK(ctx != NULL); ARG_CHECK(secp256k1_ecmult_gen_context_is_built(&ctx->ecmult_gen_ctx)); ARG_CHECK(msg32 != NULL); ARG_CHECK(sec32 != NULL); @@ -133,7 +133,7 @@ int secp256k1_schnorr_partial_sign(const secp256k1_context_t* ctx, const unsigne int overflow = 0; secp256k1_scalar_t sec, non; secp256k1_ge_t pubnon; - ARG_CHECK(ctx != NULL); + VERIFY_CHECK(ctx != NULL); ARG_CHECK(secp256k1_ecmult_gen_context_is_built(&ctx->ecmult_gen_ctx)); ARG_CHECK(msg32 != NULL); ARG_CHECK(sig64 != NULL); diff --git a/src/secp256k1.c b/src/secp256k1.c index 26eb7d93c0e..f4089bb7514 100644 --- a/src/secp256k1.c +++ b/src/secp256k1.c @@ -211,7 +211,7 @@ int secp256k1_ecdsa_verify(const secp256k1_context_t* ctx, const unsigned char * secp256k1_ge_t q; secp256k1_scalar_t r, s; secp256k1_scalar_t m; - ARG_CHECK(ctx != NULL); + VERIFY_CHECK(ctx != NULL); ARG_CHECK(secp256k1_ecmult_context_is_built(&ctx->ecmult_ctx)); ARG_CHECK(msg32 != NULL); ARG_CHECK(sig != NULL); @@ -263,7 +263,7 @@ int secp256k1_ecdsa_sign(const secp256k1_context_t* ctx, const unsigned char *ms int ret = 0; int overflow = 0; unsigned int count = 0; - ARG_CHECK(ctx != NULL); + VERIFY_CHECK(ctx != NULL); ARG_CHECK(secp256k1_ecmult_gen_context_is_built(&ctx->ecmult_gen_ctx)); ARG_CHECK(msg32 != NULL); ARG_CHECK(signature != NULL); @@ -307,7 +307,7 @@ int secp256k1_ec_seckey_verify(const secp256k1_context_t* ctx, const unsigned ch secp256k1_scalar_t sec; int ret; int overflow; - ARG_CHECK(ctx != NULL); + VERIFY_CHECK(ctx != NULL); ARG_CHECK(seckey != NULL); (void)ctx; @@ -323,7 +323,7 @@ int secp256k1_ec_pubkey_create(const secp256k1_context_t* ctx, secp256k1_pubkey_ secp256k1_scalar_t sec; int overflow; int ret = 0; - ARG_CHECK(ctx != NULL); + VERIFY_CHECK(ctx != NULL); ARG_CHECK(secp256k1_ecmult_gen_context_is_built(&ctx->ecmult_gen_ctx)); ARG_CHECK(pubkey != NULL); ARG_CHECK(seckey != NULL); @@ -345,7 +345,7 @@ int secp256k1_ec_privkey_tweak_add(const secp256k1_context_t* ctx, unsigned char secp256k1_scalar_t sec; int ret = 0; int overflow = 0; - ARG_CHECK(ctx != NULL); + VERIFY_CHECK(ctx != NULL); ARG_CHECK(seckey != NULL); ARG_CHECK(tweak != NULL); (void)ctx; @@ -368,7 +368,7 @@ int secp256k1_ec_pubkey_tweak_add(const secp256k1_context_t* ctx, secp256k1_pubk secp256k1_scalar_t term; int ret = 0; int overflow = 0; - ARG_CHECK(ctx != NULL); + VERIFY_CHECK(ctx != NULL); ARG_CHECK(secp256k1_ecmult_context_is_built(&ctx->ecmult_ctx)); ARG_CHECK(pubkey != NULL); ARG_CHECK(tweak != NULL); @@ -391,7 +391,7 @@ int secp256k1_ec_privkey_tweak_mul(const secp256k1_context_t* ctx, unsigned char secp256k1_scalar_t sec; int ret = 0; int overflow = 0; - ARG_CHECK(ctx != NULL); + VERIFY_CHECK(ctx != NULL); ARG_CHECK(seckey != NULL); ARG_CHECK(tweak != NULL); (void)ctx; @@ -413,7 +413,7 @@ int secp256k1_ec_pubkey_tweak_mul(const secp256k1_context_t* ctx, secp256k1_pubk secp256k1_scalar_t factor; int ret = 0; int overflow = 0; - ARG_CHECK(ctx != NULL); + VERIFY_CHECK(ctx != NULL); ARG_CHECK(secp256k1_ecmult_context_is_built(&ctx->ecmult_ctx)); ARG_CHECK(pubkey != NULL); ARG_CHECK(tweak != NULL); @@ -434,10 +434,10 @@ int secp256k1_ec_pubkey_tweak_mul(const secp256k1_context_t* ctx, secp256k1_pubk int secp256k1_ec_privkey_export(const secp256k1_context_t* ctx, const unsigned char *seckey, unsigned char *privkey, int *privkeylen, int compressed) { secp256k1_scalar_t key; int ret = 0; + VERIFY_CHECK(ctx != NULL); ARG_CHECK(seckey != NULL); ARG_CHECK(privkey != NULL); ARG_CHECK(privkeylen != NULL); - ARG_CHECK(ctx != NULL); ARG_CHECK(secp256k1_ecmult_gen_context_is_built(&ctx->ecmult_gen_ctx)); secp256k1_scalar_set_b32(&key, seckey, NULL); @@ -462,7 +462,7 @@ int secp256k1_ec_privkey_import(const secp256k1_context_t* ctx, unsigned char *s } int secp256k1_context_randomize(secp256k1_context_t* ctx, const unsigned char *seed32) { - ARG_CHECK(ctx != NULL); + VERIFY_CHECK(ctx != NULL); ARG_CHECK(secp256k1_ecmult_gen_context_is_built(&ctx->ecmult_gen_ctx)); secp256k1_ecmult_gen_blind(&ctx->ecmult_gen_ctx, seed32); return 1;