On 10 April 2014 07:29, chetan <chet...@neominds.in> wrote:
> Thanks for giving time to me.  I was given a task that i have to implement
> ECDHE algorithm means i can use openssl.
> So, can you please tell me what i have to do after generatic public and
> private key files. How to generate shared secret and what next after that.
>  Thanks again
>

Well the "E" on the end of ECDHE stands for "Ephemeral" which means
that the public/private key pairs for one or both parties are
generated on the fly each time rather than being persisted (and hence
you would not normally need to use key files).

So broadly speaking the steps are:
The parties agree on their parameters (for ECDHE this means agreeing
on a curve to use)
The parties create their private/public key pairs and exchange their public keys
Each party derives the shared secret from a combination of their own
private key, and the peer public key
Although not strictly part of ECDHE itself, you would then normally
pass the shared secret through some subsequent hash algorithm (e.g.
SHA256) to create the shared key

HOW communication between the parties works is protocol specific
(ECDHE is just the algorithm and says nothing about the protocol). An
important point though is that ECHDE is vulnerable to
man-in-the-middle attacks if the exchange of parameters/keys is not
authenticated (typically you might use RSA to authenticate this)

See the code sample on the link I gave you for an outline of how to
put all this together. The actually key derivation bit is here (pkey
holds the private/public key, peerkey holds the peer's public key):

/* Create the context for the shared secret derivation */
if(NULL == (ctx = EVP_PKEY_CTX_new(pkey, NULL))) handleErrors();

/* Initialise */
if(1 != EVP_PKEY_derive_init(ctx)) handleErrors();

/* Provide the peer public key */
if(1 != EVP_PKEY_derive_set_peer(ctx, peerkey)) handleErrors();

/* Determine buffer length for shared secret */
if(1 != EVP_PKEY_derive(ctx, NULL, secret_len)) handleErrors();

/* Create the buffer */
if(NULL == (secret = OPENSSL_malloc(*secret_len))) handleErrors();

/* Derive the shared secret */
if(1 != (EVP_PKEY_derive(ctx, secret, secret_len))) handleErrors();


Hope that helps,

Matt
______________________________________________________________________
OpenSSL Project                                 http://www.openssl.org
User Support Mailing List                    openssl-users@openssl.org
Automated List Manager                           majord...@openssl.org

Reply via email to