Yes, what I am implementing requires me to treat the shared secret as an
integer. I think I might be kind of close to figuring it out:
q = OpenSSL::PKey::EC.new("secp128r2")
q.generate_key
pub = OpenSSL::PKey::EC.new(q.group)
pub.public_key = q.public_key
a = pub.public_key.to_bn
ss = q.dh_compute_key(pub.public_key)
puts ss.unpack('I>*')
this puts a series of numbers such as the following:
2755907301
4161034086
221727499
1603331514
or
2041301904
2634281936
2269031273
1943826378
Just to see if this works, I have then been combining these into big
integers, so far just by hand. My theory is that if the resulting
integer is the same bit size as the curve, that it is an indication I
may not be doing it incorrectly. And I am so close to almost not
certainly doing it wrong, because sometimes it does make output that
equals 128 bits when I convert it to binary, for example
275590730141610340862217274991603331514
but alas sometimes it is slightly more or less than 128 bits, as with
2041301904263428193622690312731943826378
which is 131 bits
regardless of the curve I use the output is either the correct size or
near it, but I don't understand the variation.
ss.length always returns a number of bytes that when multiplied by 8 is
the size of the curve, assuming that the curve consists of a number of
bits that is divisible by 8 anyway.
I could be way off on this and doing it totally wrong, but since I hit a
total dead end I figured that I might as well try doing things until I
at least get the correct size integer and then try to confirm it as
being correct further from there, but I can just get close.
thanks :).
--
Posted via http://www.ruby-forum.com/.