-
Notifications
You must be signed in to change notification settings - Fork 0
/
chaum_pedersen.py
38 lines (31 loc) · 914 Bytes
/
chaum_pedersen.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
import secrets
import sys
import gensafeprime
def start(x):
# PROVER REGISTRATION
p = gensafeprime.generate(1024) # send to verifier
q = (p-1)//2
g = 81 # public
h = 121 # public
y1 = pow(g, x, p) # send to verifier
y2 = pow(h, x, p) # send to verifier
# PROVER LOGIN ROUND 1
k = secrets.randbelow(sys.maxsize - 1)
r1 = pow(g, k, p) # send to verifier
r2 = pow(h, k, p) # send to verifier
# VERIFIER LOGIN ROUND 1
c = secrets.randbelow(sys.maxsize - 1) # send to prover
# PROVER LOGIN ROUND 2
s = (k - (c*x)) % q # send to verifier
# VERIFIER LOGIN ROUND 2
r1_comp = (pow(g, s, p) * pow(y1, c, p)) % p
if(r1_comp != r1):
return False
r2_comp = (pow(h, s, p) * pow(y2, c, p)) % p
if(r2_comp != r2):
return False
return True
if __name__ == "__main__":
sercret = 35
res = start(sercret)
print(res)