From: Nokan Emiro Date: 2012-10-28T05:59:21+09:00 Subject: Re: OpenSSL ECDSA public key from private --f46d04448141ca1f3904cd10b5f4 Content-Type: text/plain; charset=UTF-8 Much better, but it's still not finished... ;-) I had a look at the ruby code. #generate_key just calls openssl > function "EC_KEY_generate_key". From openssl.sourcearchive.com, I see > that, within that function, the public key is generated with > > if (eckey->pub_key == NULL) > { > pub_key = EC_POINT_new(eckey->group); > if (pub_key == NULL) > goto err; > } > > Thanks for looking at the source. I guess this is just the creation (memory allocation?) of the point object (yes, the public key is a point with X and Y coordinates in Elliptic Curve crypto), but the calculation of this point using the private key (which is a number, not a point) must be somewhere in the next few lines in the source. > EC_POINT_new is used within Ruby when creating an > OpenSSL::PKey::EC::Point object, when passing it a 'group'. Now, I > have no idea what a group is, but your key has a 'group'. And it is > populated, even without calling #generate_key. > > If I run > > pub_key=OpenSSL::PKey::EC::Point.new(key.group) > > I get something. Again, I hope this is what you are looking for. > As far as I can see this creates a point with (0, 0) coordinates. (The .to_bn converts a point to an OpenSSL::BN, which is a Big Number, where (I think) the first N bit belongs to the X coordinate and the other bits to the Y, but to_bn answers 0.) According to this... http://stackoverflow.com/questions/12480776/how-do-i-obtain-the-public-key-from-an-ecdsa-private-key-in-openssl ...I think EC_POINT_mul() could be a solution. It's a C function in OpenSSL, and it does the calculation I need. But I don't know much about how Ruby and C are married in native gems, and I think the Ruby API does not allow me to call this C function. :( Or does it? The API should support private-to-public key calculations, however... --f46d04448141ca1f3904cd10b5f4 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Much better, but it's still not finished... =C2=A0;-)

I had a look at the ruby code. #generate_key just calls openssl
function "EC_KEY_generate_key". From =C2=A0openssl.sourcearchive.com, I s= ee
that, within that function, the public key is generated with

=C2=A0 =C2=A0 =C2=A0 if (eckey->pub_key =3D=3D NULL)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 {
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 pub_key =3D EC_POINT_new(eckey-&g= t;group);
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 if (pub_key =3D=3D NULL)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 goto err; =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 }


Thanks for looking at the source. =C2= =A0I guess this is just the creation
(memory allocation?) of the = point object (yes, the public key is a
point with X and Y coordin= ates in Elliptic Curve crypto), but the
calculation of this point using the private key (which is a number,
not a point) must be somewhere in the next few lines in the source.=
=C2=A0
EC_POINT_new is used within Ruby when creating an
OpenSSL::PKey::EC::Point object, when passing it a 'group'. Now, I<= br> have no idea what a group is, but your key has a 'group'. And it is=
populated, even without calling #generate_key.

If I run

pub_key=3DOpenSSL::PKey::EC::Point.new(key.group)

I get something. Again, I hope this is what you are looking for.

As far as I can see this creates a point with (0,= 0) coordinates.
(The .to_bn converts a point to an OpenSSL::BN, = which is a
Big Number, where (I think) the first N bit belongs to the X
coordinate=C2=A0and the other bits to the Y, but to_bn answers 0.)

According to this...

http://stackoverflow.com/questions/12= 480776/how-do-i-obtain-the-public-key-from-an-ecdsa-private-key-in-openssl<= /a>

...I think EC_POINT_mul() could be a solution. =C2=A0It= 's a C function
in OpenSSL, and it does the calculation I nee= d. =C2=A0But I don't know
much about how Ruby and C are marri= ed in native gems, and
I think the Ruby API does not allow me to call this C function. :(

Or does it?

The API should s= upport private-to-public key calculations, however...


--f46d04448141ca1f3904cd10b5f4--