Bitcoin Forum
October 23, 2017, 07:17:10 PM *
News: Latest stable version of Bitcoin Core: 0.15.0.1  [Torrent]. (New!)
 
   Home   Help Search Donate Login Register  
Pages: [1]
  Print  
Author Topic: Elliptic curve Diffie-Hellman example  (Read 984 times)
mndrix
Michael Hendricks
VIP
Sr. Member
*
Offline Offline

Activity: 447


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

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
       18424947940967940791172868542123538214411876209787668504243298468721
Bob: a2101edbea799523a0ab0cf0281e32cc39fdca05a7b6cb8c9e534f6c
     25522202360313088829965757364820961191890334919586259842035197968775

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]
  Print  
 
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!