> For the complete documentation index, see [llms.txt](https://coherence.3vidence.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://coherence.3vidence.com/ecc.md).

# ECC

## ECC

[ECC intro video](https://www.youtube.com/watch?v=IGqrbM52wtg\&index=14\&list=PL6N5qY2nvvJE8X75VkXglSrVhLv1tVcfy)

[ECC video](https://www.youtube.com/watch?v=vnpZXJL6QCQ\&list=PL6N5qY2nvvJE8X75VkXglSrVhLv1tVcfy\&index=16)

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

### ECIES

[spec](https://www.cryptopp.com/wiki/Elliptic_Curve_Integrated_Encryption_Scheme)

Description: Public-key cryptosystem

Problem: Discrete logarithm problem

Uses: Encrypt

* It only supports "type":"string"

### ECDSA

[spec](https://www.nist.gov/publications/digital-signature-standard-dss-2)

Description: Public-key cryptosystem

Problem: Discrete logarithm problem

Uses: Digital signatures

* It only supports "type":"string"

## 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 ecc_pb(data_js):
    req=json.loads(data_js)
    curve=req["curve"]
    print "Send gen parameters : \n" + data_js +"\n"
    data_js_n=sending(json.dumps(req))
    answ=json.loads(data_js_n)
    print 'Recived  ecc gen: \n'+ json.dumps(answ) +"\n\n\n"
    json_enc='{ "version": 1 , "algorithm":"ECIES", "type":"string","pubkey": "" ,"operation":"enc", "plaintext":"Hello world!" ,"curve":""}'
    req=json.loads(json_enc)
    req["pubkey"]=answ["pubkey"]
    req["curve"]=curve
    print "Send  enc: \n"+(json.dumps(req))+"\n"
    data_js_n=sending(json.dumps(req))
    answ_1=json.loads(data_js_n)
    print "Recived  enc : \n"+(json.dumps(answ_1)) +"\n"
    req["privkey"]=answ["privkey"]
    req["plaintext"]=answ_1["result"]
    req["pubkey"]=""
    req["operation"]="dec"
    data_js_n=sending(json.dumps(req))
    answ_2=json.loads(data_js_n)
    print "Recived  dec done: \n"+(json.dumps(answ_2)) +"\n\n\n"
    json_sign='{ "version": 1 , "algorithm":"ECDSA", "type":"string","plaintext": "Hello world", "hex":0,"privkey": "" ,"operation":"sign"}'
    req=json.loads(json_sign)
    req["privkey"]=answ["privkey"]
    req["curve"]=curve
    data_js_n=sending(json.dumps(req))
    answ_3=json.loads(data_js_n)
    print "Recived  sign done: \n"+(json.dumps(answ_3)) +"\n"
    json_verify='{ "version": 1 , "algorithm":"ECDSA", "type":"string","plaintext": "Hello world", "hex":0,"pubkey": "", "operation":"verify","sign":""}'
    req=json.loads(json_verify)
    req["pubkey"]=answ["pubkey"]
    req["sign"]=answ_3["sign"]
    req["curve"]=curve
    data_js_n=sending(json.dumps(req))
    answ_4=json.loads(data_js_n)
    print "Recived  verify done: \n"+(json.dumps(answ_4)) +"\n\n\n"


ecc_gen='{ "version": 1 , "algorithm":"ECC_GEN", "curve":"secp256k1"}'
ecc_pb(ecc_gen)
```

In this example we generate a ECC key (secp256k1), sign and validate "Hello world!" string, we enc and dec "Hello world!" string.

On *"curve"* can be one of *{"brainpoolP512r1","secp521r1","brainpoolP384r1","secp384r1","brainpoolP320r1","brainpoolP256r1", "secp256k1","sect571r1","sect571k1","sect409r1","sect409k1","sect283r1","sect283k1"}*

The default hash function to sign is sha3*256, you can change by adding* "hash*sign"* and can be one of *{"sha3\_512","sha3\_384","sha3\_256","sha3\_224","sha\_512","sha\_384","sha\_256","sha\_224","sha\_1","whirlpool"}*

Json to gen

```javascript
{ "version": 1 , "algorithm":"ECC_GEN", "curve":"curve flavor"}
```

Json to enc

```javascript
{ "version": 1 , "algorithm":"ECIES", "type":"string", "hex":BOOL,"pubkey": "your hex pubkey",
"operation":"enc", "plaintext":"your string" ,"curve":"curve flavor"}
```

Json to dec

```javascript
{ "version": 1 , "algorithm":"ECIES", "type":"string","privkey": "your hex privkey" ,
"operation":"dec", "plaintext":"your hex enc string" ,"curve":"curve flavor"}
```

Json to sign

```javascript
{ "version": 1 , "algorithm":"ECDSA", "type":"string","plaintext": "your string", "hex":BOOL,
"privkey": " your hex pirvkey" ,"operation":"sign","curve":"curve flavor"}
```

Json to verify

```javascript
{ "version": 1 , "algorithm":"ECDSA", "type":"string","plaintext": "your string", "hex":BOOL,
"pubkey": "your hex pubkey" ,"sign":"your hex signature","operation":"verify","curve":"curve flavor"}
```
