diff options
author | Matt Caswell <matt@openssl.org> | 2016-04-06 17:49:48 +0100 |
---|---|---|
committer | Matt Caswell <matt@openssl.org> | 2016-04-09 10:10:55 +0100 |
commit | 0aeddcfa61250a6c474c4f8b3533772a63192f1b (patch) | |
tree | d8ac8b14fc1bd8a365d522a0ecf0fc9999c01575 /crypto/dsa/dsa_lib.c | |
parent | b9aec69ace2ae84b2b4494cc49725945805d5a29 (diff) |
Make DH opaque
Move the dh_st structure into an internal header file and provide
relevant accessors for the internal fields.
Reviewed-by: Richard Levitte <levitte@openssl.org>
Diffstat (limited to 'crypto/dsa/dsa_lib.c')
-rw-r--r-- | crypto/dsa/dsa_lib.c | 40 |
1 files changed, 28 insertions, 12 deletions
diff --git a/crypto/dsa/dsa_lib.c b/crypto/dsa/dsa_lib.c index 4d5281a428..0fe455703f 100644 --- a/crypto/dsa/dsa_lib.c +++ b/crypto/dsa/dsa_lib.c @@ -254,33 +254,49 @@ DH *DSA_dup_DH(const DSA *r) */ DH *ret = NULL; + BIGNUM *p = NULL, *q = NULL, *g = NULL, *pub_key = NULL, *priv_key = NULL; if (r == NULL) goto err; ret = DH_new(); if (ret == NULL) goto err; - if (r->p != NULL) - if ((ret->p = BN_dup(r->p)) == NULL) + if (r->p != NULL || r->g != NULL || r->q != NULL) { + if (r->p == NULL || r->g == NULL || r->q == NULL) { + /* Shouldn't happen */ goto err; - if (r->q != NULL) { - ret->length = BN_num_bits(r->q); - if ((ret->q = BN_dup(r->q)) == NULL) + } + p = BN_dup(r->p); + g = BN_dup(r->g); + q = BN_dup(r->q); + if (p == NULL || g == NULL || q == NULL || !DH_set0_pqg(ret, p, q, g)) goto err; } - if (r->g != NULL) - if ((ret->g = BN_dup(r->g)) == NULL) - goto err; - if (r->pub_key != NULL) - if ((ret->pub_key = BN_dup(r->pub_key)) == NULL) + + if (r->pub_key != NULL) { + pub_key = BN_dup(r->pub_key); + if (pub_key == NULL) goto err; - if (r->priv_key != NULL) - if ((ret->priv_key = BN_dup(r->priv_key)) == NULL) + if (r->priv_key != NULL) { + priv_key = BN_dup(r->priv_key); + if (priv_key == NULL) + goto err; + } + if (!DH_set0_key(ret, pub_key, priv_key)) goto err; + } else if (r->priv_key != NULL) { + /* Shouldn't happen */ + goto err; + } return ret; err: + BN_free(p); + BN_free(g); + BN_free(q); + BN_free(pub_key); + BN_free(priv_key); DH_free(ret); return NULL; } |