-
Notifications
You must be signed in to change notification settings - Fork 0
/
sign_generation.py
32 lines (27 loc) · 1.05 KB
/
sign_generation.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
from ecdsa import SigningKey,VerifyingKey,BadSignatureError, NIST192p
import ecdsa
import sys
#Curve details-
#NIST192p: siglen= 48, keygen=0.160s, sign=0.058s, verify=0.116s;
def generate_keys():
priv_key = SigningKey.generate(curve=NIST192p)
pub_key = priv_key.get_verifying_key()
open("priv_key.pem",'w').write(priv_key.to_pem())
open("pub_key.pem",'w').write(pub_key.to_pem())
#print type(priv_key)
#print type(pub_key)
print sys.getsizeof(pub_key.to_string())
print len(pub_key.to_string())
print sys.getsizeof(VerifyingKey.from_string(pub_key.to_string(),curve=NIST192p))
#print sys.getsizeof(pub_key.to_string())
def generate_sign():
priv_key = SigningKey.from_pem(open("priv_key.pem").read())
print "privkey" + str(sys.getsizeof(priv_key))
message = open("message_file","rb").read()
sign = priv_key.sign(message);
print "sign1" + str(sys.getsizeof(sign))
print len(sign)
open("signature","wb").write(sign);
print "sign2" + str(sys.getsizeof(sign))
generate_keys();
generate_sign();