mirror of
https://github.com/openssl/openssl.git
synced 2025-01-18 13:44:20 +08:00
Use NULL comparison
Reviewed-by: Richard Levitte <levitte@openssl.org>
This commit is contained in:
parent
7bb75a5d08
commit
91e7bcc264
@ -1314,9 +1314,9 @@ IMPLEMENT_ASN1_FUNCTIONS_const(ECDSA_SIG)
|
||||
|
||||
void ECDSA_SIG_get0(BIGNUM **pr, BIGNUM **ps, ECDSA_SIG *sig)
|
||||
{
|
||||
if (pr)
|
||||
if (pr != NULL)
|
||||
*pr = sig->r;
|
||||
if (ps)
|
||||
if (ps != NULL)
|
||||
*ps = sig->s;
|
||||
}
|
||||
|
||||
|
@ -84,7 +84,8 @@ EC_KEY *EC_KEY_new_by_curve_name(int nid)
|
||||
EC_KEY_free(ret);
|
||||
return NULL;
|
||||
}
|
||||
if (ret->meth->set_group && ret->meth->set_group(ret, ret->group) == 0) {
|
||||
if (ret->meth->set_group != NULL
|
||||
&& ret->meth->set_group(ret, ret->group) == 0) {
|
||||
EC_KEY_free(ret);
|
||||
return NULL;
|
||||
}
|
||||
@ -111,11 +112,11 @@ void EC_KEY_free(EC_KEY *r)
|
||||
}
|
||||
#endif
|
||||
|
||||
if (r->meth->finish)
|
||||
if (r->meth->finish != NULL)
|
||||
r->meth->finish(r);
|
||||
|
||||
#ifndef OPENSSL_NO_ENGINE
|
||||
if (r->engine)
|
||||
if (r->engine != NULL)
|
||||
ENGINE_finish(r->engine);
|
||||
#endif
|
||||
|
||||
@ -137,16 +138,16 @@ EC_KEY *EC_KEY_copy(EC_KEY *dest, const EC_KEY *src)
|
||||
return NULL;
|
||||
}
|
||||
if (src->meth != dest->meth) {
|
||||
if (dest->meth->finish)
|
||||
if (dest->meth->finish != NULL)
|
||||
dest->meth->finish(dest);
|
||||
#ifndef OPENSSL_NO_ENGINE
|
||||
if (dest->engine && ENGINE_finish(dest->engine) == 0)
|
||||
if (dest->engine != NULL && ENGINE_finish(dest->engine) == 0)
|
||||
return 0;
|
||||
dest->engine = NULL;
|
||||
#endif
|
||||
}
|
||||
/* copy the parameters */
|
||||
if (src->group) {
|
||||
if (src->group != NULL) {
|
||||
const EC_METHOD *meth = EC_GROUP_method_of(src->group);
|
||||
/* clear the old group */
|
||||
EC_GROUP_free(dest->group);
|
||||
@ -157,7 +158,7 @@ EC_KEY *EC_KEY_copy(EC_KEY *dest, const EC_KEY *src)
|
||||
return NULL;
|
||||
}
|
||||
/* copy the public key */
|
||||
if (src->pub_key && src->group) {
|
||||
if (src->pub_key != NULL && src->group != NULL) {
|
||||
EC_POINT_free(dest->pub_key);
|
||||
dest->pub_key = EC_POINT_new(src->group);
|
||||
if (dest->pub_key == NULL)
|
||||
@ -166,7 +167,7 @@ EC_KEY *EC_KEY_copy(EC_KEY *dest, const EC_KEY *src)
|
||||
return NULL;
|
||||
}
|
||||
/* copy the private key */
|
||||
if (src->priv_key) {
|
||||
if (src->priv_key != NULL) {
|
||||
if (dest->priv_key == NULL) {
|
||||
dest->priv_key = BN_new();
|
||||
if (dest->priv_key == NULL)
|
||||
@ -186,7 +187,7 @@ EC_KEY *EC_KEY_copy(EC_KEY *dest, const EC_KEY *src)
|
||||
if (!EC_EX_DATA_set_data
|
||||
(&dest->method_data, t, d->dup_func, d->free_func,
|
||||
d->clear_free_func))
|
||||
return 0;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* copy the rest */
|
||||
@ -197,15 +198,15 @@ EC_KEY *EC_KEY_copy(EC_KEY *dest, const EC_KEY *src)
|
||||
|
||||
if (src->meth != dest->meth) {
|
||||
#ifndef OPENSSL_NO_ENGINE
|
||||
if (src->engine && ENGINE_init(src->engine) == 0)
|
||||
return 0;
|
||||
if (src->engine != NULL && ENGINE_init(src->engine) == 0)
|
||||
return NULL;
|
||||
dest->engine = src->engine;
|
||||
#endif
|
||||
dest->meth = src->meth;
|
||||
}
|
||||
|
||||
if (src->meth->copy && src->meth->copy(dest, src) == 0)
|
||||
return 0;
|
||||
if (src->meth->copy != NULL && src->meth->copy(dest, src) == 0)
|
||||
return NULL;
|
||||
|
||||
return dest;
|
||||
}
|
||||
@ -239,11 +240,11 @@ int EC_KEY_up_ref(EC_KEY *r)
|
||||
|
||||
int EC_KEY_generate_key(EC_KEY *eckey)
|
||||
{
|
||||
if (!eckey || !eckey->group) {
|
||||
if (eckey == NULL || eckey->group == NULL) {
|
||||
ECerr(EC_F_EC_KEY_GENERATE_KEY, ERR_R_PASSED_NULL_PARAMETER);
|
||||
return 0;
|
||||
}
|
||||
if (eckey->meth->keygen)
|
||||
if (eckey->meth->keygen != NULL)
|
||||
return eckey->meth->keygen(eckey);
|
||||
ECerr(EC_F_EC_KEY_GENERATE_KEY, EC_R_OPERATION_NOT_SUPPORTED);
|
||||
return 0;
|
||||
@ -308,7 +309,7 @@ int EC_KEY_check_key(const EC_KEY *eckey)
|
||||
const BIGNUM *order = NULL;
|
||||
EC_POINT *point = NULL;
|
||||
|
||||
if (!eckey || !eckey->group || !eckey->pub_key) {
|
||||
if (eckey == NULL || eckey->group == NULL || eckey->pub_key == NULL) {
|
||||
ECerr(EC_F_EC_KEY_CHECK_KEY, ERR_R_PASSED_NULL_PARAMETER);
|
||||
return 0;
|
||||
}
|
||||
@ -346,7 +347,7 @@ int EC_KEY_check_key(const EC_KEY *eckey)
|
||||
* in case the priv_key is present : check if generator * priv_key ==
|
||||
* pub_key
|
||||
*/
|
||||
if (eckey->priv_key) {
|
||||
if (eckey->priv_key != NULL) {
|
||||
if (BN_cmp(eckey->priv_key, order) >= 0) {
|
||||
ECerr(EC_F_EC_KEY_CHECK_KEY, EC_R_WRONG_ORDER);
|
||||
goto err;
|
||||
@ -379,7 +380,7 @@ int EC_KEY_set_public_key_affine_coordinates(EC_KEY *key, BIGNUM *x,
|
||||
int tmp_nid, is_char_two = 0;
|
||||
#endif
|
||||
|
||||
if (!key || !key->group || !x || !y) {
|
||||
if (key == NULL || key->group == NULL || x == NULL || y == NULL) {
|
||||
ECerr(EC_F_EC_KEY_SET_PUBLIC_KEY_AFFINE_COORDINATES,
|
||||
ERR_R_PASSED_NULL_PARAMETER);
|
||||
return 0;
|
||||
@ -453,7 +454,7 @@ const EC_GROUP *EC_KEY_get0_group(const EC_KEY *key)
|
||||
|
||||
int EC_KEY_set_group(EC_KEY *key, const EC_GROUP *group)
|
||||
{
|
||||
if (key->meth->set_group && key->meth->set_group(key, group) == 0)
|
||||
if (key->meth->set_group != NULL && key->meth->set_group(key, group) == 0)
|
||||
return 0;
|
||||
EC_GROUP_free(key->group);
|
||||
key->group = EC_GROUP_dup(group);
|
||||
@ -467,7 +468,8 @@ const BIGNUM *EC_KEY_get0_private_key(const EC_KEY *key)
|
||||
|
||||
int EC_KEY_set_private_key(EC_KEY *key, const BIGNUM *priv_key)
|
||||
{
|
||||
if (key->meth->set_private && key->meth->set_private(key, priv_key) == 0)
|
||||
if (key->meth->set_private != NULL
|
||||
&& key->meth->set_private(key, priv_key) == 0)
|
||||
return 0;
|
||||
BN_clear_free(key->priv_key);
|
||||
key->priv_key = BN_dup(priv_key);
|
||||
@ -481,7 +483,8 @@ const EC_POINT *EC_KEY_get0_public_key(const EC_KEY *key)
|
||||
|
||||
int EC_KEY_set_public_key(EC_KEY *key, const EC_POINT *pub_key)
|
||||
{
|
||||
if (key->meth->set_public && key->meth->set_public(key, pub_key) == 0)
|
||||
if (key->meth->set_public != NULL
|
||||
&& key->meth->set_public(key, pub_key) == 0)
|
||||
return 0;
|
||||
EC_POINT_free(key->pub_key);
|
||||
key->pub_key = EC_POINT_dup(pub_key, key->group);
|
||||
|
@ -103,7 +103,7 @@ EC_KEY *EC_KEY_new_method(ENGINE *engine)
|
||||
}
|
||||
ret->meth = EC_KEY_get_default_method();
|
||||
#ifndef OPENSSL_NO_ENGINE
|
||||
if (engine) {
|
||||
if (engine != NULL) {
|
||||
if (!ENGINE_init(engine)) {
|
||||
ECerr(EC_F_EC_KEY_NEW_METHOD, ERR_R_ENGINE_LIB);
|
||||
OPENSSL_free(ret);
|
||||
@ -112,9 +112,9 @@ EC_KEY *EC_KEY_new_method(ENGINE *engine)
|
||||
ret->engine = engine;
|
||||
} else
|
||||
ret->engine = ENGINE_get_default_EC();
|
||||
if (ret->engine) {
|
||||
if (ret->engine != NULL) {
|
||||
ret->meth = ENGINE_get_EC(ret->engine);
|
||||
if (!ret->meth) {
|
||||
if (ret->meth == NULL) {
|
||||
ECerr(EC_F_EC_KEY_NEW_METHOD, ERR_R_ENGINE_LIB);
|
||||
ENGINE_finish(ret->engine);
|
||||
OPENSSL_free(ret);
|
||||
@ -126,7 +126,7 @@ EC_KEY *EC_KEY_new_method(ENGINE *engine)
|
||||
ret->version = 1;
|
||||
ret->conv_form = POINT_CONVERSION_UNCOMPRESSED;
|
||||
ret->references = 1;
|
||||
if (ret->meth->init && ret->meth->init(ret) == 0) {
|
||||
if (ret->meth->init != NULL && ret->meth->init(ret) == 0) {
|
||||
EC_KEY_free(ret);
|
||||
return NULL;
|
||||
}
|
||||
@ -138,7 +138,7 @@ int ECDH_compute_key(void *out, size_t outlen, const EC_POINT *pub_key,
|
||||
void *(*KDF) (const void *in, size_t inlen, void *out,
|
||||
size_t *outlen))
|
||||
{
|
||||
if (eckey->meth->compute_key)
|
||||
if (eckey->meth->compute_key != NULL)
|
||||
return eckey->meth->compute_key(out, outlen, pub_key, eckey, KDF);
|
||||
ECerr(EC_F_ECDH_COMPUTE_KEY, EC_R_OPERATION_NOT_SUPPORTED);
|
||||
return 0;
|
||||
@ -150,7 +150,7 @@ EC_KEY_METHOD *EC_KEY_METHOD_new(const EC_KEY_METHOD *meth)
|
||||
ret = OPENSSL_zalloc(sizeof(*meth));
|
||||
if (ret == NULL)
|
||||
return NULL;
|
||||
if (meth)
|
||||
if (meth != NULL)
|
||||
*ret = *meth;
|
||||
ret->flags |= EC_KEY_METHOD_DYNAMIC;
|
||||
return ret;
|
||||
|
@ -365,7 +365,7 @@ int ossl_ecdsa_verify(int type, const unsigned char *dgst, int dgst_len,
|
||||
goto err;
|
||||
/* Ensure signature uses DER and doesn't have trailing garbage */
|
||||
derlen = i2d_ECDSA_SIG(s, &der);
|
||||
if (derlen != sig_len || memcmp(sigbuf, der, derlen))
|
||||
if (derlen != sig_len || memcmp(sigbuf, der, derlen) != 0)
|
||||
goto err;
|
||||
ret = ECDSA_do_verify(dgst, dgst_len, s, eckey);
|
||||
err:
|
||||
@ -402,7 +402,7 @@ int ossl_ecdsa_verify_sig(const unsigned char *dgst, int dgst_len,
|
||||
u2 = BN_CTX_get(ctx);
|
||||
m = BN_CTX_get(ctx);
|
||||
X = BN_CTX_get(ctx);
|
||||
if (!X) {
|
||||
if (X == NULL) {
|
||||
ECerr(EC_F_OSSL_ECDSA_VERIFY_SIG, ERR_R_BN_LIB);
|
||||
goto err;
|
||||
}
|
||||
|
@ -70,7 +70,7 @@ ECDSA_SIG *ECDSA_do_sign_ex(const unsigned char *dgst, int dlen,
|
||||
const BIGNUM *kinv, const BIGNUM *rp,
|
||||
EC_KEY *eckey)
|
||||
{
|
||||
if (eckey->meth->sign_sig)
|
||||
if (eckey->meth->sign_sig != NULL)
|
||||
return eckey->meth->sign_sig(dgst, dlen, kinv, rp, eckey);
|
||||
ECerr(EC_F_ECDSA_DO_SIGN_EX, EC_R_OPERATION_NOT_SUPPORTED);
|
||||
return NULL;
|
||||
@ -86,7 +86,7 @@ int ECDSA_sign_ex(int type, const unsigned char *dgst, int dlen,
|
||||
unsigned char *sig, unsigned int *siglen, const BIGNUM *kinv,
|
||||
const BIGNUM *r, EC_KEY *eckey)
|
||||
{
|
||||
if (eckey->meth->sign)
|
||||
if (eckey->meth->sign != NULL)
|
||||
return eckey->meth->sign(type, dgst, dlen, sig, siglen, kinv, r, eckey);
|
||||
ECerr(EC_F_ECDSA_SIGN_EX, EC_R_OPERATION_NOT_SUPPORTED);
|
||||
return 0;
|
||||
@ -95,7 +95,7 @@ int ECDSA_sign_ex(int type, const unsigned char *dgst, int dlen,
|
||||
int ECDSA_sign_setup(EC_KEY *eckey, BN_CTX *ctx_in, BIGNUM **kinvp,
|
||||
BIGNUM **rp)
|
||||
{
|
||||
if (eckey->meth->sign_setup)
|
||||
if (eckey->meth->sign_setup != NULL)
|
||||
return eckey->meth->sign_setup(eckey, ctx_in, kinvp, rp);
|
||||
ECerr(EC_F_ECDSA_SIGN_SETUP, EC_R_OPERATION_NOT_SUPPORTED);
|
||||
return 0;
|
||||
|
@ -73,7 +73,7 @@
|
||||
int ECDSA_do_verify(const unsigned char *dgst, int dgst_len,
|
||||
const ECDSA_SIG *sig, EC_KEY *eckey)
|
||||
{
|
||||
if (eckey->meth->verify_sig)
|
||||
if (eckey->meth->verify_sig != NULL)
|
||||
return eckey->meth->verify_sig(dgst, dgst_len, sig, eckey);
|
||||
ECerr(EC_F_ECDSA_DO_VERIFY, EC_R_OPERATION_NOT_SUPPORTED);
|
||||
return 0;
|
||||
@ -88,10 +88,9 @@ int ECDSA_do_verify(const unsigned char *dgst, int dgst_len,
|
||||
int ECDSA_verify(int type, const unsigned char *dgst, int dgst_len,
|
||||
const unsigned char *sigbuf, int sig_len, EC_KEY *eckey)
|
||||
{
|
||||
if (eckey->meth->verify)
|
||||
if (eckey->meth->verify != NULL)
|
||||
return eckey->meth->verify(type, dgst, dgst_len, sigbuf, sig_len,
|
||||
eckey);
|
||||
ECerr(EC_F_ECDSA_VERIFY, EC_R_OPERATION_NOT_SUPPORTED);
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
@ -76,7 +76,7 @@ static void engine_unregister_all_EC(void)
|
||||
|
||||
int ENGINE_register_EC(ENGINE *e)
|
||||
{
|
||||
if (e->ec_meth)
|
||||
if (e->ec_meth != NULL)
|
||||
return engine_table_register(&dh_table,
|
||||
engine_unregister_all_EC, e, &dummy_nid,
|
||||
1, 0);
|
||||
@ -93,7 +93,7 @@ void ENGINE_register_all_EC()
|
||||
|
||||
int ENGINE_set_default_EC(ENGINE *e)
|
||||
{
|
||||
if (e->ec_meth)
|
||||
if (e->ec_meth != NULL)
|
||||
return engine_table_register(&dh_table,
|
||||
engine_unregister_all_EC, e, &dummy_nid,
|
||||
1, 1);
|
||||
|
Loading…
Reference in New Issue
Block a user