Bitcoin Forum
July 21, 2018, 06:55:21 AM *
News: Latest stable version of Bitcoin Core: 0.16.1  [Torrent]. (New!)
   Home   Help Search Donate Login Register  
Pages: [1]
Author Topic: Elliptic curve Diffie-Hellman example  (Read 1004 times)
Michael Hendricks
Sr. Member
Offline Offline

Activity: 447
Merit: 250

View Profile
April 12, 2013, 06:27:25 PM

Diffie-Hellman key agreement is really easy using elliptic curves.  Maybe because of that, I was unable to find a good, working example with which to experiment, so I wrote one: 32 lines of Go.  It should be equally short for any other language that has a decent EC math library.

Here's a sample run:

$ go run ecc.go
Alice: c84fd9a9c8538375d86d4fb03f6651ed62431d236584d07d45048432
Bob: a2101edbea799523a0ab0cf0281e32cc39fdca05a7b6cb8c9e534f6c

Alice: 21477883440431114094502151543289380813227450324823096547884771069269
Bob:   21477883440431114094502151543289380813227450324823096547884771069269

The first 4 lines show Alice and Bob's private and public keys, respectively.  The final 2 lines show that they each calculate the same shared secret.  The example uses curve P-224 instead of secp256k1 since the former is part of Go's library.
Pages: [1]
Jump to:  

Sponsored by , a Bitcoin-accepting VPN.
Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!