# DSA

[Digital signatures video](https://www.youtube.com/watch?v=jbBe4AS5pk0\&index=18\&list=PL6N5qY2nvvJE8X75VkXglSrVhLv1tVcfy)

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

### DSA

[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 dsa(data_js, bits):
    req=json.loads(data_js)
    req["length"]=bits
    print "Send gen parameters : \n " + json.dumps(req) +"\n"
    data_js_n=sending(json.dumps(req))
    answ=json.loads(data_js_n)
    print "Recived  dsa gen: \n"+(json.dumps(answ)) +"\n\n\n"
    json_s=json_v='{ "version": 1 , "algorithm":"DSA", "type":"string","plaintext": "Hello world!", "hex":0,"privkey": "" ,"operation":"sign"}'
    req=json.loads(json_s)
    req["privkey"]=answ["privkey"]
    print "Send sign : \n " + json.dumps(req) +"\n"
    data_js_n=sending(json.dumps(req))
    answ_1=json.loads(data_js_n)
    print "Recived  sign done: \n"+(json.dumps(answ_1)) +"\n\n\n"
    json_v='{ "version": 1 , "algorithm":"DSA", "type":"string","plaintext": "Hello world!", "hex":0,"pubkey": "" ,"sign":"","operation":"verify"}'
    req=json.loads(json_v)
    req["pubkey"]=answ["pubkey"]
    req["sign"]=answ_1["sign"]
    print "Send verify : \n " + json.dumps(req) +"\n"
    data_js_n=sending(json.dumps(req))
    answ_2=json.loads(data_js_n)
    print "Recived  verify done: \n"+(json.dumps(answ_2)) +"\n\n\n"


dsa_gen='{ "version": 1 , "algorithm":"DSA", "operation":"gen", "length": 0 }'
dsa(dsa_gen,1024)
```

In this example we generate a DSA key (1024 bits), we sign *"Hello world!"* and validate it.

Json to generate

```javascript
{"operation": "gen", "version": 1, "length": INT, "algorithm": "DSA"}
```

* Length can be 1024, 2048 and 3072

Json to sign string

```javascript
{"algorithm": "DSA", "plaintext": "your string", "hex": BOOL, "version": 1, "operation": "sign", "type": "string", "privkey": "your private key"}
```

Json to validate string

```javascript
{"algorithm": "DSA", "plaintext": "Hello world", "pubkey": "your hex pubkey", "hex": 0, "sign": "your hex signature", "version": 1, "operation": "verify", "type": "string"}
```


---

# 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/dsa.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.
