Exemplo n.º 1
0
    def dot(self, other: 'FixedPointTensor', target_name=None):
        spdz = self.get_spdz()
        if target_name is None:
            target_name = NamingService.get_instance().next()

        a, b, c = beaver_triplets(a_tensor=self.value,
                                  b_tensor=other.value,
                                  dot=table_dot,
                                  q_field=self.q_field,
                                  he_key_pair=(spdz.public_key,
                                               spdz.private_key),
                                  communicator=spdz.communicator,
                                  name=target_name)

        x_add_a = (self + a).rescontruct(f"{target_name}_confuse_x")
        y_add_b = (other + b).rescontruct(f"{target_name}_confuse_y")
        cross = c - table_dot_mod(a, y_add_b, self.q_field) - table_dot_mod(
            x_add_a, b, self.q_field)
        if spdz.party_idx == 0:
            cross += table_dot_mod(x_add_a, y_add_b, self.q_field)
        cross = cross % self.q_field
        cross = self.endec.truncate(cross, self.get_spdz().party_idx)
        share = fixedpoint_numpy.FixedPointTensor(cross, self.q_field,
                                                  self.endec, target_name)
        return share
Exemplo n.º 2
0
 def __exit__(self, exc_type, exc_val, exc_tb):
     NamingService.set_instance(self._pre_instance)
Exemplo n.º 3
0
 def __enter__(self):
     self._prev_name_service = NamingService.set_instance(self.name_service)
     self._pre_instance = self.set_instance(self)
     return self
Exemplo n.º 4
0
 def __init__(self, value, q_field, endec, tensor_name: str = None):
     super().__init__(q_field, tensor_name)
     self.value = value
     self.endec = endec
     self.tensor_name = NamingService.get_instance().next(
     ) if tensor_name is None else tensor_name
Exemplo n.º 5
0
 def __init__(self, q_field, tensor_name: str = None):
     self.q_field = q_field
     self.tensor_name = NamingService.get_instance().next(
     ) if tensor_name is None else tensor_name