Coherence
Search…
DH

DH

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

How to ???

1
#!/usr/bin/env python
2
3
import requests
4
import json
5
import os,binascii
6
7
def sending(message):
8
url = 'http://127.0.0.1:6613/'
9
response = requests.post(url, data=message)
10
print response.content
11
return response.content
12
13
def dh(data_js):
14
req=json.loads(data_js)
15
print "Send gen parameters (A): \n " + json.dumps(req) +"\n"
16
data_js_n=sending(json.dumps(req))
17
answ=json.loads(data_js_n)
18
print "Recived gen parameters donde (A): \n" + (json.dumps(answ)) +"\n\n\n"
19
data_js_n=sending(json.dumps(req))
20
print "Send gen parameters (B): \n " + json.dumps(req) +"\n"
21
answ_1=json.loads(data_js_n)
22
print "Recived gen parameters donde (B): \n" + (json.dumps(answ_1)) +"\n\n\n"
23
gen='{ "version":1 , "algorithm":"DH","family": "", "privkey":"","sharedpub":"", "operation":"a_rfc"}'
24
req=json.loads(gen)
25
req["family"]=answ["family"]
26
req["privkey"]=answ["privkey"]
27
req["sharedpub"]=answ_1["pubkey"]
28
print "Send agreetment (A): \n " + json.dumps(req) +"\n"
29
data_js_n=sending(json.dumps(req))
30
answ_2=json.loads(data_js_n)
31
print "Recived agreetment donde (A): \n" + (json.dumps(answ_2)) +"\n\n\n"
32
req["privkey"]=answ_1["privkey"]
33
req["sharedpub"]=answ["pubkey"]
34
print "Send agreetment (B): \n " + json.dumps(req) +"\n"
35
data_js_n=sending(json.dumps(req))
36
answ_3=json.loads(data_js_n)
37
print "Recived agreetment donde (B): \n" + (json.dumps(answ_3)) +"\n\n\n"
38
39
40
dh_gen='{ "version": 1 , "algorithm":"DH", "family": "modp256", "operation":"gen_rfc"}'
41
dh(dh_gen)
Copied!
In this example we generate keys for A and B, and we make a key exchange between A and B.
On "family" parameneter can be {"modp256","modp160","modp224"}
Json to gen
1
{ "version": 1 , "algorithm":"DH", "family": "mod flavor", "operation":"gen_rfc"}
Copied!
Json to key agreetment
1
{ "version":1 , "algorithm":"DH","family": "mod flavor", "privkey":" your hex privkey",
2
"sharedpub":"your partnert hex pubkey", "operation":"a_rfc"}
Copied!
Copy link
Contents
DH
How to ???