-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtest.py
54 lines (39 loc) · 1.33 KB
/
test.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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
from tdc_falcon import generate_keypair, sign, verify, priv_to_pub, generate_keypair_random
import binascii
import hashlib
import time
time_change = time.time()
salt = bytes.fromhex('aaef2d3f4d77ac66e9c5a6c3d8f921d1')
passwd = "Master Key".encode("utf8")
key = hashlib.pbkdf2_hmac('sha512', passwd, salt, iterations=500000, dklen=48)
print("Derived seed:", binascii.hexlify(key))
pub,priv=generate_keypair(key)
print("==== PUBKEY ====")
print(pub.hex())
print("==== PRIVKEY ====")
print(priv.hex())
print("==== PRIV TO PUB ====")
derived_pub=priv_to_pub(priv)
print(derived_pub.hex())
print("==== SIGNATURE ====")
sig=sign(priv, b'MESSAGE')
print(sig.hex())
print("==== VERIFY ====")
print(verify(pub,b'MESSAGE',sig))
print("==== VERIFY BAD MESSAGE ====")
print(verify(pub,b'BADMESSAGE',sig))
passwd1 = "Master Key 2".encode("utf8")
key1 = hashlib.pbkdf2_hmac('sha512', passwd1, salt, iterations=500000, dklen=48)
pub1,priv1=generate_keypair(key1)
sig1=sign(priv1,b'MESSAGE')
print("==== VERIFY BAD SIG ====")
print(verify(pub,b'MESSAGE',sig1))
print("==== VERIFY BAD PUB ====")
print(verify(pub1,b'MESSAGE',sig))
pub1,priv1=generate_keypair_random()
sig1=sign(priv1,b'MESSAGE')
print("==== VERIFY BAD SIG ====")
print(verify(pub,b'MESSAGE',sig1))
print("==== VERIFY BAD PUB ====")
print(verify(pub1,b'MESSAGE',sig))
print(time.time()-time_change)