diff options
| author | tb <> | 2018-11-05 23:50:05 +0000 |
|---|---|---|
| committer | tb <> | 2018-11-05 23:50:05 +0000 |
| commit | 8e9f1d9b90e9437962a4af66f58e24dd9fa2c0c7 (patch) | |
| tree | 1e04cc34be4d65b95be7fd1dc42660ff4e7b6580 /src/lib/libcrypto/dsa/dsa_key.c | |
| parent | d84e997e985b21f7846260ada232d4d74b349e3e (diff) | |
| download | openbsd-8e9f1d9b90e9437962a4af66f58e24dd9fa2c0c7.tar.gz openbsd-8e9f1d9b90e9437962a4af66f58e24dd9fa2c0c7.tar.bz2 openbsd-8e9f1d9b90e9437962a4af66f58e24dd9fa2c0c7.zip | |
Eliminate a few "} else" branches, a few unneeded NULL checks before
freeing and indent nearby labels.
ok beck jsing
Diffstat (limited to 'src/lib/libcrypto/dsa/dsa_key.c')
| -rw-r--r-- | src/lib/libcrypto/dsa/dsa_key.c | 20 |
1 files changed, 9 insertions, 11 deletions
diff --git a/src/lib/libcrypto/dsa/dsa_key.c b/src/lib/libcrypto/dsa/dsa_key.c index b2d08e5e0c..520b980983 100644 --- a/src/lib/libcrypto/dsa/dsa_key.c +++ b/src/lib/libcrypto/dsa/dsa_key.c | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: dsa_key.c,v 1.24 2018/11/05 23:46:16 tb Exp $ */ | 1 | /* $OpenBSD: dsa_key.c,v 1.25 2018/11/05 23:50:05 tb Exp $ */ |
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) |
| 3 | * All rights reserved. | 3 | * All rights reserved. |
| 4 | * | 4 | * |
| @@ -82,27 +82,25 @@ dsa_builtin_keygen(DSA *dsa) | |||
| 82 | { | 82 | { |
| 83 | int ok = 0; | 83 | int ok = 0; |
| 84 | BN_CTX *ctx = NULL; | 84 | BN_CTX *ctx = NULL; |
| 85 | BIGNUM *pub_key = NULL, *priv_key = NULL; | 85 | BIGNUM *pub_key = dsa->pub_key, *priv_key = dsa->priv_key; |
| 86 | 86 | ||
| 87 | if ((ctx = BN_CTX_new()) == NULL) | 87 | if ((ctx = BN_CTX_new()) == NULL) |
| 88 | goto err; | 88 | goto err; |
| 89 | 89 | ||
| 90 | if (dsa->priv_key == NULL) { | 90 | if (priv_key == NULL) { |
| 91 | if ((priv_key = BN_new()) == NULL) | 91 | if ((priv_key = BN_new()) == NULL) |
| 92 | goto err; | 92 | goto err; |
| 93 | } else | 93 | } |
| 94 | priv_key=dsa->priv_key; | ||
| 95 | 94 | ||
| 96 | do { | 95 | do { |
| 97 | if (!BN_rand_range(priv_key, dsa->q)) | 96 | if (!BN_rand_range(priv_key, dsa->q)) |
| 98 | goto err; | 97 | goto err; |
| 99 | } while (BN_is_zero(priv_key)); | 98 | } while (BN_is_zero(priv_key)); |
| 100 | 99 | ||
| 101 | if (dsa->pub_key == NULL) { | 100 | if (pub_key == NULL) { |
| 102 | if ((pub_key = BN_new()) == NULL) | 101 | if ((pub_key = BN_new()) == NULL) |
| 103 | goto err; | 102 | goto err; |
| 104 | } else | 103 | } |
| 105 | pub_key=dsa->pub_key; | ||
| 106 | 104 | ||
| 107 | if (!BN_mod_exp_ct(pub_key, dsa->g, priv_key, dsa->p, ctx)) | 105 | if (!BN_mod_exp_ct(pub_key, dsa->g, priv_key, dsa->p, ctx)) |
| 108 | goto err; | 106 | goto err; |
| @@ -111,10 +109,10 @@ dsa_builtin_keygen(DSA *dsa) | |||
| 111 | dsa->pub_key = pub_key; | 109 | dsa->pub_key = pub_key; |
| 112 | ok = 1; | 110 | ok = 1; |
| 113 | 111 | ||
| 114 | err: | 112 | err: |
| 115 | if (pub_key != NULL && dsa->pub_key == NULL) | 113 | if (dsa->pub_key == NULL) |
| 116 | BN_free(pub_key); | 114 | BN_free(pub_key); |
| 117 | if (priv_key != NULL && dsa->priv_key == NULL) | 115 | if (dsa->priv_key == NULL) |
| 118 | BN_free(priv_key); | 116 | BN_free(priv_key); |
| 119 | BN_CTX_free(ctx); | 117 | BN_CTX_free(ctx); |
| 120 | return ok; | 118 | return ok; |
