X-Git-Url: https://git.openssl.org/?p=openssl.git;a=blobdiff_plain;f=crypto%2Fec%2Fecx_meth.c;h=88787e0db6c749feea8eb99b27f375881075b567;hp=15b902ec1dda4e17e600d07a6b98ca4815103e53;hb=6f7d213533d9c7c2d810499cfedaa6d2424482c9;hpb=90d3cb57c6caafbe031e32a99051386b8c5a90c0 diff --git a/crypto/ec/ecx_meth.c b/crypto/ec/ecx_meth.c index 15b902ec1d..88787e0db6 100644 --- a/crypto/ec/ecx_meth.c +++ b/crypto/ec/ecx_meth.c @@ -18,6 +18,8 @@ #include #include #include +#include +#include "internal/param_build.h" #include "crypto/asn1.h" #include "crypto/evp.h" #include "crypto/ecx.h" @@ -401,6 +403,48 @@ static int ecx_get_pub_key(const EVP_PKEY *pkey, unsigned char *pub, return 1; } +static size_t ecx_pkey_dirty_cnt(const EVP_PKEY *pkey) +{ + /* + * We provide no mechanism to "update" an ECX key once it has been set, + * therefore we do not have to maintain a dirty count. + */ + return 1; +} + +static int ecx_pkey_export_to(const EVP_PKEY *from, void *to_keydata, + EVP_KEYMGMT *to_keymgmt) +{ + const ECX_KEY *key = from->pkey.ecx; + OSSL_PARAM_BLD tmpl; + OSSL_PARAM *params = NULL; + int rv = 0; + + ossl_param_bld_init(&tmpl); + + /* A key must at least have a public part */ + if (!ossl_param_bld_push_octet_string(&tmpl, OSSL_PKEY_PARAM_PUB_KEY, + key->pubkey, key->keylen)) + goto err; + + if (key->privkey != NULL) { + if (!ossl_param_bld_push_octet_string(&tmpl, + OSSL_PKEY_PARAM_PRIV_KEY, + key->privkey, key->keylen)) + goto err; + } + + params = ossl_param_bld_to_param(&tmpl); + + /* We export, the provider imports */ + rv = evp_keymgmt_import(to_keymgmt, to_keydata, OSSL_KEYMGMT_SELECT_ALL, + params); + + err: + ossl_param_bld_free(params); + return rv; +} + const EVP_PKEY_ASN1_METHOD ecx25519_asn1_meth = { EVP_PKEY_X25519, EVP_PKEY_X25519, @@ -442,6 +486,8 @@ const EVP_PKEY_ASN1_METHOD ecx25519_asn1_meth = { ecx_set_pub_key, ecx_get_priv_key, ecx_get_pub_key, + ecx_pkey_dirty_cnt, + ecx_pkey_export_to }; const EVP_PKEY_ASN1_METHOD ecx448_asn1_meth = { @@ -485,6 +531,8 @@ const EVP_PKEY_ASN1_METHOD ecx448_asn1_meth = { ecx_set_pub_key, ecx_get_priv_key, ecx_get_pub_key, + ecx_pkey_dirty_cnt, + ecx_pkey_export_to }; static int ecd_size25519(const EVP_PKEY *pkey)