summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortb <>2018-02-18 14:58:12 +0000
committertb <>2018-02-18 14:58:12 +0000
commit1b561f846b060aedbadbe38a4aef0bb347dbf2e0 (patch)
tree2f49be312f3f68a1760dd001d14bafc0a40e6123
parent629e6de4bc68d390bb4829a7656219e3e0efeb4a (diff)
downloadopenbsd-1b561f846b060aedbadbe38a4aef0bb347dbf2e0.tar.gz
openbsd-1b561f846b060aedbadbe38a4aef0bb347dbf2e0.tar.bz2
openbsd-1b561f846b060aedbadbe38a4aef0bb347dbf2e0.zip
Provide {DH,DSA}_set0_key(). Requested by sthen.
ok jsing
-rw-r--r--src/lib/libcrypto/Symbols.list2
-rw-r--r--src/lib/libcrypto/dh/dh.h3
-rw-r--r--src/lib/libcrypto/dh/dh_lib.c21
-rw-r--r--src/lib/libcrypto/dsa/dsa.h3
-rw-r--r--src/lib/libcrypto/dsa/dsa_lib.c20
5 files changed, 45 insertions, 4 deletions
diff --git a/src/lib/libcrypto/Symbols.list b/src/lib/libcrypto/Symbols.list
index 77cf4399e7..b88d6c6182 100644
--- a/src/lib/libcrypto/Symbols.list
+++ b/src/lib/libcrypto/Symbols.list
@@ -755,6 +755,7 @@ DH_get_ex_data
755DH_get_ex_new_index 755DH_get_ex_new_index
756DH_new 756DH_new
757DH_new_method 757DH_new_method
758DH_set0_key
758DH_set0_pqg 759DH_set0_pqg
759DH_set_default_method 760DH_set_default_method
760DH_set_ex_data 761DH_set_ex_data
@@ -800,6 +801,7 @@ DSA_new
800DSA_new_method 801DSA_new_method
801DSA_print 802DSA_print
802DSA_print_fp 803DSA_print_fp
804DSA_set0_key
803DSA_set0_pqg 805DSA_set0_pqg
804DSA_set_default_method 806DSA_set_default_method
805DSA_set_ex_data 807DSA_set_ex_data
diff --git a/src/lib/libcrypto/dh/dh.h b/src/lib/libcrypto/dh/dh.h
index e5daa2cbdd..f1c51850eb 100644
--- a/src/lib/libcrypto/dh/dh.h
+++ b/src/lib/libcrypto/dh/dh.h
@@ -1,4 +1,4 @@
1/* $OpenBSD: dh.h,v 1.20 2018/02/18 12:51:31 tb Exp $ */ 1/* $OpenBSD: dh.h,v 1.21 2018/02/18 14:58:12 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 *
@@ -192,6 +192,7 @@ void DH_get0_pqg(const DH *dh, const BIGNUM **p, const BIGNUM **q,
192 const BIGNUM **g); 192 const BIGNUM **g);
193int DH_set0_pqg(DH *dh, BIGNUM *p, BIGNUM *q, BIGNUM *g); 193int DH_set0_pqg(DH *dh, BIGNUM *p, BIGNUM *q, BIGNUM *g);
194void DH_get0_key(const DH *dh, const BIGNUM **pub_key, const BIGNUM **priv_key); 194void DH_get0_key(const DH *dh, const BIGNUM **pub_key, const BIGNUM **priv_key);
195int DH_set0_key(DH *dh, BIGNUM *pub_key, BIGNUM *priv_key);
195 196
196/* Deprecated version */ 197/* Deprecated version */
197#ifndef OPENSSL_NO_DEPRECATED 198#ifndef OPENSSL_NO_DEPRECATED
diff --git a/src/lib/libcrypto/dh/dh_lib.c b/src/lib/libcrypto/dh/dh_lib.c
index 31857727e2..bb2ca426a0 100644
--- a/src/lib/libcrypto/dh/dh_lib.c
+++ b/src/lib/libcrypto/dh/dh_lib.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: dh_lib.c,v 1.24 2018/02/18 12:51:31 tb Exp $ */ 1/* $OpenBSD: dh_lib.c,v 1.25 2018/02/18 14:58:12 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 *
@@ -281,3 +281,22 @@ DH_get0_key(const DH *dh, const BIGNUM **pub_key, const BIGNUM **priv_key)
281 if (priv_key != NULL) 281 if (priv_key != NULL)
282 *priv_key = dh->priv_key; 282 *priv_key = dh->priv_key;
283} 283}
284
285int
286DH_set0_key(DH *dh, BIGNUM *pub_key, BIGNUM *priv_key)
287{
288 if ((dh->pub_key == NULL && pub_key == NULL) ||
289 (dh->priv_key == NULL && priv_key == NULL))
290 return 0;
291
292 if (pub_key != NULL) {
293 BN_free(dh->pub_key);
294 dh->pub_key = pub_key;
295 }
296 if (priv_key != NULL) {
297 BN_free(dh->priv_key);
298 dh->priv_key = priv_key;
299 }
300
301 return 1;
302}
diff --git a/src/lib/libcrypto/dsa/dsa.h b/src/lib/libcrypto/dsa/dsa.h
index 21e5baa235..20db7f91c1 100644
--- a/src/lib/libcrypto/dsa/dsa.h
+++ b/src/lib/libcrypto/dsa/dsa.h
@@ -1,4 +1,4 @@
1/* $OpenBSD: dsa.h,v 1.25 2018/02/18 12:50:58 tb Exp $ */ 1/* $OpenBSD: dsa.h,v 1.26 2018/02/18 14:58:12 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 *
@@ -261,6 +261,7 @@ void DSA_get0_pqg(const DSA *d, const BIGNUM **p, const BIGNUM **q,
261 const BIGNUM **g); 261 const BIGNUM **g);
262int DSA_set0_pqg(DSA *d, BIGNUM *p, BIGNUM *q, BIGNUM *g); 262int DSA_set0_pqg(DSA *d, BIGNUM *p, BIGNUM *q, BIGNUM *g);
263void DSA_get0_key(const DSA *d, const BIGNUM **pub_key, const BIGNUM **priv_key); 263void DSA_get0_key(const DSA *d, const BIGNUM **pub_key, const BIGNUM **priv_key);
264int DSA_set0_key(DSA *d, BIGNUM *pub_key, BIGNUM *priv_key);
264 265
265#define EVP_PKEY_CTX_set_dsa_paramgen_bits(ctx, nbits) \ 266#define EVP_PKEY_CTX_set_dsa_paramgen_bits(ctx, nbits) \
266 EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_DSA, EVP_PKEY_OP_PARAMGEN, \ 267 EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_DSA, EVP_PKEY_OP_PARAMGEN, \
diff --git a/src/lib/libcrypto/dsa/dsa_lib.c b/src/lib/libcrypto/dsa/dsa_lib.c
index 2dec8567f5..772c939d31 100644
--- a/src/lib/libcrypto/dsa/dsa_lib.c
+++ b/src/lib/libcrypto/dsa/dsa_lib.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: dsa_lib.c,v 1.25 2018/02/18 12:50:58 tb Exp $ */ 1/* $OpenBSD: dsa_lib.c,v 1.26 2018/02/18 14:58:12 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 *
@@ -346,3 +346,21 @@ DSA_get0_key(const DSA *d, const BIGNUM **pub_key, const BIGNUM **priv_key)
346 if (priv_key != NULL) 346 if (priv_key != NULL)
347 *priv_key = d->priv_key; 347 *priv_key = d->priv_key;
348} 348}
349
350int
351DSA_set0_key(DSA *d, BIGNUM *pub_key, BIGNUM *priv_key)
352{
353 if (d->pub_key == NULL && pub_key == NULL)
354 return 0;
355
356 if (pub_key != NULL) {
357 BN_free(d->pub_key);
358 d->pub_key = pub_key;
359 }
360 if (priv_key != NULL) {
361 BN_free(d->priv_key);
362 d->priv_key = priv_key;
363 }
364
365 return 1;
366}