Example #1
0
 def _sign_loop(self, r, s, h, k, priv):
     while r == 0 or s == 0:
         if k is None:
             k = (getrandbits(self.bits) % (self.N - 1)) + 1
         kinv = inv(k, self.N)
         kg = mulp(self.a, self.b, self.p, self.G, k)
         r = kg[0] % self.N
         if r == 0:
             continue
         s = (kinv * (h + r * priv)) % self.N
     return r, s
Example #2
0
 def verify(self, h, sig, pub):
     while h > self.N:
         h >>= 1
     r = self.bytes2int(sig[:self.bytes])
     s = self.bytes2int(sig[self.bytes:])
     if 0 < r < self.N and 0 < s < self.N:
         w = inv(s, self.N)
         u1 = (h * w) % self.N
         u2 = (r * w) % self.N
         x, y = muladdp(self.a, self.b, self.p, self.G, u1, pub, u2)
         return r % self.N == x % self.N
     return False
Example #3
0
 def sign(self, h, priv, k=None):
     while h > self.N:
         h >>= 1
     r = s = 0
     while r == 0 or s == 0:
         if k is None:
             k = (getrandbits(self.bits) % (self.N - 1)) + 1
         kinv = inv(k, self.N)
         kg = mulp(self.a, self.b, self.p, self.G, k)
         r = kg[0] % self.N
         if r == 0:
             continue
         s = (kinv * (h + r * priv)) % self.N
     return self.int2bytes(r) + self.int2bytes(s) 
Example #4
0
 def sign(self, h, priv, k=None):
     while h > self.N:
         h >>= 1
     r = s = 0
     while r == 0 or s == 0:
         if k is None:
             k = (getrandbits(self.bits) % (self.N - 1)) + 1
         kinv = inv(k, self.N)
         kg = mulp(self.a, self.b, self.p, self.G, k)
         r = kg[0] % self.N
         if r == 0:
             continue
         s = (kinv * (h + r * priv)) % self.N
     return self.int2bytes(r) + self.int2bytes(s)