On 14/04/12 11:32, opensshelpmeplz wrote:
I need to generate a public EC key given a private EC key that I provide
myself. Is it possible to do this with OpenSSL? I have no problems to
generate a key pair , and I know how to set private and public key to
specific values, but is there some way to give it a private key and get a
corresponding public key that is tied to the provided private key? I am
using the Ruby wrapper for what it is worth....

thanks for any help, I have spent many hours trying to figure this out now.
There is no direct way in the API to do this. However it is easy to achieve. An EC private key is a random number of size up to the order of the group.

A public key can be calculated from the private key simply by multiplying the generator for the group by the private key.

I am not familiar with the Ruby bindings but in C you would do this as follows:

pub_key = EC_POINT_new(group);
if (pub_key == NULL)
        goto err;
    }
if(!EC_POINT_mul(group, pub_key, priv_key, NULL, NULL, ctx))
    goto err;

ec_key = EC_KEY_new();
if(ec_key == NULL)
    goto err;
if(!EC_KEY_set_group(ec_key, group))
    goto err;
if(!EC_KEY_set_private_key(ec_key, priv_key))
    goto err;
if(!EC_KEY_set_public_key(ec_key, pub_key))
    goto err;


 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