|
8 | 8 | #include "openssl/ec.h" |
9 | 9 | #include "openssl/evp.h" |
10 | 10 | #include "openssl/obj_mac.h" |
| 11 | +#include "openssl/pem.h" |
11 | 12 | #if defined(WITH_OPENSSL3) |
12 | 13 | #include "openssl/core_names.h" |
13 | 14 | #include "openssl/param_build.h" |
@@ -526,14 +527,27 @@ struct ECKeyGroup : public EVPGroup |
526 | 527 | #endif |
527 | 528 | } |
528 | 529 |
|
| 530 | + std::unique_ptr<Group::PrivateKey> deserialize_private_der( |
| 531 | + const bytes& der) const override |
| 532 | + { |
| 533 | + BIO* mem = BIO_new_mem_buf(der.data(), der.size()); |
| 534 | + if (!mem) { |
| 535 | + throw openssl_error(); |
| 536 | + } |
| 537 | + EVP_PKEY* pkey = d2i_PrivateKey_bio(mem, NULL); |
| 538 | + BIO_free(mem); |
| 539 | + if (!pkey) { |
| 540 | + throw openssl_error(); |
| 541 | + } |
| 542 | + |
| 543 | + return std::make_unique<EVPGroup::PrivateKey>(pkey); |
| 544 | + } |
| 545 | + |
529 | 546 | private: |
530 | 547 | int curve_nid; |
531 | 548 |
|
532 | 549 | #if !defined(WITH_OPENSSL3) |
533 | | - EC_KEY* new_ec_key() const |
534 | | - { |
535 | | - return EC_KEY_new_by_curve_name(curve_nid); |
536 | | - } |
| 550 | + EC_KEY* new_ec_key() const { return EC_KEY_new_by_curve_name(curve_nid); } |
537 | 551 |
|
538 | 552 | static EVP_PKEY* to_pkey(EC_KEY* eckey) |
539 | 553 | { |
@@ -651,6 +665,22 @@ struct RawKeyGroup : public EVPGroup |
651 | 665 | return std::make_unique<EVPGroup::PrivateKey>(pkey); |
652 | 666 | } |
653 | 667 |
|
| 668 | + std::unique_ptr<Group::PrivateKey> deserialize_private_der( |
| 669 | + const bytes& der) const override |
| 670 | + { |
| 671 | + BIO* mem = BIO_new_mem_buf(der.data(), der.size()); |
| 672 | + if (!mem) { |
| 673 | + throw openssl_error(); |
| 674 | + } |
| 675 | + EVP_PKEY* pkey = d2i_PrivateKey_bio(mem, NULL); |
| 676 | + BIO_free(mem); |
| 677 | + if (!pkey) { |
| 678 | + throw openssl_error(); |
| 679 | + } |
| 680 | + |
| 681 | + return std::make_unique<RawKeyGroup::PrivateKey>(pkey); |
| 682 | + } |
| 683 | + |
654 | 684 | private: |
655 | 685 | const int evp_type; |
656 | 686 |
|
|
0 commit comments