Skip to content

Commit

Permalink
Add DSA_dup() function
Browse files Browse the repository at this point in the history
  • Loading branch information
tmshort committed Dec 18, 2015
1 parent f78119f commit 83cf048
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
45 changes: 45 additions & 0 deletions crypto/dsa/dsa_lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -289,3 +289,48 @@ DH *DSA_dup_DH(const DSA *r)
return NULL;
}
#endif

DSA *DSA_dup(const DSA *dsa)
{
DSA *ret = NULL;

if (dsa == NULL)
goto err;

ret = DSA_new_method(dsa->engine);
if (ret == NULL)
goto err;

if (dsa->p != NULL)
if ((ret->p = BN_dup(dsa->p)) == NULL)
goto err;
if (dsa->q != NULL)
if ((ret->q = BN_dup(dsa->q)) == NULL)
goto err;
if (dsa->g != NULL)
if ((ret->g = BN_dup(dsa->g)) == NULL)
goto err;
if (dsa->pub_key != NULL)
if ((ret->pub_key = BN_dup(dsa->pub_key)) == NULL)
goto err;
if (dsa->priv_key != NULL)
if ((ret->priv_key = BN_dup(dsa->priv_key)) == NULL)
goto err;
if (dsa->kinv != NULL)
if ((ret->kinv = BN_dup(dsa->kinv)) == NULL)
goto err;
if (dsa->r != NULL)
if ((ret->r = BN_dup(dsa->r)) == NULL)
goto err;

if (!CRYPTO_dup_ex_data(CRYPTO_EX_INDEX_DSA, &ret->ex_data, &dsa->ex_data))
goto err;

ret->flags = dsa->flags;

return ret;

err:
DSA_free(ret);
return NULL;
}
2 changes: 2 additions & 0 deletions include/openssl/dsa.h
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,8 @@ int DSA_print_fp(FILE *bp, const DSA *x, int off);
DH *DSA_dup_DH(const DSA *r);
# endif

DSA *DSA_dup(const DSA *r);

# define EVP_PKEY_CTX_set_dsa_paramgen_bits(ctx, nbits) \
EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_DSA, EVP_PKEY_OP_PARAMGEN, \
EVP_PKEY_CTRL_DSA_PARAMGEN_BITS, nbits, NULL)
Expand Down

0 comments on commit 83cf048

Please sign in to comment.