def compute_point_xy(self): in_str = self.input_seed + "point" x_hash = utils.hash_sha512(in_str) self.point_x = int(x_hash, 16) % self.prime_p end = False while not end: ring = Integers(self.prime_p) tmp = power_mod(self.point_x, 3, self.prime_p) + \ self.coeff_a * self.point_x + self.coeff_b y = ring(tmp) if not utils.is_quadratic_residue(y, self.prime_p): x_hash = utils.hash_sha512(x_hash) self.point_x = int(x_hash, 16) % self.prime_p else: sq_root = int(y.square_root()) if sq_root % 2 == 0: self.point_y = sq_root else: self.point_y = self.prime_p - sq_root end = True
def ro_function(self, x, exp, p): is_qr = utils.is_quadratic_residue(x, p) if is_qr: sq_root = pow(x, exp, p) if sq_root % 2 == 0: return sq_root else: return (p - sq_root) else: sq_root = pow(p - x, exp, p) if sq_root % 2 == 0: return (p - sq_root) else: return sq_root