I'm trying to do the following:
- Receive x and y coordinates of a EC public key
- Generate a random EC public key
- Compute the shared secret of the two keys
I'm stuck at the last step, from the Documentation is seems like I have to use ECDH<ECP>::Domain but nowhere is it explained how to convert the keys into the required SecByteBlock objects, how can I do this? Pseudocode follows.
std::string x = ...
std::string y = ...
auto make_curve = []{ return ASN1::secp256r1(); };
// Public key
ECDSA<ECP, SHA256>::PublicKey g_a;
g_a.Initialize(make_curve(),
ECP::Point {
Integer { x.data() },
Integer { y.data() }
});
// Private key
ECDSA<ECP, SHA256>::PrivateKey g_b;
g_b.Initialize(RANDOM_POOL, make_curve());
// Compute shared secret
ECDH<ECP>::Domain agreement { make_curve() };
SecByteBlock shared_secret_buf { agreement.AgreedValueLength() };
agreement.Agree(shared_secret_buf, ???, ???);