summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authortb <>2025-07-02 06:36:52 +0000
committertb <>2025-07-02 06:36:52 +0000
commit6b47f048c12894f6c2677b85edda844d168c969c (patch)
tree9209c373920f0b7491e3c9c0a2dd3aaa7a762f23 /src
parent3d76905090cbe420b60189cf441b5452c9c8bdf0 (diff)
downloadopenbsd-6b47f048c12894f6c2677b85edda844d168c969c.tar.gz
openbsd-6b47f048c12894f6c2677b85edda844d168c969c.tar.bz2
openbsd-6b47f048c12894f6c2677b85edda844d168c969c.zip
Const correct EVP_PKEY_get{0,1}_{DH,DSA,EC_KEY,RSA}()
These are safe to call concurrently and they don't modify the memory region pointed to by the pkey - they only bump the refcount of the key hanging off of it. The returned "legacy" key has to be handled with care in threaded constexts, so it is handed back as non-const. This also matches what EVP_PKEY_get0() always had. This way our signature is identical to BoringSSL's and doesn't cause compiler warnings in code that overuses const because one of the many API incoherencies added by OpenSSL 3 was to turn get0 into a function that takes and returns const while leaving get1 as it was. dlg agrees ok kenjiro
Diffstat (limited to 'src')
-rw-r--r--src/lib/libcrypto/evp/evp.h30
-rw-r--r--src/lib/libcrypto/evp/p_lib.c18
2 files changed, 22 insertions, 26 deletions
diff --git a/src/lib/libcrypto/evp/evp.h b/src/lib/libcrypto/evp/evp.h
index c2b81d0576..94295e1262 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.137 2024/08/31 10:38:49 tb Exp $ */ 1/* $OpenBSD: evp.h,v 1.138 2025/07/02 06:36:52 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 *
@@ -778,28 +778,24 @@ void *EVP_PKEY_get0(const EVP_PKEY *pkey);
778const unsigned char *EVP_PKEY_get0_hmac(const EVP_PKEY *pkey, size_t *len); 778const unsigned char *EVP_PKEY_get0_hmac(const EVP_PKEY *pkey, size_t *len);
779 779
780#ifndef OPENSSL_NO_RSA 780#ifndef OPENSSL_NO_RSA
781struct rsa_st; 781RSA *EVP_PKEY_get0_RSA(const EVP_PKEY *pkey);
782struct rsa_st *EVP_PKEY_get0_RSA(EVP_PKEY *pkey); 782RSA *EVP_PKEY_get1_RSA(const EVP_PKEY *pkey);
783struct rsa_st *EVP_PKEY_get1_RSA(EVP_PKEY *pkey); 783int EVP_PKEY_set1_RSA(EVP_PKEY *pkey, RSA *key);
784int EVP_PKEY_set1_RSA(EVP_PKEY *pkey, struct rsa_st *key);
785#endif 784#endif
786#ifndef OPENSSL_NO_DSA 785#ifndef OPENSSL_NO_DSA
787struct dsa_st; 786DSA *EVP_PKEY_get0_DSA(const EVP_PKEY *pkey);
788struct dsa_st *EVP_PKEY_get0_DSA(EVP_PKEY *pkey); 787DSA *EVP_PKEY_get1_DSA(const EVP_PKEY *pkey);
789struct dsa_st *EVP_PKEY_get1_DSA(EVP_PKEY *pkey); 788int EVP_PKEY_set1_DSA(EVP_PKEY *pkey, DSA *key);
790int EVP_PKEY_set1_DSA(EVP_PKEY *pkey, struct dsa_st *key);
791#endif 789#endif
792#ifndef OPENSSL_NO_DH 790#ifndef OPENSSL_NO_DH
793struct dh_st; 791DH *EVP_PKEY_get0_DH(const EVP_PKEY *pkey);
794struct dh_st *EVP_PKEY_get0_DH(EVP_PKEY *pkey); 792DH *EVP_PKEY_get1_DH(const EVP_PKEY *pkey);
795struct dh_st *EVP_PKEY_get1_DH(EVP_PKEY *pkey); 793int EVP_PKEY_set1_DH(EVP_PKEY *pkey, DH *key);
796int EVP_PKEY_set1_DH(EVP_PKEY *pkey, struct dh_st *key);
797#endif 794#endif
798#ifndef OPENSSL_NO_EC 795#ifndef OPENSSL_NO_EC
799struct ec_key_st; 796EC_KEY *EVP_PKEY_get0_EC_KEY(const EVP_PKEY *pkey);
800struct ec_key_st *EVP_PKEY_get0_EC_KEY(EVP_PKEY *pkey); 797EC_KEY *EVP_PKEY_get1_EC_KEY(const EVP_PKEY *pkey);
801struct ec_key_st *EVP_PKEY_get1_EC_KEY(EVP_PKEY *pkey); 798int EVP_PKEY_set1_EC_KEY(EVP_PKEY *pkey, EC_KEY *key);
802int EVP_PKEY_set1_EC_KEY(EVP_PKEY *pkey, struct ec_key_st *key);
803#endif 799#endif
804 800
805EVP_PKEY *EVP_PKEY_new(void); 801EVP_PKEY *EVP_PKEY_new(void);
diff --git a/src/lib/libcrypto/evp/p_lib.c b/src/lib/libcrypto/evp/p_lib.c
index 9623bb59a1..3f88185737 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.62 2025/05/10 05:54:38 tb Exp $ */ 1/* $OpenBSD: p_lib.c,v 1.63 2025/07/02 06:36:52 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 *
@@ -628,7 +628,7 @@ LCRYPTO_ALIAS(EVP_PKEY_get0_hmac);
628 628
629#ifndef OPENSSL_NO_RSA 629#ifndef OPENSSL_NO_RSA
630RSA * 630RSA *
631EVP_PKEY_get0_RSA(EVP_PKEY *pkey) 631EVP_PKEY_get0_RSA(const EVP_PKEY *pkey)
632{ 632{
633 if (pkey->type == EVP_PKEY_RSA || pkey->type == EVP_PKEY_RSA_PSS) 633 if (pkey->type == EVP_PKEY_RSA || pkey->type == EVP_PKEY_RSA_PSS)
634 return pkey->pkey.rsa; 634 return pkey->pkey.rsa;
@@ -639,7 +639,7 @@ EVP_PKEY_get0_RSA(EVP_PKEY *pkey)
639LCRYPTO_ALIAS(EVP_PKEY_get0_RSA); 639LCRYPTO_ALIAS(EVP_PKEY_get0_RSA);
640 640
641RSA * 641RSA *
642EVP_PKEY_get1_RSA(EVP_PKEY *pkey) 642EVP_PKEY_get1_RSA(const EVP_PKEY *pkey)
643{ 643{
644 RSA *rsa; 644 RSA *rsa;
645 645
@@ -665,7 +665,7 @@ LCRYPTO_ALIAS(EVP_PKEY_set1_RSA);
665 665
666#ifndef OPENSSL_NO_DSA 666#ifndef OPENSSL_NO_DSA
667DSA * 667DSA *
668EVP_PKEY_get0_DSA(EVP_PKEY *pkey) 668EVP_PKEY_get0_DSA(const EVP_PKEY *pkey)
669{ 669{
670 if (pkey->type != EVP_PKEY_DSA) { 670 if (pkey->type != EVP_PKEY_DSA) {
671 EVPerror(EVP_R_EXPECTING_A_DSA_KEY); 671 EVPerror(EVP_R_EXPECTING_A_DSA_KEY);
@@ -676,7 +676,7 @@ EVP_PKEY_get0_DSA(EVP_PKEY *pkey)
676LCRYPTO_ALIAS(EVP_PKEY_get0_DSA); 676LCRYPTO_ALIAS(EVP_PKEY_get0_DSA);
677 677
678DSA * 678DSA *
679EVP_PKEY_get1_DSA(EVP_PKEY *pkey) 679EVP_PKEY_get1_DSA(const EVP_PKEY *pkey)
680{ 680{
681 DSA *dsa; 681 DSA *dsa;
682 682
@@ -702,7 +702,7 @@ LCRYPTO_ALIAS(EVP_PKEY_set1_DSA);
702 702
703#ifndef OPENSSL_NO_EC 703#ifndef OPENSSL_NO_EC
704EC_KEY * 704EC_KEY *
705EVP_PKEY_get0_EC_KEY(EVP_PKEY *pkey) 705EVP_PKEY_get0_EC_KEY(const EVP_PKEY *pkey)
706{ 706{
707 if (pkey->type != EVP_PKEY_EC) { 707 if (pkey->type != EVP_PKEY_EC) {
708 EVPerror(EVP_R_EXPECTING_A_EC_KEY); 708 EVPerror(EVP_R_EXPECTING_A_EC_KEY);
@@ -713,7 +713,7 @@ EVP_PKEY_get0_EC_KEY(EVP_PKEY *pkey)
713LCRYPTO_ALIAS(EVP_PKEY_get0_EC_KEY); 713LCRYPTO_ALIAS(EVP_PKEY_get0_EC_KEY);
714 714
715EC_KEY * 715EC_KEY *
716EVP_PKEY_get1_EC_KEY(EVP_PKEY *pkey) 716EVP_PKEY_get1_EC_KEY(const EVP_PKEY *pkey)
717{ 717{
718 EC_KEY *key; 718 EC_KEY *key;
719 719
@@ -740,7 +740,7 @@ LCRYPTO_ALIAS(EVP_PKEY_set1_EC_KEY);
740 740
741#ifndef OPENSSL_NO_DH 741#ifndef OPENSSL_NO_DH
742DH * 742DH *
743EVP_PKEY_get0_DH(EVP_PKEY *pkey) 743EVP_PKEY_get0_DH(const EVP_PKEY *pkey)
744{ 744{
745 if (pkey->type != EVP_PKEY_DH) { 745 if (pkey->type != EVP_PKEY_DH) {
746 EVPerror(EVP_R_EXPECTING_A_DH_KEY); 746 EVPerror(EVP_R_EXPECTING_A_DH_KEY);
@@ -751,7 +751,7 @@ EVP_PKEY_get0_DH(EVP_PKEY *pkey)
751LCRYPTO_ALIAS(EVP_PKEY_get0_DH); 751LCRYPTO_ALIAS(EVP_PKEY_get0_DH);
752 752
753DH * 753DH *
754EVP_PKEY_get1_DH(EVP_PKEY *pkey) 754EVP_PKEY_get1_DH(const EVP_PKEY *pkey)
755{ 755{
756 DH *dh; 756 DH *dh;
757 757