diff options
| author | hrxi <hrrrxi@gmail.com> | 2023-11-24 20:53:50 +0100 |
|---|---|---|
| committer | Marvin W <git@larma.de> | 2026-10-23 16:58:30 +0200 |
| commit | 76a91fca2fc7dd5975e8ff0e6695f27c98539dba (patch) | |
| tree | 7829340be71fe60ef847247e578c4589571fecc5 /plugins/ice/src/openssl_utils.c | |
| parent | b013d28182ce582f229185c23b6011f566f1f8cc (diff) | |
Add support for OpenSSL
Uses work by @hrxi in https://github.com/dino/dino/pull/1515
Co-Authored-By: hrxi <hrrrxi@gmail.com>
Diffstat (limited to 'plugins/ice/src/openssl_utils.c')
| -rw-r--r-- | plugins/ice/src/openssl_utils.c | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/plugins/ice/src/openssl_utils.c b/plugins/ice/src/openssl_utils.c new file mode 100644 index 00000000..7f4bf331 --- /dev/null +++ b/plugins/ice/src/openssl_utils.c @@ -0,0 +1,49 @@ +#include "openssl_utils.h" +#include <openssl/opensslv.h> +#include <openssl/ec.h> + +#if defined(OPENSSL_VERSION_NUMBER) && OPENSSL_VERSION_NUMBER >= 0x30000000L +// This is for OpenSSL 3.0.0 and newer + +EVP_PKEY *EVP_PKEY_new_generate_ecdsa (const char* curve) { + // Generate EVP_PKEY directly + EVP_PKEY *pkey = EVP_EC_gen (curve); + return pkey; +} + +#else +// This is for OpenSSL before 3.0.0 and forks of earlier OpenSSL versions like LibreSSL + +EVP_PKEY *EVP_PKEY_new_generate_ecdsa (const char* curve) { + // Get NID from curve name + int nid = OBJ_sn2nid (curve); + if (nid == NID_undef) return NULL; + + // Create EC_KEY + EC_KEY *ec_key = EC_KEY_new_by_curve_name (nid); + if (!ec_key) return NULL; + + // Generate key + if (!EC_KEY_generate_key (ec_key)) { + EC_KEY_free (ec_key); + return NULL; + } + + // Create EVP_PKEY + EVP_PKEY *pkey = EVP_PKEY_new (); + if (!pkey) { + EC_KEY_free (ec_key); + return NULL; + } + + // Assign EC_KEY to EVP_PKEY + if (!EVP_PKEY_assign_EC_KEY (pkey, ec_key)) { + EC_KEY_free (ec_key); + return NULL; + } + + // EVP_PKEY_assign_EC_KEY takes ownership of ec_key, no need to free it explicitly + return pkey; +} + +#endif |
