Skip to content

Curve 25519

Liesware edited this page Apr 15, 2019 · 1 revision

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?

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 ed25519(data_js):
	req=json.loads(data_js)
	print "Send gen parameters : \n " + json.dumps(req) +"\n"
	data_js_n=sending(json.dumps(req))
	answ=json.loads(data_js_n)
	print "Recived  ed25519 gen: \n"+(json.dumps(answ)) +"\n\n\n"
	json_s=json_v='{ "version": 1 , "algorithm":"ED25519", "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":"ED25519", "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"

ed25519_gen='{ "version": 1 , "algorithm":"ED25519", "operation":"gen"}'
ed25519(ed25519_gen)

Json to gen

{"operation": "gen", "version": 1, "algorithm": "ED25519"}

Json to sign

{"algorithm": "ED25519", "plaintext": "your string", "hex": BOOL, "version": 1, "operation": "sign", 
"type": "string", "privkey": "your hex privkey"}

Json to verify

{"algorithm": "ED25519", "plaintext": "Hello world!", "pubkey": "your hex pubkey", "hex": BOOL, 
"sign": "your hex signature", "version": 1, "operation": "verify", "type": "string"}

How to X25519?

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 x25519():
	x25519_gen='{ "version": 1 , "algorithm":"X25519", "operation":"gen"}'
	req=json.loads(x25519_gen)
	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"
	agree='{ "version":1 , "algorithm":"X25519", "privkey":"","sharedpub":"", "operation":"agree"}'
	req=json.loads(agree)
	req["privkey"]=answ["privkey"]
	req["sharedpub"]=answ_1["pubkey"]
	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"

x25519()

Json to gen

{"operation": "gen", "version": 1, "algorithm": "X25519"}

Json to agree

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