def __init__(self, federal_info: dict, sec_param: dict): """ Args: federal_info: sec_param: """ if sec_param is not None: self.load_default_sec_param(path.join(path.dirname(__file__), 'sec_param.json')) super().__init__(federal_info, sec_param) self.chan_host_guest = make_variable_channel('he_otp_lr_ft2_variable_H2G', self.federal_info.host[0], self.federal_info.guest[0]) self.chan_host_coordinator = make_variable_channel('he_otp_lr_ft2_variable_H2C', self.federal_info.host[0], self.federal_info.coordinator) # Step 1: self.encryptor = self.chan_host_coordinator.recv(tag='encryptor')
def test_key_exchange(): commu.init(fed_conf_host) var_chan = make_variable_channel('test_key_exchange', fed_conf_host["federation"]["host"][0], fed_conf_host["federation"]["guest"][0]) for times in range(5): for each in [2048, 3072, 4096, 6144, 8192]: k = make_agreement(remote_id='zhibang-d-014011', key_size=each) var_chan.send(k, tag="k")
def __init__(self, federal_info: dict, sec_param: dict = None): """ Args: federal_info: sec_param: """ if sec_param: self.load_default_sec_param(path.join(path.dirname(__file__), 'sec_param.json')) super().__init__(federal_info, sec_param) self.variable_chan_guest_coordinator = make_variable_channel('he_lr_fp_variable_gc', self.federal_info.guest[0], self.federal_info.coordinator) self.variable_chan_host_coordinator = make_variable_channel('he_lr_fp_variable_hc', self.federal_info.host[0], self.federal_info.coordinator) # step1,get pk, get [u1] self.encryptor = self.variable_chan_guest_coordinator.recv(tag='pub_key') # step2: send pk to P2 self.variable_chan_host_coordinator.send(self.encryptor, tag='pub_key')
def __init__(self, federal_info: dict, sec_param: dict): """ Args: federal_info: sec_param: """ if sec_param: self.load_default_sec_param(path.join(path.dirname(__file__), 'sec_param.json')) super().__init__(federal_info, sec_param) self.variable_chan_host_coordinator = make_variable_channel('he_lr_fp_variable_hc', self.federal_info.coordinator, self.federal_info.host[0]) # step3, receive pk self.encryptor = self.variable_chan_host_coordinator.recv(tag='pub_key')
def test(): theta = [[ np.random.uniform(-1, 1, (2, 4)).astype(np.float32), np.random.uniform(-1, 1, (2, 6)).astype(np.float32) ], [np.random.uniform(-1, 1, (2, 8)).astype(np.float32)]] print(theta) federal_info = fed_conf_guest sec_param = {"key_exchange_size": 2048} trainer = make_protocol(OTP_SA_FT, federal_info, sec_param) result = trainer.exchange(theta) var_chan = make_variable_channel('test_otp_sa_ft', fed_conf_guest["federation"]["host"][0], fed_conf_guest["federation"]["guest"][0]) var_chan.send(theta, tag='theta')
def __init__(self, federal_info: dict, sec_param: dict): """ Args: federal_info: sec_param: """ if sec_param: self.load_default_sec_param(path.join(path.dirname(__file__), 'sec_param.json')) super().__init__(federal_info, sec_param) self.variable_chan_guest_coordinator = make_variable_channel('he_lr_fp_variable_gc', self.federal_info.guest[0], self.federal_info.coordinator) if self.sec_param.he_algo == CRYPTO_PAILLIER: self.encryptor, self.decryptor = generate_paillier_encryptor_decryptor(self.sec_param.he_key_length) else: raise NotImplementedError(f"Encryption algorithm {self.sec_param.he_algo} is not supported.") self.variable_chan_guest_coordinator.send(self.encryptor, tag='pub_key')
def test(): theta = [[ np.random.uniform(-1, 1, (2, 4)).astype(np.float32), np.random.uniform(-1, 1, (2, 6)).astype(np.float32) ], [np.random.uniform(-1, 1, (2, 8)).astype(np.float32)]] print(theta) federal_info = fed_conf_host sec_param = {"key_exchange_size": 2048} trainer = make_protocol(OTP_SA_FT, federal_info, sec_param) result = trainer.exchange(theta) var_chan = make_variable_channel('test_otp_sa_ft', fed_conf_host["federation"]["host"][0], fed_conf_host["federation"]["guest"][0]) guest_theta = var_chan.recv(tag='theta') sum_theta = iterative_add(theta, guest_theta) # 本地计算的平均梯度 avg_theta = iterative_divide(sum_theta, 2.0) assert almost_equal(result, avg_theta)
def _make_channel(self): self.var_chan = make_variable_channel('he_otp_lr_ft1_variable_H2G', self.federal_info.host[0], self.federal_info.guest[0])
def _make_channel(self): self.var_chan = make_variable_channel( name="iv_ffs_variable", endpoint1=self.federal_info.host[0], endpoint2=self.federal_info.guest[0])