-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathblinds.py
71 lines (52 loc) · 1.71 KB
/
blinds.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
55
56
57
58
59
60
61
62
63
64
65
## Simple Examples of how to use pycrypto blind signs ###
##########################################################
import Crypto
import Crypto.PublicKey.RSA
from Crypto.Random.random import getrandbits
# key = RSA.generate(1024)
# key2 = RSA.generate(1024)
#
#
#
#
# #Syntax for verification
# key.verify(plaintext,key.sign(plaintext, 123L))
#
#
# #This gives original message back, "Hello"
# key.decrypt(key.encrypt( "Hello", 123L))
#
# NKey = RSA.generate(1024)
#
# #Blind with Notary, Sign by Notary, Unblind with notary (Sign with encrypt and decrypt)
# r = 3L
# blinded = NKey.blind(plaintext, r)
# k = 2L
# blindsigned = NKey.sign( blinded, k)
# signed = NKey.unblind( blindsigned[0], r)
# # NotaryKey.sign( plaintext, k) == signed
######### END OF EXAMPLES CODE##########################
#############################################################
###### This part of the code is for the voter communication##
###### with the Notary ###################################
#############################################################
#encrypt the vote with Paillier here
#PaillierEncryptedVote
#Load Notary public key from file
f = open('NotaryKey.pem','r')
NotaryPublic = RSA.importKey(f.read())
f.close()
f = open('CurrentVoter.pem', 'r')
VoterPrivate = RSA.importKey(f.read())#Add prompt for user passcode
f.close()
#Sign the randomBits
k = getrandbits(64)
x = VoterPrivate.sign(randomBits, k)
r = getrandbits(64) #make this more random/secure?
#blind the PaillierVote with Notary key
blinded = NotaryPublic.blind(PaillierEncryptedVote,r)
#Recieve the blind signed vote back
blindsigned
#Get PaillierVote with a signature on it
signed = NotaryPublic.unblind( blindsigned[0]. r)
#Now this can be sent to the server