Bitcoin Forum
November 13, 2024, 02:49:08 AM *
News: Check out the artwork 1Dq created to commemorate this forum's 15th anniversary
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: Elliptic curve Diffie-Hellman example  (Read 1129 times)
mndrix (OP)
Michael Hendricks
VIP
Sr. Member
*
Offline Offline

Activity: 447
Merit: 258


View Profile
April 12, 2013, 06:27:25 PM
Last edit: May 10, 2013, 04:51:34 PM by mndrix
 #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:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!