Skip to content
Liesware edited this page Jan 29, 2019 · 1 revision

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 ???

import socket
import json
import os,binascii

def sending(message):
	ip = '127.0.0.1'
	port = 6613
	BUFFER_SIZE = 65536
	s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
	s.connect((ip, port))
	s.send(message)
	data = s.recv(BUFFER_SIZE)
	s.close()
	return data

def ecdh(data_js):
	req=json.loads(data_js)
	curve=req["curve"]
	print "Send gen parameters (A): \n " + json.dumps(req) +"\n"
	data_js_n=sending(json.dumps(req))
	answ=json.loads(data_js_n)
	print "Recived gen parameters donde (A): \n" + (json.dumps(answ)) +"\n\n\n"
	data_js_n=sending(json.dumps(req))
	print "Send gen parameters (B): \n " + json.dumps(req) +"\n"
	answ_1=json.loads(data_js_n)
	print "Recived gen parameters donde (B): \n" + (json.dumps(answ_1)) +"\n\n\n"
	gen='{ "version":1 , "algorithm":"ECDH","family": "", "privkey":"","sharedpub":"", "operation":"agree"}'
	req=json.loads(gen)
	req["privkey"]=answ["privkey"]
	req["sharedpub"]=answ_1["pubkey"]
	req["curve"]=curve
	print "Send agreetment (A): \n " + json.dumps(req) +"\n"
	data_js_n=sending(json.dumps(req))
	answ_2=json.loads(data_js_n)
	print "Recived agreetment donde (A): \n" + (json.dumps(answ_2)) +"\n\n\n"
	req["privkey"]=answ_1["privkey"]
	req["sharedpub"]=answ["pubkey"]
	print "Send agreetment (B): \n " + json.dumps(req) +"\n"
	data_js_n=sending(json.dumps(req))
	answ_3=json.loads(data_js_n)
	print "Recived agreetment donde (B): \n" + (json.dumps(answ_3)) +"\n\n\n"


ecdh_gen='{ "version": 1 , "algorithm":"ECDH", "curve":"secp256k1", "operation":"gen"}'
ecdh(ecdh_gen)

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

{ "version": 1 , "algorithm":"ECDH", "curve":"curve flavor", "operation":"gen"}

Json to key agreetment

{ "version":1 , "algorithm":"ECDH","family": "", "privkey":" your hex privkey",
"sharedpub":"your partnert hex pubkey", "operation":"agree","curve":"curve flavor"}
You can’t perform that action at this time.