Coherence
Search…
ECDH
In order to understand hex and type parameters read HASH

ECDH

spec
Description: Public-key cryptosystem
Problem: Discrete logarithm problem
Uses: Key exchange

How to ???

1
import requests
2
import json
3
import os,binascii
4
5
def sending(message):
6
url = 'http://127.0.0.1:6613/'
7
response = requests.post(url, data=message)
8
print response.content
9
return response.content
10
11
def ecdh(data_js):
12
req=json.loads(data_js)
13
curve=req["curve"]
14
print "Send gen parameters (A): \n " + json.dumps(req) +"\n"
15
data_js_n=sending(json.dumps(req))
16
answ=json.loads(data_js_n)
17
print "Recived gen parameters donde (A): \n" + (json.dumps(answ)) +"\n\n\n"
18
data_js_n=sending(json.dumps(req))
19
print "Send gen parameters (B): \n " + json.dumps(req) +"\n"
20
answ_1=json.loads(data_js_n)
21
print "Recived gen parameters donde (B): \n" + (json.dumps(answ_1)) +"\n\n\n"
22
gen='{ "version":1 , "algorithm":"ECDH","family": "", "privkey":"","sharedpub":"", "operation":"agree"}'
23
req=json.loads(gen)
24
req["privkey"]=answ["privkey"]
25
req["sharedpub"]=answ_1["pubkey"]
26
req["curve"]=curve
27
print "Send agreetment (A): \n " + json.dumps(req) +"\n"
28
data_js_n=sending(json.dumps(req))
29
answ_2=json.loads(data_js_n)
30
print "Recived agreetment donde (A): \n" + (json.dumps(answ_2)) +"\n\n\n"
31
req["privkey"]=answ_1["privkey"]
32
req["sharedpub"]=answ["pubkey"]
33
print "Send agreetment (B): \n " + json.dumps(req) +"\n"
34
data_js_n=sending(json.dumps(req))
35
answ_3=json.loads(data_js_n)
36
print "Recived agreetment donde (B): \n" + (json.dumps(answ_3)) +"\n\n\n"
37
38
39
ecdh_gen='{ "version": 1 , "algorithm":"ECDH", "curve":"secp256k1", "operation":"gen"}'
40
ecdh(ecdh_gen)
Copied!
In this example we generate keys for A and B, and we make a key exchange between A and B.
On "curve" can be one of {"brainpoolP512r1","secp521r1","brainpoolP384r1","secp384r1","brainpoolP320r1","brainpoolP256r1", "secp256k1","sect571r1","sect571k1","sect409r1","sect409k1","sect283r1","sect283k1"}
Json to gen
1
{ "version": 1 , "algorithm":"ECDH", "curve":"curve flavor", "operation":"gen"}
Copied!
Json to key agreetment
1
{ "version":1 , "algorithm":"ECDH","family": "", "privkey":" your hex privkey",
2
"sharedpub":"your partnert hex pubkey", "operation":"agree","curve":"curve flavor"}
Copied!
Last modified 9mo ago
Copy link