From: tb Date: Sun, 18 Feb 2018 14:58:12 +0000 (+0000) Subject: Provide {DH,DSA}_set0_key(). Requested by sthen. X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=1cdc303d4b8c1495368c126c56f78cf047e8c7d5;p=openbsd Provide {DH,DSA}_set0_key(). Requested by sthen. ok jsing --- diff --git a/lib/libcrypto/Symbols.list b/lib/libcrypto/Symbols.list index 77cf4399e78..b88d6c61823 100644 --- a/lib/libcrypto/Symbols.list +++ b/lib/libcrypto/Symbols.list @@ -755,6 +755,7 @@ DH_get_ex_data DH_get_ex_new_index DH_new DH_new_method +DH_set0_key DH_set0_pqg DH_set_default_method DH_set_ex_data @@ -800,6 +801,7 @@ DSA_new DSA_new_method DSA_print DSA_print_fp +DSA_set0_key DSA_set0_pqg DSA_set_default_method DSA_set_ex_data diff --git a/lib/libcrypto/dh/dh.h b/lib/libcrypto/dh/dh.h index e5daa2cbdd6..f1c51850eb5 100644 --- a/lib/libcrypto/dh/dh.h +++ b/lib/libcrypto/dh/dh.h @@ -1,4 +1,4 @@ -/* $OpenBSD: dh.h,v 1.20 2018/02/18 12:51:31 tb Exp $ */ +/* $OpenBSD: dh.h,v 1.21 2018/02/18 14:58:12 tb Exp $ */ /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * @@ -192,6 +192,7 @@ void DH_get0_pqg(const DH *dh, const BIGNUM **p, const BIGNUM **q, const BIGNUM **g); int DH_set0_pqg(DH *dh, BIGNUM *p, BIGNUM *q, BIGNUM *g); void DH_get0_key(const DH *dh, const BIGNUM **pub_key, const BIGNUM **priv_key); +int DH_set0_key(DH *dh, BIGNUM *pub_key, BIGNUM *priv_key); /* Deprecated version */ #ifndef OPENSSL_NO_DEPRECATED diff --git a/lib/libcrypto/dh/dh_lib.c b/lib/libcrypto/dh/dh_lib.c index 31857727e22..bb2ca426a0c 100644 --- a/lib/libcrypto/dh/dh_lib.c +++ b/lib/libcrypto/dh/dh_lib.c @@ -1,4 +1,4 @@ -/* $OpenBSD: dh_lib.c,v 1.24 2018/02/18 12:51:31 tb Exp $ */ +/* $OpenBSD: dh_lib.c,v 1.25 2018/02/18 14:58:12 tb Exp $ */ /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * @@ -281,3 +281,22 @@ DH_get0_key(const DH *dh, const BIGNUM **pub_key, const BIGNUM **priv_key) if (priv_key != NULL) *priv_key = dh->priv_key; } + +int +DH_set0_key(DH *dh, BIGNUM *pub_key, BIGNUM *priv_key) +{ + if ((dh->pub_key == NULL && pub_key == NULL) || + (dh->priv_key == NULL && priv_key == NULL)) + return 0; + + if (pub_key != NULL) { + BN_free(dh->pub_key); + dh->pub_key = pub_key; + } + if (priv_key != NULL) { + BN_free(dh->priv_key); + dh->priv_key = priv_key; + } + + return 1; +} diff --git a/lib/libcrypto/dsa/dsa.h b/lib/libcrypto/dsa/dsa.h index 21e5baa235e..20db7f91c17 100644 --- a/lib/libcrypto/dsa/dsa.h +++ b/lib/libcrypto/dsa/dsa.h @@ -1,4 +1,4 @@ -/* $OpenBSD: dsa.h,v 1.25 2018/02/18 12:50:58 tb Exp $ */ +/* $OpenBSD: dsa.h,v 1.26 2018/02/18 14:58:12 tb Exp $ */ /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * @@ -261,6 +261,7 @@ void DSA_get0_pqg(const DSA *d, const BIGNUM **p, const BIGNUM **q, const BIGNUM **g); int DSA_set0_pqg(DSA *d, BIGNUM *p, BIGNUM *q, BIGNUM *g); void DSA_get0_key(const DSA *d, const BIGNUM **pub_key, const BIGNUM **priv_key); +int DSA_set0_key(DSA *d, BIGNUM *pub_key, BIGNUM *priv_key); #define EVP_PKEY_CTX_set_dsa_paramgen_bits(ctx, nbits) \ EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_DSA, EVP_PKEY_OP_PARAMGEN, \ diff --git a/lib/libcrypto/dsa/dsa_lib.c b/lib/libcrypto/dsa/dsa_lib.c index 2dec8567f5d..772c939d314 100644 --- a/lib/libcrypto/dsa/dsa_lib.c +++ b/lib/libcrypto/dsa/dsa_lib.c @@ -1,4 +1,4 @@ -/* $OpenBSD: dsa_lib.c,v 1.25 2018/02/18 12:50:58 tb Exp $ */ +/* $OpenBSD: dsa_lib.c,v 1.26 2018/02/18 14:58:12 tb Exp $ */ /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * @@ -346,3 +346,21 @@ DSA_get0_key(const DSA *d, const BIGNUM **pub_key, const BIGNUM **priv_key) if (priv_key != NULL) *priv_key = d->priv_key; } + +int +DSA_set0_key(DSA *d, BIGNUM *pub_key, BIGNUM *priv_key) +{ + if (d->pub_key == NULL && pub_key == NULL) + return 0; + + if (pub_key != NULL) { + BN_free(d->pub_key); + d->pub_key = pub_key; + } + if (priv_key != NULL) { + BN_free(d->priv_key); + d->priv_key = priv_key; + } + + return 1; +}