/
text.py
44 lines (30 loc) · 992 Bytes
/
text.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
from Crypto.PublicKey import RSA
from Crypto.Hash import SHA256
from random import SystemRandom
# Signing authority (SA) key
priv = RSA.generate(3072)
pub = priv.publickey()
## Protocol: Blind signature ##
# must be guaranteed to be chosen uniformly at random
r = SystemRandom().randrange(pub.n >> 10, pub.n)
msg = 'OStoLFQC'# large message (larger than the modulus)
msg = str.encode(msg)
# hash message so that messages of arbitrary length can be signed
hash = SHA256.new()
hash.update(msg)
msgDigest = hash.digest()
# user computes
msg_blinded = pub.blind(msgDigest, r)
# SA computes
msg_blinded_signature = priv.sign(msg_blinded, 0)
# user computes
msg_signature = pub.unblind(msg_blinded_signature[0], r)
print('----msg_signature---------')
print(msg_signature)
# Someone verifies
hash = SHA256.new()
hash.update(msg)
msgDigest = hash.digest()
print('------msgDigest---------')
print(msgDigest)
print("Message is authentic: " + str(pub.verify(msgDigest, (msg_signature,))))