Coherence
Search…
Curve-25519
Why?
spec
Description: Public-key cryptosystem
Problem: Discrete logarithm problem
Uses: Digital signatures and Key exchange
  • It only supports "type":"string"

How to Ed25519?

1
import requests
2
import json
3
import os,binascii
4
5
def sending(message):
6
url = 'http://127.0.0.1:6613/'
7
response = requests.post(url, data=message)
8
print response.content
9
return response.content
10
11
def ed25519(data_js):
12
req=json.loads(data_js)
13
print "Send gen parameters : \n " + json.dumps(req) +"\n"
14
data_js_n=sending(json.dumps(req))
15
answ=json.loads(data_js_n)
16
print "Recived ed25519 gen: \n"+(json.dumps(answ)) +"\n\n\n"
17
json_s=json_v='{ "version": 1 , "algorithm":"ED25519", "type":"string","plaintext": "Hello world!", "hex":0,"privkey": "" ,"operation":"sign"}'
18
req=json.loads(json_s)
19
req["privkey"]=answ["privkey"]
20
print "Send sign : \n " + json.dumps(req) +"\n"
21
data_js_n=sending(json.dumps(req))
22
answ_1=json.loads(data_js_n)
23
print "Recived sign done: \n"+(json.dumps(answ_1)) +"\n\n\n"
24
json_v='{ "version": 1 , "algorithm":"ED25519", "type":"string","plaintext": "Hello world!", "hex":0,"pubkey": "" ,"sign":"","operation":"verify"}'
25
req=json.loads(json_v)
26
req["pubkey"]=answ["pubkey"]
27
req["sign"]=answ_1["sign"]
28
print "Send verify : \n " + json.dumps(req) +"\n"
29
data_js_n=sending(json.dumps(req))
30
answ_2=json.loads(data_js_n)
31
print "Recived verify done: \n"+(json.dumps(answ_2)) +"\n\n\n"
32
33
ed25519_gen='{ "version": 1 , "algorithm":"ED25519", "operation":"gen"}'
34
ed25519(ed25519_gen)
Copied!
Json to gen
1
{"operation": "gen", "version": 1, "algorithm": "ED25519"}
Copied!
Json to sign
1
{"algorithm": "ED25519", "plaintext": "your string", "hex": BOOL, "version": 1, "operation": "sign",
2
"type": "string", "privkey": "your hex privkey"}
Copied!
Json to verify
1
{"algorithm": "ED25519", "plaintext": "Hello world!", "pubkey": "your hex pubkey", "hex": BOOL,
2
"sign": "your hex signature", "version": 1, "operation": "verify", "type": "string"}
Copied!

How to X25519?

1
import socket
2
import json
3
import os,binascii
4
5
def sending(message):
6
ip = '127.0.0.1'
7
port = 6613
8
BUFFER_SIZE = 65536
9
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
10
s.connect((ip, port))
11
s.send(message)
12
data = s.recv(BUFFER_SIZE)
13
s.close()
14
return data
15
16
def x25519():
17
x25519_gen='{ "version": 1 , "algorithm":"X25519", "operation":"gen"}'
18
req=json.loads(x25519_gen)
19
print "Send gen parameters (A): \n " + json.dumps(req) +"\n"
20
data_js_n=sending(json.dumps(req))
21
answ=json.loads(data_js_n)
22
print "Recived gen parameters donde (A): \n" + (json.dumps(answ)) +"\n\n\n"
23
data_js_n=sending(json.dumps(req))
24
print "Send gen parameters (B): \n " + json.dumps(req) +"\n"
25
answ_1=json.loads(data_js_n)
26
print "Recived gen parameters donde (B): \n" + (json.dumps(answ_1)) +"\n\n\n"
27
agree='{ "version":1 , "algorithm":"X25519", "privkey":"","sharedpub":"", "operation":"agree"}'
28
req=json.loads(agree)
29
req["privkey"]=answ["privkey"]
30
req["sharedpub"]=answ_1["pubkey"]
31
print "Send agreetment (A): \n " + json.dumps(req) +"\n"
32
data_js_n=sending(json.dumps(req))
33
answ_2=json.loads(data_js_n)
34
print "Recived agreetment donde (A): \n" + (json.dumps(answ_2)) +"\n\n\n"
35
req["privkey"]=answ_1["privkey"]
36
req["sharedpub"]=answ["pubkey"]
37
print "Send agreetment (B): \n " + json.dumps(req) +"\n"
38
data_js_n=sending(json.dumps(req))
39
answ_3=json.loads(data_js_n)
40
print "Recived agreetment donde (B): \n" + (json.dumps(answ_3)) +"\n\n\n"
41
42
x25519()
Copied!
Json to gen
1
{"operation": "gen", "version": 1, "algorithm": "X25519"}
Copied!
Json to agree
1
{"operation": "agree", "version": 1, "sharedpub": "your partnert hex pubkey",
2
"algorithm": "X25519", "privkey": "your hex privkey"}
Copied!
Last modified 9mo ago