summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortb <>2018-02-17 13:47:36 +0000
committertb <>2018-02-17 13:47:36 +0000
commite1b05f77869d986a0aee6aa4076f008274e98d27 (patch)
treef0cc2d3dd2a3842c40f792227fe86c133a668af2
parent0c7165079d7f7c944f8c516a5bb23a71b674c170 (diff)
downloadopenbsd-e1b05f77869d986a0aee6aa4076f008274e98d27.tar.gz
openbsd-e1b05f77869d986a0aee6aa4076f008274e98d27.tar.bz2
openbsd-e1b05f77869d986a0aee6aa4076f008274e98d27.zip
Provide further parts of the OpenSSL 1.1 API: {DH,DSA}_get0_{key,pqg}(),
EVP_PKEY_get0_{DH,DSA,RSA}(), RSA_{g,s}et0_key(). ok jsing
-rw-r--r--src/lib/libcrypto/Symbols.list9
-rw-r--r--src/lib/libcrypto/dh/dh.h6
-rw-r--r--src/lib/libcrypto/dh/dh_lib.c22
-rw-r--r--src/lib/libcrypto/dsa/dsa.h6
-rw-r--r--src/lib/libcrypto/dsa/dsa_lib.c22
-rw-r--r--src/lib/libcrypto/evp/evp.h11
-rw-r--r--src/lib/libcrypto/evp/p_lib.c67
-rw-r--r--src/lib/libcrypto/rsa/rsa.h6
-rw-r--r--src/lib/libcrypto/rsa/rsa_lib.c35
9 files changed, 155 insertions, 29 deletions
diff --git a/src/lib/libcrypto/Symbols.list b/src/lib/libcrypto/Symbols.list
index d9cbe853a9..99930ffa17 100644
--- a/src/lib/libcrypto/Symbols.list
+++ b/src/lib/libcrypto/Symbols.list
@@ -736,6 +736,8 @@ DH_free
736DH_generate_key 736DH_generate_key
737DH_generate_parameters 737DH_generate_parameters
738DH_generate_parameters_ex 738DH_generate_parameters_ex
739DH_get0_key
740DH_get0_pqg
739DH_get_default_method 741DH_get_default_method
740DH_get_ex_data 742DH_get_ex_data
741DH_get_ex_new_index 743DH_get_ex_new_index
@@ -776,6 +778,8 @@ DSA_free
776DSA_generate_key 778DSA_generate_key
777DSA_generate_parameters 779DSA_generate_parameters
778DSA_generate_parameters_ex 780DSA_generate_parameters_ex
781DSA_get0_key
782DSA_get0_pqg
779DSA_get_default_method 783DSA_get_default_method
780DSA_get_ex_data 784DSA_get_ex_data
781DSA_get_ex_new_index 785DSA_get_ex_new_index
@@ -1338,9 +1342,12 @@ EVP_PKEY_encrypt_old
1338EVP_PKEY_free 1342EVP_PKEY_free
1339EVP_PKEY_get0 1343EVP_PKEY_get0
1340EVP_PKEY_get0_asn1 1344EVP_PKEY_get0_asn1
1345EVP_PKEY_get0_DH
1341EVP_PKEY_get1_DH 1346EVP_PKEY_get1_DH
1347EVP_PKEY_get0_DSA
1342EVP_PKEY_get1_DSA 1348EVP_PKEY_get1_DSA
1343EVP_PKEY_get1_EC_KEY 1349EVP_PKEY_get1_EC_KEY
1350EVP_PKEY_get0_RSA
1344EVP_PKEY_get1_RSA 1351EVP_PKEY_get1_RSA
1345EVP_PKEY_get_attr 1352EVP_PKEY_get_attr
1346EVP_PKEY_get_attr_by_NID 1353EVP_PKEY_get_attr_by_NID
@@ -2185,6 +2192,7 @@ RSA_flags
2185RSA_free 2192RSA_free
2186RSA_generate_key 2193RSA_generate_key
2187RSA_generate_key_ex 2194RSA_generate_key_ex
2195RSA_get0_key
2188RSA_get_default_method 2196RSA_get_default_method
2189RSA_get_ex_data 2197RSA_get_ex_data
2190RSA_get_ex_new_index 2198RSA_get_ex_new_index
@@ -2209,6 +2217,7 @@ RSA_private_decrypt
2209RSA_private_encrypt 2217RSA_private_encrypt
2210RSA_public_decrypt 2218RSA_public_decrypt
2211RSA_public_encrypt 2219RSA_public_encrypt
2220RSA_set0_key
2212RSA_set_default_method 2221RSA_set_default_method
2213RSA_set_ex_data 2222RSA_set_ex_data
2214RSA_set_method 2223RSA_set_method
diff --git a/src/lib/libcrypto/dh/dh.h b/src/lib/libcrypto/dh/dh.h
index 920af3b92d..61c7d6c873 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.18 2016/11/04 18:35:30 jsing Exp $ */ 1/* $OpenBSD: dh.h,v 1.19 2018/02/17 13:47:36 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 *
@@ -188,6 +188,10 @@ int DH_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func,
188int DH_set_ex_data(DH *d, int idx, void *arg); 188int DH_set_ex_data(DH *d, int idx, void *arg);
189void *DH_get_ex_data(DH *d, int idx); 189void *DH_get_ex_data(DH *d, int idx);
190 190
191void DH_get0_pqg(const DH *dh, const BIGNUM **p, const BIGNUM **q,
192 const BIGNUM **g);
193void DH_get0_key(const DH *dh, const BIGNUM **pub_key, const BIGNUM **priv_key);
194
191/* Deprecated version */ 195/* Deprecated version */
192#ifndef OPENSSL_NO_DEPRECATED 196#ifndef OPENSSL_NO_DEPRECATED
193DH * DH_generate_parameters(int prime_len,int generator, 197DH * DH_generate_parameters(int prime_len,int generator,
diff --git a/src/lib/libcrypto/dh/dh_lib.c b/src/lib/libcrypto/dh/dh_lib.c
index d45dc17168..5a54ca88da 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.22 2017/01/29 17:49:22 beck Exp $ */ 1/* $OpenBSD: dh_lib.c,v 1.23 2018/02/17 13:47:36 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 *
@@ -239,3 +239,23 @@ DH_size(const DH *dh)
239{ 239{
240 return BN_num_bytes(dh->p); 240 return BN_num_bytes(dh->p);
241} 241}
242
243void
244DH_get0_pqg(const DH *dh, const BIGNUM **p, const BIGNUM **q, const BIGNUM **g)
245{
246 if (p != NULL)
247 *p = dh->p;
248 if (q != NULL)
249 *q = dh->q;
250 if (g != NULL)
251 *g = dh->g;
252}
253
254void
255DH_get0_key(const DH *dh, const BIGNUM **pub_key, const BIGNUM **priv_key)
256{
257 if (pub_key != NULL)
258 *pub_key = dh->pub_key;
259 if (priv_key != NULL)
260 *priv_key = dh->priv_key;
261}
diff --git a/src/lib/libcrypto/dsa/dsa.h b/src/lib/libcrypto/dsa/dsa.h
index 6ddd4c35d5..f990ad52f0 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.22 2016/11/04 18:35:30 jsing Exp $ */ 1/* $OpenBSD: dsa.h,v 1.23 2018/02/17 13:47:36 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 *
@@ -257,6 +257,10 @@ int DSA_print_fp(FILE *bp, const DSA *x, int off);
257DH *DSA_dup_DH(const DSA *r); 257DH *DSA_dup_DH(const DSA *r);
258#endif 258#endif
259 259
260void DSA_get0_pqg(const DSA *d, const BIGNUM **p, const BIGNUM **q,
261 const BIGNUM **g);
262void DSA_get0_key(const DH *d, const BIGNUM **pub_key, const BIGNUM **priv_key);
263
260#define EVP_PKEY_CTX_set_dsa_paramgen_bits(ctx, nbits) \ 264#define EVP_PKEY_CTX_set_dsa_paramgen_bits(ctx, nbits) \
261 EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_DSA, EVP_PKEY_OP_PARAMGEN, \ 265 EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_DSA, EVP_PKEY_OP_PARAMGEN, \
262 EVP_PKEY_CTRL_DSA_PARAMGEN_BITS, nbits, NULL) 266 EVP_PKEY_CTRL_DSA_PARAMGEN_BITS, nbits, NULL)
diff --git a/src/lib/libcrypto/dsa/dsa_lib.c b/src/lib/libcrypto/dsa/dsa_lib.c
index 58af74889c..ae9155c9f8 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.23 2017/01/29 17:49:22 beck Exp $ */ 1/* $OpenBSD: dsa_lib.c,v 1.24 2018/02/17 13:47:36 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 *
@@ -303,3 +303,23 @@ err:
303 return NULL; 303 return NULL;
304} 304}
305#endif 305#endif
306
307void
308DSA_get0_pqg(const DSA *d, const BIGNUM **p, const BIGNUM **q, const BIGNUM **g)
309{
310 if (p != NULL)
311 *p = d->p;
312 if (q != NULL)
313 *q = d->q;
314 if (g != NULL)
315 *g = d->g;
316}
317
318void
319DSA_get0_key(const DSA *d, const BIGNUM **pub_key, const BIGNUM **priv_key)
320{
321 if (pub_key != NULL)
322 *pub_key = d->pub_key;
323 if (priv_key != NULL)
324 *priv_key = d->priv_key;
325}
diff --git a/src/lib/libcrypto/evp/evp.h b/src/lib/libcrypto/evp/evp.h
index 09df7db64b..c8da89844d 100644
--- a/src/lib/libcrypto/evp/evp.h
+++ b/src/lib/libcrypto/evp/evp.h
@@ -1,4 +1,4 @@
1/* $OpenBSD: evp.h,v 1.54 2018/02/14 16:40:42 jsing Exp $ */ 1/* $OpenBSD: evp.h,v 1.55 2018/02/17 13:47:36 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 *
@@ -870,18 +870,21 @@ void *EVP_PKEY_get0(EVP_PKEY *pkey);
870 870
871#ifndef OPENSSL_NO_RSA 871#ifndef OPENSSL_NO_RSA
872struct rsa_st; 872struct rsa_st;
873int EVP_PKEY_set1_RSA(EVP_PKEY *pkey, struct rsa_st *key); 873struct rsa_st *EVP_PKEY_get0_RSA(EVP_PKEY *pkey);
874struct rsa_st *EVP_PKEY_get1_RSA(EVP_PKEY *pkey); 874struct rsa_st *EVP_PKEY_get1_RSA(EVP_PKEY *pkey);
875int EVP_PKEY_set1_RSA(EVP_PKEY *pkey, struct rsa_st *key);
875#endif 876#endif
876#ifndef OPENSSL_NO_DSA 877#ifndef OPENSSL_NO_DSA
877struct dsa_st; 878struct dsa_st;
878int EVP_PKEY_set1_DSA(EVP_PKEY *pkey, struct dsa_st *key); 879struct dsa_st *EVP_PKEY_get0_DSA(EVP_PKEY *pkey);
879struct dsa_st *EVP_PKEY_get1_DSA(EVP_PKEY *pkey); 880struct dsa_st *EVP_PKEY_get1_DSA(EVP_PKEY *pkey);
881int EVP_PKEY_set1_DSA(EVP_PKEY *pkey, struct dsa_st *key);
880#endif 882#endif
881#ifndef OPENSSL_NO_DH 883#ifndef OPENSSL_NO_DH
882struct dh_st; 884struct dh_st;
883int EVP_PKEY_set1_DH(EVP_PKEY *pkey, struct dh_st *key); 885struct dh_st *EVP_PKEY_get0_DH(EVP_PKEY *pkey);
884struct dh_st *EVP_PKEY_get1_DH(EVP_PKEY *pkey); 886struct dh_st *EVP_PKEY_get1_DH(EVP_PKEY *pkey);
887int EVP_PKEY_set1_DH(EVP_PKEY *pkey, struct dh_st *key);
885#endif 888#endif
886#ifndef OPENSSL_NO_EC 889#ifndef OPENSSL_NO_EC
887struct ec_key_st; 890struct ec_key_st;
diff --git a/src/lib/libcrypto/evp/p_lib.c b/src/lib/libcrypto/evp/p_lib.c
index e001755ef1..3cd1bf3b34 100644
--- a/src/lib/libcrypto/evp/p_lib.c
+++ b/src/lib/libcrypto/evp/p_lib.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: p_lib.c,v 1.18 2018/02/14 16:40:42 jsing Exp $ */ 1/* $OpenBSD: p_lib.c,v 1.19 2018/02/17 13:47:36 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 *
@@ -286,13 +286,14 @@ EVP_PKEY_get0(EVP_PKEY *pkey)
286} 286}
287 287
288#ifndef OPENSSL_NO_RSA 288#ifndef OPENSSL_NO_RSA
289int 289RSA *
290EVP_PKEY_set1_RSA(EVP_PKEY *pkey, RSA *key) 290EVP_PKEY_get0_RSA(EVP_PKEY *pkey)
291{ 291{
292 int ret = EVP_PKEY_assign_RSA(pkey, key); 292 if (pkey->type != EVP_PKEY_RSA) {
293 if (ret) 293 EVPerror(EVP_R_EXPECTING_AN_RSA_KEY);
294 RSA_up_ref(key); 294 return NULL;
295 return ret; 295 }
296 return pkey->pkey.rsa;
296} 297}
297 298
298RSA * 299RSA *
@@ -305,17 +306,27 @@ EVP_PKEY_get1_RSA(EVP_PKEY *pkey)
305 RSA_up_ref(pkey->pkey.rsa); 306 RSA_up_ref(pkey->pkey.rsa);
306 return pkey->pkey.rsa; 307 return pkey->pkey.rsa;
307} 308}
308#endif
309 309
310#ifndef OPENSSL_NO_DSA
311int 310int
312EVP_PKEY_set1_DSA(EVP_PKEY *pkey, DSA *key) 311EVP_PKEY_set1_RSA(EVP_PKEY *pkey, RSA *key)
313{ 312{
314 int ret = EVP_PKEY_assign_DSA(pkey, key); 313 int ret = EVP_PKEY_assign_RSA(pkey, key);
315 if (ret) 314 if (ret)
316 DSA_up_ref(key); 315 RSA_up_ref(key);
317 return ret; 316 return ret;
318} 317}
318#endif
319
320#ifndef OPENSSL_NO_DSA
321DSA *
322EVP_PKEY_get0_DSA(EVP_PKEY *pkey)
323{
324 if (pkey->type != EVP_PKEY_DSA) {
325 EVPerror(EVP_R_EXPECTING_A_DSA_KEY);
326 return NULL;
327 }
328 return pkey->pkey.dsa;
329}
319 330
320DSA * 331DSA *
321EVP_PKEY_get1_DSA(EVP_PKEY *pkey) 332EVP_PKEY_get1_DSA(EVP_PKEY *pkey)
@@ -327,6 +338,15 @@ EVP_PKEY_get1_DSA(EVP_PKEY *pkey)
327 DSA_up_ref(pkey->pkey.dsa); 338 DSA_up_ref(pkey->pkey.dsa);
328 return pkey->pkey.dsa; 339 return pkey->pkey.dsa;
329} 340}
341
342int
343EVP_PKEY_set1_DSA(EVP_PKEY *pkey, DSA *key)
344{
345 int ret = EVP_PKEY_assign_DSA(pkey, key);
346 if (ret)
347 DSA_up_ref(key);
348 return ret;
349}
330#endif 350#endif
331 351
332#ifndef OPENSSL_NO_EC 352#ifndef OPENSSL_NO_EC
@@ -354,14 +374,14 @@ EVP_PKEY_get1_EC_KEY(EVP_PKEY *pkey)
354 374
355 375
356#ifndef OPENSSL_NO_DH 376#ifndef OPENSSL_NO_DH
357 377DH *
358int 378EVP_PKEY_get0_DH(EVP_PKEY *pkey)
359EVP_PKEY_set1_DH(EVP_PKEY *pkey, DH *key)
360{ 379{
361 int ret = EVP_PKEY_assign_DH(pkey, key); 380 if (pkey->type != EVP_PKEY_DH) {
362 if (ret) 381 EVPerror(EVP_R_EXPECTING_A_DH_KEY);
363 DH_up_ref(key); 382 return NULL;
364 return ret; 383 }
384 return pkey->pkey.dh;
365} 385}
366 386
367DH * 387DH *
@@ -374,6 +394,15 @@ EVP_PKEY_get1_DH(EVP_PKEY *pkey)
374 DH_up_ref(pkey->pkey.dh); 394 DH_up_ref(pkey->pkey.dh);
375 return pkey->pkey.dh; 395 return pkey->pkey.dh;
376} 396}
397
398int
399EVP_PKEY_set1_DH(EVP_PKEY *pkey, DH *key)
400{
401 int ret = EVP_PKEY_assign_DH(pkey, key);
402 if (ret)
403 DH_up_ref(key);
404 return ret;
405}
377#endif 406#endif
378 407
379int 408int
diff --git a/src/lib/libcrypto/rsa/rsa.h b/src/lib/libcrypto/rsa/rsa.h
index 7476a1164a..7d4bd838c5 100644
--- a/src/lib/libcrypto/rsa/rsa.h
+++ b/src/lib/libcrypto/rsa/rsa.h
@@ -1,4 +1,4 @@
1/* $OpenBSD: rsa.h,v 1.31 2017/08/30 16:07:35 jsing Exp $ */ 1/* $OpenBSD: rsa.h,v 1.32 2018/02/17 13:47:36 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 *
@@ -395,6 +395,10 @@ int RSA_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func,
395int RSA_set_ex_data(RSA *r, int idx, void *arg); 395int RSA_set_ex_data(RSA *r, int idx, void *arg);
396void *RSA_get_ex_data(const RSA *r, int idx); 396void *RSA_get_ex_data(const RSA *r, int idx);
397 397
398int RSA_set0_key(RSA *r, BIGNUM *n, BIGNUM *e, BIGNUM *d);
399void RSA_get0_key(const RSA *r, const BIGNUM **n, const BIGNUM **e,
400 const BIGNUM **d);
401
398RSA *RSAPublicKey_dup(RSA *rsa); 402RSA *RSAPublicKey_dup(RSA *rsa);
399RSA *RSAPrivateKey_dup(RSA *rsa); 403RSA *RSAPrivateKey_dup(RSA *rsa);
400 404
diff --git a/src/lib/libcrypto/rsa/rsa_lib.c b/src/lib/libcrypto/rsa/rsa_lib.c
index 31ea418427..2a73364e70 100644
--- a/src/lib/libcrypto/rsa/rsa_lib.c
+++ b/src/lib/libcrypto/rsa/rsa_lib.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: rsa_lib.c,v 1.31 2017/01/29 17:49:23 beck Exp $ */ 1/* $OpenBSD: rsa_lib.c,v 1.32 2018/02/17 13:47:36 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 *
@@ -256,3 +256,36 @@ RSA_get_ex_data(const RSA *r, int idx)
256{ 256{
257 return CRYPTO_get_ex_data(&r->ex_data, idx); 257 return CRYPTO_get_ex_data(&r->ex_data, idx);
258} 258}
259
260int
261RSA_set0_key(RSA *r, BIGNUM *n, BIGNUM *e, BIGNUM *d)
262{
263 if ((r->n == NULL && n == NULL) || (r->e == NULL && e == NULL))
264 return 0;
265
266 if (n != NULL) {
267 BN_free(r->n);
268 r->n = n;
269 }
270 if (e != NULL) {
271 BN_free(r->e);
272 r->e = e;
273 }
274 if (d != NULL) {
275 BN_free(r->d);
276 r->d = d;
277 }
278
279 return 1;
280}
281
282void
283RSA_get0_key(const RSA *r, const BIGNUM **n, const BIGNUM **e, const BIGNUM **d)
284{
285 if (n != NULL)
286 *n = r->n;
287 if (e != NULL)
288 *e = r->e;
289 if (d != NULL)
290 *d = r->d;
291}