diff options
| author | tb <> | 2023-09-10 17:32:17 +0000 |
|---|---|---|
| committer | tb <> | 2023-09-10 17:32:17 +0000 |
| commit | 439052492960f8018c044ad859f1bfa787fc993b (patch) | |
| tree | 286b46c9758687afc137dd1fe48d92a7ec5d0c87 | |
| parent | 3ffd50d46144ae89cb26a04218127b0cf3038673 (diff) | |
| download | openbsd-439052492960f8018c044ad859f1bfa787fc993b.tar.gz openbsd-439052492960f8018c044ad859f1bfa787fc993b.tar.bz2 openbsd-439052492960f8018c044ad859f1bfa787fc993b.zip | |
Make EVP_PKEY_get1_$TYPE a wrapper of EVP_PKEY_get0_$TYPE
Avoids a bit of code duplication and reduces the probability of a fix being
applied to only one of get0 and get1 (which happend in p_lib.c r1.35).
ok jsing
| -rw-r--r-- | src/lib/libcrypto/evp/p_lib.c | 51 |
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) | |||
| 449 | RSA * | 449 | RSA * |
| 450 | EVP_PKEY_get1_RSA(EVP_PKEY *pkey) | 450 | EVP_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 | ||
| 461 | int | 462 | int |
| @@ -482,12 +483,14 @@ EVP_PKEY_get0_DSA(EVP_PKEY *pkey) | |||
| 482 | DSA * | 483 | DSA * |
| 483 | EVP_PKEY_get1_DSA(EVP_PKEY *pkey) | 484 | EVP_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 | ||
| 493 | int | 496 | int |
| @@ -514,12 +517,14 @@ EVP_PKEY_get0_EC_KEY(EVP_PKEY *pkey) | |||
| 514 | EC_KEY * | 517 | EC_KEY * |
| 515 | EVP_PKEY_get1_EC_KEY(EVP_PKEY *pkey) | 518 | EVP_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 | ||
| 525 | int | 530 | int |
| @@ -547,12 +552,14 @@ EVP_PKEY_get0_DH(EVP_PKEY *pkey) | |||
| 547 | DH * | 552 | DH * |
| 548 | EVP_PKEY_get1_DH(EVP_PKEY *pkey) | 553 | EVP_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 | ||
| 558 | int | 565 | int |
