diff options
author | Theo Buehler <tb@cvs.openbsd.org> | 2018-11-05 23:50:06 +0000 |
---|---|---|
committer | Theo Buehler <tb@cvs.openbsd.org> | 2018-11-05 23:50:06 +0000 |
commit | cb53f3e5d83bf758ed5d2369d6fc26bb307fd14a (patch) | |
tree | a254d9ff5310525f047b2743ce96666e83c8c4bd /lib | |
parent | 36b29cbae60cfbe22aab6c159f407e26fe98d353 (diff) |
Eliminate a few "} else" branches, a few unneeded NULL checks before
freeing and indent nearby labels.
ok beck jsing
Diffstat (limited to 'lib')
-rw-r--r-- | lib/libcrypto/dh/dh_key.c | 28 | ||||
-rw-r--r-- | lib/libcrypto/dsa/dsa_key.c | 20 | ||||
-rw-r--r-- | lib/libcrypto/ec/ec_key.c | 28 |
3 files changed, 33 insertions, 43 deletions
diff --git a/lib/libcrypto/dh/dh_key.c b/lib/libcrypto/dh/dh_key.c index dd3a3af3abc..2cbf128d80a 100644 --- a/lib/libcrypto/dh/dh_key.c +++ b/lib/libcrypto/dh/dh_key.c @@ -1,4 +1,4 @@ -/* $OpenBSD: dh_key.c,v 1.30 2018/11/05 23:46:16 tb Exp $ */ +/* $OpenBSD: dh_key.c,v 1.31 2018/11/05 23:50:05 tb Exp $ */ /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * @@ -106,7 +106,7 @@ generate_key(DH *dh) unsigned l; BN_CTX *ctx; BN_MONT_CTX *mont = NULL; - BIGNUM *pub_key = NULL, *priv_key = NULL; + BIGNUM *pub_key = dh->pub_key, *priv_key = dh->priv_key; if (BN_num_bits(dh->p) > OPENSSL_DH_MAX_MODULUS_BITS) { DHerror(DH_R_MODULUS_TOO_LARGE); @@ -117,20 +117,16 @@ generate_key(DH *dh) if (ctx == NULL) goto err; - if (dh->priv_key == NULL) { - priv_key = BN_new(); - if (priv_key == NULL) + if (priv_key == NULL) { + if ((priv_key = BN_new()) == NULL) goto err; generate_new_key = 1; - } else - priv_key = dh->priv_key; + } - if (dh->pub_key == NULL) { - pub_key = BN_new(); - if (pub_key == NULL) + if (pub_key == NULL) { + if ((pub_key = BN_new()) == NULL) goto err; - } else - pub_key = dh->pub_key; + } if (dh->flags & DH_FLAG_CACHE_MONT_P) { mont = BN_MONT_CTX_set_locked(&dh->method_mont_p, @@ -160,13 +156,13 @@ generate_key(DH *dh) dh->pub_key = pub_key; dh->priv_key = priv_key; ok = 1; -err: + err: if (ok != 1) DHerror(ERR_R_BN_LIB); - if (pub_key != NULL && dh->pub_key == NULL) + if (dh->pub_key == NULL) BN_free(pub_key); - if (priv_key != NULL && dh->priv_key == NULL) + if (dh->priv_key == NULL) BN_free(priv_key); BN_CTX_free(ctx); return ok; @@ -220,7 +216,7 @@ compute_key(unsigned char *key, const BIGNUM *pub_key, DH *dh) } ret = BN_bn2bin(tmp, key); -err: + err: if (ctx != NULL) { BN_CTX_end(ctx); BN_CTX_free(ctx); diff --git a/lib/libcrypto/dsa/dsa_key.c b/lib/libcrypto/dsa/dsa_key.c index b2d08e5e0ca..520b9809834 100644 --- a/lib/libcrypto/dsa/dsa_key.c +++ b/lib/libcrypto/dsa/dsa_key.c @@ -1,4 +1,4 @@ -/* $OpenBSD: dsa_key.c,v 1.24 2018/11/05 23:46:16 tb Exp $ */ +/* $OpenBSD: dsa_key.c,v 1.25 2018/11/05 23:50:05 tb Exp $ */ /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * @@ -82,27 +82,25 @@ dsa_builtin_keygen(DSA *dsa) { int ok = 0; BN_CTX *ctx = NULL; - BIGNUM *pub_key = NULL, *priv_key = NULL; + BIGNUM *pub_key = dsa->pub_key, *priv_key = dsa->priv_key; if ((ctx = BN_CTX_new()) == NULL) goto err; - if (dsa->priv_key == NULL) { + if (priv_key == NULL) { if ((priv_key = BN_new()) == NULL) goto err; - } else - priv_key=dsa->priv_key; + } do { if (!BN_rand_range(priv_key, dsa->q)) goto err; } while (BN_is_zero(priv_key)); - if (dsa->pub_key == NULL) { + if (pub_key == NULL) { if ((pub_key = BN_new()) == NULL) goto err; - } else - pub_key=dsa->pub_key; + } if (!BN_mod_exp_ct(pub_key, dsa->g, priv_key, dsa->p, ctx)) goto err; @@ -111,10 +109,10 @@ dsa_builtin_keygen(DSA *dsa) dsa->pub_key = pub_key; ok = 1; -err: - if (pub_key != NULL && dsa->pub_key == NULL) + err: + if (dsa->pub_key == NULL) BN_free(pub_key); - if (priv_key != NULL && dsa->priv_key == NULL) + if (dsa->priv_key == NULL) BN_free(priv_key); BN_CTX_free(ctx); return ok; diff --git a/lib/libcrypto/ec/ec_key.c b/lib/libcrypto/ec/ec_key.c index d1b8e8fcc1c..966ebab4a55 100644 --- a/lib/libcrypto/ec/ec_key.c +++ b/lib/libcrypto/ec/ec_key.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ec_key.c,v 1.17 2018/07/15 16:27:39 tb Exp $ */ +/* $OpenBSD: ec_key.c,v 1.18 2018/11/05 23:50:05 tb Exp $ */ /* * Written by Nils Larsch for the OpenSSL project. */ @@ -207,12 +207,12 @@ EC_KEY_up_ref(EC_KEY * r) } int -EC_KEY_generate_key(EC_KEY * eckey) +EC_KEY_generate_key(EC_KEY *eckey) { int ok = 0; BN_CTX *ctx = NULL; - BIGNUM *priv_key = NULL, *order = NULL; - EC_POINT *pub_key = NULL; + BIGNUM *priv_key = eckey->priv_key, *order = NULL; + EC_POINT *pub_key = eckey->pub_key; if (!eckey || !eckey->group) { ECerror(ERR_R_PASSED_NULL_PARAMETER); @@ -223,12 +223,10 @@ EC_KEY_generate_key(EC_KEY * eckey) if ((ctx = BN_CTX_new()) == NULL) goto err; - if (eckey->priv_key == NULL) { - priv_key = BN_new(); - if (priv_key == NULL) + if (priv_key == NULL) { + if ((priv_key = BN_new()) == NULL) goto err; - } else - priv_key = eckey->priv_key; + } if (!EC_GROUP_get_order(eckey->group, order, ctx)) goto err; @@ -238,12 +236,10 @@ EC_KEY_generate_key(EC_KEY * eckey) goto err; while (BN_is_zero(priv_key)); - if (eckey->pub_key == NULL) { - pub_key = EC_POINT_new(eckey->group); - if (pub_key == NULL) + if (pub_key == NULL) { + if ((pub_key = EC_POINT_new(eckey->group)) == NULL) goto err; - } else - pub_key = eckey->pub_key; + } if (!EC_POINT_mul(eckey->group, pub_key, priv_key, NULL, NULL, ctx)) goto err; @@ -255,9 +251,9 @@ EC_KEY_generate_key(EC_KEY * eckey) err: BN_free(order); - if (pub_key != NULL && eckey->pub_key == NULL) + if (eckey->pub_key == NULL) EC_POINT_free(pub_key); - if (priv_key != NULL && eckey->priv_key == NULL) + if (eckey->priv_key == NULL) BN_free(priv_key); BN_CTX_free(ctx); return (ok); |