-
Notifications
You must be signed in to change notification settings - Fork 0
/
schnorr_scheme_client.py
52 lines (40 loc) · 1.12 KB
/
schnorr_scheme_client.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
from random import randint
from src.dsa import DSABase
class SchnorrSchemeClient(DSABase):
def __init__(self):
super().__init__()
self._x = 0
self._s = 0
self._r = 0
self._e = 0
@property
def x(self) -> int:
return self._x
def gen_x(self):
pk = self.public_key
if pk.has_p and pk.has_q and pk.has_g:
p, q, g, _ = self.public_key.to_list()
if self._r == 0:
self.gen_r()
self._x = pow(g, self._r, p)
@property
def r(self) -> int:
return self._r
def gen_r(self):
if self.public_key.has_q:
self._r = randint(0, self.public_key.q - 1)
@property
def s(self) -> int:
return self._s
def gen_s(self):
pk = self.public_key
if pk.has_p and pk.has_q and pk.has_g:
p, q, g, _ = self.public_key.to_list()
w = self._keys_container.private_key
self._s = (self._r + w * self._e) % q
@property
def e(self) -> int:
return self._e
@e.setter
def e(self, e: int):
self._e = e