def verify(self, message, signature): p, q, a, y = self.prover_key w, s = signature h = calc_hash(message, sha256) v = pow(h, q - 2, q) z1 = positive_mod(s * v, q) z2 = positive_mod((q - w) * v, q) u = positive_mod(positive_mod(pow(a, z1, p) * pow(y, z2, p), p), q) passed = w == u self.steps = locals() return passed
def sign(self, message): """ Подтверждение авторства сообщения """ p, q, a, y = self.public_key h = calc_hash(message, sha256) s = w_ = w = k = 0 while s == 0: while w == 0: k = randint(1, q) w = pow(a, k, p) w_ = w % q s = positive_mod(self._private_key * w_ + k * h, q) self.steps = locals() return w_, s
def sign(self, message): """ Создание электронной подписи """ (a, b, n), (x_p, y_p), q, _ = self.public_key h = calc_hash(message, sha512) e = h % q s = k = r = 0 while s == 0: while r == 0: k = randint(1, q - 1) x_c, y_c = mul((x_p, y_p), k, (a, b, n)) # умножение точки на кривой на число r = x_c % q s = (r * self._private_key + k * e) % q self.steps = locals() return r, s
def verify(self, message, signature): """ Подтверждение авторства сообщения """ (a, b, n), (x_p, y_p), q, (x_q, y_q) = self.prover_key r, s = signature h = calc_hash(message, sha512) e = h % q e_1 = int(crt((e, q), (0, 1))[0]) // e # обратное значение v = e_1 % q z1 = (s * v) % q z2 = positive_mod((q - r) * v, q) x_c, y_c = add(mul((x_p, y_p), z1, (a, b, n)), mul((x_q, y_q), z2, (a, b, n)), (a, b, n)) r_ = x_c % q passed = r == r_ self.steps = locals() return passed
def sign(self, message): h = calc_hash(message, md5) s = pow(h, *self._private_key) self.steps = locals() return s
def verify(self, message, signature): h1 = calc_hash(message, md5) h2 = pow(signature, *self.prover_key) passed = h1 % self.prover_key[1] == h2 self.steps = locals() return passed