def verify(self, msg, signature, y): r, s = signature # assert 0 < r < self.q assert 0 < s < self.q w = modinv(s, self.q) u1 = (sha1num(msg) * w) % self.q u2 = (r * w) % self.q v = (pow(self.g, u1, self.p) * pow(y, u2, self.p)) % self.p % self.q return v == r
def sign(self, msg, x): hash = sha1num(msg) return self.sign_hash(hash, x)