Q:

OpenSSL: Encrypt a symmetric key with an ECC public key

I have a symmetric key that I would like to encrypt with an ECC public key using OpenSSL. In its high-level portion, EVP, OpenSSL offers a solution to encrypt "an envelop", which is exactly what I need. 
However, I would like to have these in separate steps, not all in one, as OpenSSL offers in EVP. I would like to have control where I encrypt the symmetric key myself with OpenSSL, and encrypt the message using my own C++ wrappers, and put them both in my selected format.
How can I encrypt the just symmetric key with a public key using OpenSSL without having it encrypt the message as well? Is this doable?
I've tried to have zero-length plaintext in the example provided, but it crashes. Is this possible?
If not, how can I encrypt with a public key without EVP with an EC_KEY?

A:

Unlike RSA, encryption and decryption can't be performed directly with ECC.
The preferred way to do this is to create an ephemeral ECC key pair and use your private key and the receiver's public key to create a shared secret to encrypt the message with. Then you send the encrypted message along with the ECC public key you created. This scheme is called ECIES (Elliptic Curve Integrated Encryption Scheme).
You would need to call ECDH_compute_key to create the shared secret and pass it your ephemeral private key and the receiver's public key along with a pointer to a key derivation function (KDF) that you define.  The simplest KDF would be a hash of the x-coordinate of the output of the ECDH calculation. Whatever scheme you use, the other side would need to agree on the KDF that is being used.

