summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/lib/libcrypto/evp/p_lib.c51
1 files changed, 29 insertions, 22 deletions
diff --git a/src/lib/libcrypto/evp/p_lib.c b/src/lib/libcrypto/evp/p_lib.c
index c53f38f92c..23ec8e6031 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.36 2023/09/02 04:15:39 tb Exp $ */ 1/* $OpenBSD: p_lib.c,v 1.37 2023/09/10 17:32:17 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 *
@@ -449,13 +449,14 @@ EVP_PKEY_get0_RSA(EVP_PKEY *pkey)
449RSA * 449RSA *
450EVP_PKEY_get1_RSA(EVP_PKEY *pkey) 450EVP_PKEY_get1_RSA(EVP_PKEY *pkey)
451{ 451{
452 if (pkey->type == EVP_PKEY_RSA || pkey->type == EVP_PKEY_RSA_PSS) { 452 RSA *rsa;
453 RSA_up_ref(pkey->pkey.rsa);
454 return pkey->pkey.rsa;
455 }
456 453
457 EVPerror(EVP_R_EXPECTING_AN_RSA_KEY); 454 if ((rsa = EVP_PKEY_get0_RSA(pkey)) == NULL)
458 return NULL; 455 return NULL;
456
457 RSA_up_ref(rsa);
458
459 return rsa;
459} 460}
460 461
461int 462int
@@ -482,12 +483,14 @@ EVP_PKEY_get0_DSA(EVP_PKEY *pkey)
482DSA * 483DSA *
483EVP_PKEY_get1_DSA(EVP_PKEY *pkey) 484EVP_PKEY_get1_DSA(EVP_PKEY *pkey)
484{ 485{
485 if (pkey->type != EVP_PKEY_DSA) { 486 DSA *dsa;
486 EVPerror(EVP_R_EXPECTING_A_DSA_KEY); 487
488 if ((dsa = EVP_PKEY_get0_DSA(pkey)) == NULL)
487 return NULL; 489 return NULL;
488 } 490
489 DSA_up_ref(pkey->pkey.dsa); 491 DSA_up_ref(dsa);
490 return pkey->pkey.dsa; 492
493 return dsa;
491} 494}
492 495
493int 496int
@@ -514,12 +517,14 @@ EVP_PKEY_get0_EC_KEY(EVP_PKEY *pkey)
514EC_KEY * 517EC_KEY *
515EVP_PKEY_get1_EC_KEY(EVP_PKEY *pkey) 518EVP_PKEY_get1_EC_KEY(EVP_PKEY *pkey)
516{ 519{
517 if (pkey->type != EVP_PKEY_EC) { 520 EC_KEY *key;
518 EVPerror(EVP_R_EXPECTING_A_EC_KEY); 521
522 if ((key = EVP_PKEY_get0_EC_KEY(pkey)) == NULL)
519 return NULL; 523 return NULL;
520 } 524
521 EC_KEY_up_ref(pkey->pkey.ec); 525 EC_KEY_up_ref(key);
522 return pkey->pkey.ec; 526
527 return key;
523} 528}
524 529
525int 530int
@@ -547,12 +552,14 @@ EVP_PKEY_get0_DH(EVP_PKEY *pkey)
547DH * 552DH *
548EVP_PKEY_get1_DH(EVP_PKEY *pkey) 553EVP_PKEY_get1_DH(EVP_PKEY *pkey)
549{ 554{
550 if (pkey->type != EVP_PKEY_DH) { 555 DH *dh;
551 EVPerror(EVP_R_EXPECTING_A_DH_KEY); 556
557 if ((dh = EVP_PKEY_get0_DH(pkey)) == NULL)
552 return NULL; 558 return NULL;
553 } 559
554 DH_up_ref(pkey->pkey.dh); 560 DH_up_ref(dh);
555 return pkey->pkey.dh; 561
562 return dh;
556} 563}
557 564
558int 565int