<div dir="ltr">Hello Openssl-users,<div><br></div><div>I'm trying to write some code that derives the shared secret for 2 elliptic curve keys ( i.e. does ECDH )</div><div><br></div><div>I am doing the following to load up both the local and remote EC key ( code shown for local side ):</div><div><br></div><div>EC_KEY* localEC = EC_KEY_new_by_curve_name( curveName );<br></div><div>EC_KEY_set_private_key( localEC, privateKeyLocal )<br></div><div>EC_KEY_set_public_key_affine_coordinates( localEC, publicXCoordLocal, publicYCoordLocal ) <br></div><div><br></div><div>I check the return values for all of these, as well as EC_KEY_check_key at the end. Everything returns non-zero, so I assume that it is good to go. I then do the following to turn the EC_KEY into an EVP_PKEY for ECDH:</div><div><br></div><div>pkey = EVP_PKEY_new();<br></div><div>EVP_PKEY_set1_EC_KEY( *pkey, localEC );<br></div><div><br></div><div>The same is done for the remote EC, except that the private key is not loaded up.</div><div><br></div><div>Now this is where things get weird.<br><br>I run code pretty similar to the example given here ( starting from EVP_PKEY_CTX_new() since I already have the pkey and peerkey. ( <a href="https://wiki.openssl.org/index.php/Elliptic_Curve_Diffie_Hellman">https://wiki.openssl.org/index.php/Elliptic_Curve_Diffie_Hellman</a> ) and it fails on the call to EVP_PKEY_derive()without an error message. I tried running into under gdb() and it gets to ecdh_check() before it's unable to fill in the ecdh_data structure, i.e. it returns it as NULL.</div><div><br></div><div>If I use the example code to generate the local EVP_PKEY with a random set of points on the correct curve, then run the following line, the key derivation will work with the parameters I read in:</div><div>( in this example, pkey is as in the example code, i.e. generated randomly. pkey2 is the one I made via EVP_PKEY_set1_EC_KEY )<br><br>EVP_PKEY_set1_EC_KEY( pkey, EVP_PKEY_get1_EC_KEY( pkey2 ) );</div><div><br></div><div>It would appear that there is something that EVP_PKEY_set1_EC_KEY is not setting, or perhaps that I need to add, but I'm unclear what that would be. Does anyone on this list have any ideas?</div><div><br></div><div>Much thanks,</div><div><br></div><div>Ethan</div></div>