# ECDH

In order to understand *hex* and *type* parameters read [HASH](https://github.com/liesware/coherence/wiki/Hash)

### ECDH

[spec](https://csrc.nist.gov/publications/detail/sp/800-56a/rev-2/final)

Description: Public-key cryptosystem

Problem: Discrete logarithm problem

Uses: Key exchange

## How to ???

```python
import requests
import json
import os,binascii

def sending(message):
    url = 'http://127.0.0.1:6613/'
    response = requests.post(url, data=message)
    print response.content
    return response.content

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

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

Json to key agreetment

```javascript
{ "version":1 , "algorithm":"ECDH","family": "", "privkey":" your hex privkey",
"sharedpub":"your partnert hex pubkey", "operation":"agree","curve":"curve flavor"}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://coherence.3vidence.com/ecdh.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
