summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/evp/p_lib.c
diff options
context:
space:
mode:
authortb <>2025-07-02 06:36:52 +0000
committertb <>2025-07-02 06:36:52 +0000
commitee8028bd119b3e4cd917dc91bde28658b6256b9f (patch)
tree9209c373920f0b7491e3c9c0a2dd3aaa7a762f23 /src/lib/libcrypto/evp/p_lib.c
parent352bfb516a8a7791f3f4d8ce80d477d61afeb90f (diff)
downloadopenbsd-ee8028bd119b3e4cd917dc91bde28658b6256b9f.tar.gz
openbsd-ee8028bd119b3e4cd917dc91bde28658b6256b9f.tar.bz2
openbsd-ee8028bd119b3e4cd917dc91bde28658b6256b9f.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/lib/libcrypto/evp/p_lib.c')
-rw-r--r--src/lib/libcrypto/evp/p_lib.c18
1 files changed, 9 insertions, 9 deletions
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